[MT4指标]请帮忙改成有报警信号的MACD背离指标
//+------------------------------------------------------------------+
//|                                        MACD_beili.mq4   Ver. 1.0 |
//|                               MACD背离指标(按最高最低价计算)。 |
//|                                                       Henry Zhao |
//|                                              [email protected] |
//|                                                    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;
datetime alerttime=0;
//---- buffers
double ExtMapBuffer1;
double ExtMapBuffer2;
double ExtMapBuffer3;
//+------------------------------------------------------------------+
//| 指标初始化代码                                                   |
//+------------------------------------------------------------------+
int init(){
   SetIndexStyle(0,DRAW_ARROW);      // RSI背离信号用箭头表示
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexArrow(0,233);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexArrow(1,234);
   SetIndexStyle(2,DRAW_ARROW);     // 阶段高/低点用黑色点表示
   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;
for( i=shift-2*bars_compared; i>=0; i--){
      low1 = 0;
      if( Low[i+2] v2){   ExtMapBuffer1 = Low - pos_adjust;
                           ExtMapBuffer3[bar1] = Low[bar1] - pos_adjust*0.3;
                           ExtMapBuffer3[bar2] = Low[bar2] - pos_adjust*0.3;
                       }
            }
            
      high1 = 0;
      if( High[i+2]>High[i+1] && High[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 = High + pos_adjust;
                           ExtMapBuffer3[bar1] = High[bar1] + pos_adjust*0.3;
                           ExtMapBuffer3[bar2] = High[bar2] + pos_adjust*0.3;
                        }
            }
      } // end of for(i)
return(0);
}
//+------------------------------------------------------------------+ 
发表于:2008-09-26 12:05只看该作者
2楼 
你这个语句怎么有错误啊????
利润是等出来的,亏损是冲动出来的
发表于:2016-12-07 14:27只看该作者
4楼 
感谢分享
发表于:2017-06-16 05:07只看该作者
5楼 
这个不能修改。。。

















