关于MACD背离作业,请牛版主批改,还有几个问题,谢谢!
源代码引自:http://bbs.520fx.com/viewthread. ... =%E8%83%8C%E7%A6%BB //+------------------------------------------------------------------+ //| MACD_beili.mq4 Ver. 1.0 | //| MACD背离指标(按最高最低价计算)。 | //| Henry Zhao | //| shinetrip@yahoo.com | //| Feb. 19, 2007 | //+------------------------------------------------------------------+ #property copyright "Henry Zhao" #property indicator_chart_window #property indicator_buffers 3 #property indicator_color1 Cyan #property indicator_color2 Magenta #property indicator_color3 Black extern int method = 1; extern int bars_compared = 15; // 在多少个bar中寻找第二个峰值 extern int number_of_bars = 1000; //---- buffers double ExtMapBuffer1[]; double ExtMapBuffer2[]; double ExtMapBuffer3[]; //+------------------------------------------------------------------+ //| 指标初始化代码 | //+------------------------------------------------------------------+ int init(){ //SetIndexStyle(0,DRAW_ARROW); // RSI背离信号用箭头表示 SetIndexStyle(0,DRAW_NONE); // RSI背离信号用箭头表示 SetIndexBuffer(0,ExtMapBuffer1); SetIndexArrow(0,233); //SetIndexStyle(1,DRAW_ARROW); SetIndexStyle(1,DRAW_NONE); SetIndexBuffer(1,ExtMapBuffer2); SetIndexArrow(1,234); SetIndexStyle(2,DRAW_ARROW,EMPTY,4); // 阶段高/低点用黑色点表示 SetIndexBuffer(2,ExtMapBuffer3); SetIndexArrow(2,159); return(0); } //+------------------------------------------------------------------+ //| 指标反初始化代码 | //+------------------------------------------------------------------+ int deinit(){ return(0); } //+------------------------------------------------------------------+ //| 计算显示指标的条件 | //+------------------------------------------------------------------+ int start(){ int i, m, shift, bar1, bar2; double pos_adjust, low1, low2, high1, high2, v1, v2; pos_adjust = 100*Point; // 根据不同的时间框架确定信号显示的位置。主要是为了美观 if(Period()==1) pos_adjust = 1*Point; if(Period()==5) pos_adjust = 3*Point; if(Period()==15) pos_adjust = 8*Point; if(Period()==30) pos_adjust = 10*Point; if(Period()==60) pos_adjust = 13*Point; if(Period()==240) pos_adjust = 20*Point; if(Period()==1440) pos_adjust = 50*Point; shift=Bars; if( shift>number_of_bars ) shift = number_of_bars;//只计数1000个k线 for( i=shift-2*bars_compared; i>=0; i--)//i从第970条至第0根K线(包括第0根k线)开始从左向右循环计算,(为何要从第970根k线开始计算?从第1000根k线不行么?) { low1 = 0; if( Low[i+2]High[i+3]){ bar1=i+2; high1 = High[bar1]; } // 最高点必须是前三条已完成bar的中间那一条 high2 = 0; if(method==1){ bar2 = iHighest(NULL, 0, MODE_HIGH, bars_compared, i+4); if( bar2 != i+4 && bar2 != i+4 +bars_compared-1 ) high2 = High[bar2]; } if(method==2){ bar2 = iHighest(NULL, 0, MODE_HIGH, bars_compared, i+bars_compared); if( bar2 != i+bars_compared && bar2 != i + 2*bars_compared-1 ) high2 = High[bar2]; } if( high1!=0 && high2!=0 && high1>high2){ v1 = iMACD( NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_MAIN, bar1); v2 = iMACD( NULL, 0, 12, 26, 9, PRICE_CLOSE, MODE_MAIN, bar2); if( v1 < v2 ){ ExtMapBuffer2<i> = High<i> + pos_adjust; ExtMapBuffer3[bar1] = High[bar1] + pos_adjust*0.3; ExtMapBuffer3[bar2] = High[bar2] + pos_adjust*0.3; } } } // end of for(i) return(0); } //+------------------------------------------------------------------+[/td][/tr] |
打赏
最新创建圈子
- 新闻EA运行效果图圈 2019-05-05
圈主:admin 帖子:1