AIME 5820 Crossover Alert

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

  1. //compile//
  2. //+------------------------------------------------------------------+
  3. //|                                       EMA_58_Crossover_alert.mq4 |
  4. //|                         Copyright ?2006, Robert Hill            |
  5. //|                                                                  |
  6. //| Written Robert Hill for use with AIME for the EMA 5/8 cross to   |
  7. //| draw arrows and popup alert or send email                        |
  8. //+------------------------------------------------------------------+

  9. #property copyright "Copyright ?2006, Robert Hill"

  10. #property indicator_chart_window
  11. #property indicator_buffers 5
  12. #property indicator_color1 LawnGreen
  13. #property indicator_color2 Red
  14. #property indicator_color3 Red
  15. #property indicator_color4 Aqua
  16. #property indicator_color5 Yellow
  17. #property indicator_width1  2
  18. #property indicator_width2  2
  19. #property indicator_width3  2
  20. #property indicator_width4  2
  21. #property indicator_width5  2

  22. extern bool SoundON=true;
  23. extern bool EmailON=false;

  24. double CrossUp[];
  25. double CrossDown[];
  26. double Ema5[];
  27. double Ema8[];
  28. double Ema20[];
  29. int flagval1 = 0;
  30. int flagval2 = 0;
  31. //+------------------------------------------------------------------+
  32. //| Custom indicator initialization function                         |
  33. //+------------------------------------------------------------------+
  34. int init()
  35.   {
  36. //---- indicators
  37.    SetIndexStyle(0, DRAW_ARROW, EMPTY);
  38.    SetIndexArrow(0, 233);
  39.    SetIndexBuffer(0, CrossUp);
  40.    SetIndexStyle(1, DRAW_ARROW, EMPTY);
  41.    SetIndexArrow(1, 234);
  42.    SetIndexBuffer(1, CrossDown);
  43.    SetIndexStyle(2, DRAW_LINE, STYLE_SOLID);
  44.    SetIndexBuffer(2, Ema5);
  45.    SetIndexStyle(3, DRAW_LINE, STYLE_SOLID);
  46.    SetIndexBuffer(3, Ema8);
  47.    SetIndexStyle(4, DRAW_LINE, STYLE_SOLID);
  48.    SetIndexBuffer(4, Ema20);
  49. //----
  50.    return(0);
  51.   }
  52. //+------------------------------------------------------------------+
  53. //| Custom indicator deinitialization function                       |
  54. //+------------------------------------------------------------------+
  55. int deinit()
  56.   {
  57. //----

  58. //----
  59.    return(0);
  60.   }


  61. //+------------------------------------------------------------------+
  62. //| Custom indicator iteration function                              |
  63. //+------------------------------------------------------------------+
  64. int start() {
  65.    int limit, i, counter;
  66.    double tmp=0;
  67.    double fastMAnow, slowMAnow, fastMAprevious, slowMAprevious;
  68.    double Range, AvgRange;
  69.    int counted_bars=IndicatorCounted();
  70. //---- check for possible errors
  71.    if(counted_bars<0) return(-1);
  72. //---- last counted bar will be recounted
  73.    if(counted_bars>0) counted_bars--;

  74.    limit=Bars-counted_bars;
  75.    
  76.    for(i = 1; i <= limit; i++) {
  77.    
  78.       counter=i;
  79.       Range=0;
  80.       AvgRange=0;
  81.       for (counter=i ;counter<=i+9;counter++)
  82.       {
  83.          AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
  84.       }
  85.       Range=AvgRange/10;
  86.       
  87.       fastMAnow = iMA(NULL, 0, 5, -1, MODE_EMA, PRICE_CLOSE, i);
  88.       fastMAprevious = iMA(NULL, 0, 5, -1, MODE_EMA, PRICE_CLOSE, i+1);

  89.       slowMAnow = iMA(NULL, 0, 8, 0, MODE_EMA, PRICE_OPEN, i);
  90.       slowMAprevious = iMA(NULL, 0, 8, 0, MODE_EMA, PRICE_OPEN, i+1);
  91.       
  92.       Ema20[i] = iMA(NULL, 0, 20, 0, MODE_EMA, PRICE_CLOSE, i);
  93.       Ema5[i] = fastMAnow;
  94.       Ema8[i] = slowMAnow;
  95.       CrossUp[i] = 0;
  96.       CrossDown[i] = 0;
  97.       if ((fastMAnow > slowMAnow) && (fastMAprevious < slowMAprevious))
  98.       {
  99.          if (i == 1 && flagval1==0)
  100.          {
  101.            flagval1=1;
  102.            flagval2=0;
  103.            if (SoundON) alert("BUY signal at Ask=",Ask,"n Bid=",Bid,"n Time=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime()),"n Symbol=",Symbol()," Period=",Period());
  104.            if (EmailON) SendMail("BUY signal alert","BUY signal at Ask="+DoubleToStr(Ask,4)+", Bid="+DoubleToStr(Bid,4)+", Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
  105.          }
  106.          CrossUp[i] = Low[i] - Range*0.75;
  107.       }
  108.       else if ((fastMAnow < slowMAnow) && (fastMAprevious > slowMAprevious))
  109.       {
  110.          if (i == 1 && flagval2==0)
  111.          {
  112.           flagval2=1;
  113.           flagval1=0;
  114.          if (SoundON) alert("SELL signal at Ask=",Ask,"n Bid=",Bid,"n Date=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime()),"n Symbol=",Symbol()," Period=",Period());
  115.          if (EmailON) SendMail("SELL signal alert","SELL signal at Ask="+DoubleToStr(Ask,4)+", Bid="+DoubleToStr(Bid,4)+", Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
  116.          }
  117.          CrossDown[i] = High[i] + Range*0.75;
  118.       }
  119.    }

  120.    return(0);
  121. }
打赏