MACD Crossover Signal

楼主  收藏   举报   帖子创建时间:  2019-05-05 05:06 回复:0 关注量:799
EURGBPH1.png

  1. //+------------------------------------------------------------------+
  2. //|                                        MACD Crossover Signal.mq4 |
  3. //+------------------------------------------------------------------+

  4. #property copyright "Copyright ?2007, Robert Hill)"

  5. #property indicator_chart_window
  6. #property indicator_buffers 2
  7. #property indicator_color1 Blue
  8. #property indicator_color2 Red

  9. double CrossUp[];
  10. double CrossDown[];
  11. extern int FastEMA=12;
  12. extern int SlowEMA=26;
  13. extern int SignalSMA=9;
  14. //+------------------------------------------------------------------+
  15. //| Custom indicator initialization function                         |
  16. //+------------------------------------------------------------------+
  17. int init()
  18.   {
  19. //---- indicators
  20.    SetIndexStyle(0, DRAW_ARROW, EMPTY, 1);
  21.    SetIndexArrow(0, 221);
  22.    SetIndexBuffer(0, CrossUp);
  23.    SetIndexStyle(1, DRAW_ARROW, EMPTY, 1);
  24.    SetIndexArrow(1, 222);
  25.    SetIndexBuffer(1, CrossDown);
  26.    IndicatorDigits(2);
  27. //----
  28.    return(0);
  29.   }
  30. //+------------------------------------------------------------------+
  31. //| Custom indicator deinitialization function                       |
  32. //+------------------------------------------------------------------+
  33. int deinit()
  34.   {
  35. //----

  36. //----
  37.    return(0);
  38.   }
  39. //+------------------------------------------------------------------+
  40. //| Custom indicator iteration function                              |
  41. //+------------------------------------------------------------------+
  42. int start() {
  43.    int limit, i, counter;
  44.    double MACD_Main, MACD_Signal, MACD_MainPrevious, MACD_SignalPrevious;
  45.    double Range, AvgRange;
  46.    int counted_bars=IndicatorCounted();
  47. //---- check for possible errors
  48.    if(counted_bars<0) return(-1);
  49. //---- last counted bar will be recounted
  50.    if(counted_bars>0) counted_bars--;

  51.    limit=Bars-counted_bars;
  52.    
  53.    for(i = 0; i <= limit; i++) {
  54.    
  55.       counter=i;
  56.       Range=0;
  57.       AvgRange=0;
  58.       for (counter=i ;counter<=i+9;counter++) {
  59.          AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
  60.       }
  61.       Range=AvgRange/10;
  62.       
  63.       MACD_Main = iMACD(NULL, 0, FastEMA, SlowEMA, SignalSMA, PRICE_CLOSE, MODE_MAIN, i);
  64.       MACD_MainPrevious = iMACD(NULL, 0, FastEMA, SlowEMA, SignalSMA, PRICE_CLOSE, MODE_MAIN, i+1);
  65.       MACD_Signal = iMACD(NULL, 0, FastEMA, SlowEMA, SignalSMA, PRICE_CLOSE, MODE_SIGNAL, i);
  66.       MACD_SignalPrevious = iMACD(NULL, 0, FastEMA, SlowEMA, SignalSMA, PRICE_CLOSE, MODE_SIGNAL, i+1);

  67.       
  68.       if ((MACD_Signal < MACD_Main) && (MACD_SignalPrevious > MACD_MainPrevious)) {
  69.          CrossUp[i] = Low[i] - Range*0.5;
  70.       }
  71.       else if ((MACD_Signal > MACD_Main) && (MACD_SignalPrevious < MACD_MainPrevious)) {
  72.          CrossDown[i] = High[i] + Range*0.5;
  73.       }
  74.    }
  75.    return(0);
  76. }

打赏