|
|
本帖最后由 idcjet2 于 2013-5-7 20:02 编辑
吊灯追踪止损在图表中的显示问题:
试着编写该指标的目的:为了便于动态观察止损位的改变
原理:根据平均真实波幅与赢利间的比率关系动态调整波幅参数
问题:加载到主图表后,没有画出线,不知是哪里的问题,高手们帮看一下
- #property indicator_chart_window
- //#property indicator_separate_window
- #property indicator_buffers 1
- #property indicator_color1 HotPink
- #property indicator_width1 2
- //---- input parameters
- extern int AtrPeriod=14;
- extern string text = "";//下单后手动设置文字 买时赋值为 buy,卖时赋值为 sell
- //---- buffers
- double zzzs[];//保存追踪止损值
- //+------------------------------------------------------------------+
- //| Custom indicator initialization function |
- //+------------------------------------------------------------------+
- int init()
- {
- string short_name;
- //---- 1 additional buffer used for counting.
- IndicatorBuffers(1);
- //---- indicator line
- SetIndexStyle(0,DRAW_LINE);
- SetIndexBuffer(0,zzzs);
- //---- name for DataWindow and indicator subwindow label
- short_name="zzzs("+AtrPeriod+")";
- IndicatorShortName(short_name);
- SetIndexLabel(0,short_name);
- //----
- //----
- return(0);
- }
- //+------------------------------------------------------------------+
- //+------------------------------------------------------------------+
- int start()
- {
- if (ObjectFind(text) == 1) {
- int shift = iBarShift(NULL, 0, ObjectGet(text, OBJPROP_TIME1), TRUE);
- double price = ObjectGet(text,OBJPROP_PRICE1);
- double p_max = High[iHighest(NULL, 0, MODE_HIGH, shift, 0)];//最高点时卖
- double p_mim = Low[iLowest(NULL, 0, MODE_LOW, shift, 0)]; //最低点时买
- double p_dif = High[iHighest(NULL, 0, MODE_HIGH, shift, 0)] - Low[iLowest(NULL, 0, MODE_LOW, shift, 0)];//当前价与最佳买卖点之间的价差
- }
- for(int i=0; i<shift; i++)////
- {
- double AtrBuffer = iCustom(NULL, 0, "ATR", AtrPeriod , 0, i);
- //begin sell
- if(text=="sell"){
- if(p_dif<4*AtrBuffer) {zzzs[i]=Low[0]+3.5*AtrBuffer;}//初始止损atr参数3.5
- if(p_dif>4*AtrBuffer) {zzzs[i]=Low[0]+ 3*AtrBuffer;}//赢利大于4倍atr时,art参数改为3
- if(p_dif>6*AtrBuffer) {zzzs[i]=Low[0]+2.5*AtrBuffer;}//大于6倍时,art参数改为2.5
- if(p_dif>8*AtrBuffer) {zzzs[i]=Low[0]+2.0*AtrBuffer;}//大于8倍时,art参数改为2
- if(p_dif>10*AtrBuffer){zzzs[i]=Low[0]+1.5*AtrBuffer;}//大于10倍时,art参数改为1.5
- if(p_dif>12*AtrBuffer){zzzs[i]=Low[0]+1.0*AtrBuffer;}//大于12倍时,art参数改为1
- }
- //end sell
- //bengin buy 追踪止损
- if(text=="buy"){
- if(p_dif<4*AtrBuffer) {zzzs[i]=High[0]-3.5*AtrBuffer;}
- if(p_dif>4*AtrBuffer) {zzzs[i]=High[0]- 3*AtrBuffer;}
- if(p_dif>6*AtrBuffer) {zzzs[i]=High[0]-2.5*AtrBuffer;}
- if(p_dif>8*AtrBuffer) {zzzs[i]=High[0]-2.0*AtrBuffer;}
- if(p_dif>10*AtrBuffer){zzzs[i]=High[0]-1.5*AtrBuffer;}
- if(p_dif>12*AtrBuffer){zzzs[i]=High[0]-1.0*AtrBuffer;}
- }
- //end buy
- }
- //end for
- //----
- return(0);
- }
- //+------------------------------------------------------------------+
复制代码 |
|