MA Cross w

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

  1. // This is Not Tested , Use At Your Own Risk !

  2. //+--------------------------------------------------------------------------+
  3. //| 3 MA Cross w_alert v2.mq4                                                |
  4. //| Copyright © 2005, Jason Robinson (jnrtrading)                            |
  5. //| http://www.jnrtading.co.uk                                               |
  6. //| 3 ma conversion and alert , David Honeywell , transport.david@gmail.com  |
  7. //| http://finance.groups.yahoo.com/group/metaTrader_Experts_and_Indicators/ |
  8. //+--------------------------------------------------------------------------+

  9.    

  10. #property copyright "Copyright © 2005, Jason Robinson (jnrtrading)"
  11. #property link      "http://www.jnrtrading.co.uk"

  12. #property indicator_chart_window
  13. #property indicator_buffers 2
  14. #property indicator_color1 Aqua
  15. #property indicator_color2 Coral

  16. double CrossUp[];
  17. double CrossDown[];
  18. double prevtime;
  19. double Range, AvgRange;
  20. double fasterMAnow, fasterMAprevious, fasterMAafter;
  21. double mediumMAnow, mediumMAprevious, mediumMAafter;
  22. double slowerMAnow, slowerMAprevious, slowerMAafter;

  23. extern int FasterMA    =    5;
  24. extern int FasterShift =   -5;
  25. extern int FasterMode  =    1; // 0 = sma, 1 = ema, 2 = smma, 3 = lwma

  26. extern int MediumMA    =   20;
  27. extern int MediumShift =   -5;
  28. extern int MediumMode  =    1; // 0 = sma, 1 = ema, 2 = smma, 3 = lwma

  29. extern int SlowerMA    =   34;
  30. extern int SlowerShift =    0;
  31. extern int SlowerMode  =    1; // 0 = sma, 1 = ema, 2 = smma, 3 = lwma

  32. extern int Soundalert =    1; // 0 = disabled

  33. //+------------------------------------------------------------------+
  34. //| Custom indicator initialization function                         |
  35. //+------------------------------------------------------------------+
  36. int init()
  37.   {
  38. //---- indicators
  39.    SetIndexStyle(0, DRAW_ARROW, EMPTY);
  40.    SetIndexArrow(0, 233);
  41.    SetIndexBuffer(0, CrossUp);
  42.    SetIndexStyle(1, DRAW_ARROW, EMPTY);
  43.    SetIndexArrow(1, 234);
  44.    SetIndexBuffer(1, CrossDown);
  45. //----
  46.    return(0);
  47.   }
  48. //+------------------------------------------------------------------+
  49. //| Custom indicator deinitialization function                       |
  50. //+------------------------------------------------------------------+
  51. int deinit()
  52.   {
  53. //----

  54. //----
  55.    return(0);
  56.   }
  57. //+------------------------------------------------------------------+
  58. //| Custom indicator iteration function                              |
  59. //+------------------------------------------------------------------+
  60. int start()
  61. {
  62.    
  63.    int limit, i, counter;
  64.    
  65.    int counted_bars=IndicatorCounted();
  66.    //---- check for possible errors
  67.    if(counted_bars<0) return(-1);
  68.    //---- last counted bar will be recounted
  69.    if(counted_bars>0) counted_bars--;
  70.    
  71.    limit=Bars-counted_bars;
  72.    
  73.    for(i = 0; i <= limit; i++)
  74.     {
  75.       
  76.       counter=i;
  77.       Range=0;
  78.       AvgRange=0;
  79.       for (counter=i ;counter<=i+9;counter++)
  80.        {
  81.          AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
  82.        }
  83.       Range=AvgRange/10;
  84.       
  85.       fasterMAnow      = iMA(NULL, 0, FasterMA, FasterShift, FasterMode, PRICE_CLOSE, i+1);
  86.       fasterMAprevious = iMA(NULL, 0, FasterMA, FasterShift, FasterMode, PRICE_CLOSE, i+2);
  87.       fasterMAafter    = iMA(NULL, 0, FasterMA, FasterShift, FasterMode, PRICE_CLOSE, i-1);
  88.       
  89.       mediumMAnow      = iMA(NULL, 0, MediumMA, MediumShift, MediumMode, PRICE_CLOSE, i+1);
  90.       mediumMAprevious = iMA(NULL, 0, MediumMA, MediumShift, MediumMode, PRICE_CLOSE, i+2);
  91.       mediumMAafter    = iMA(NULL, 0, MediumMA, MediumShift, MediumMode, PRICE_CLOSE, i-1);
  92.       
  93.       slowerMAnow      = iMA(NULL, 0, SlowerMA, SlowerShift, SlowerMode, PRICE_CLOSE, i+1);
  94.       slowerMAprevious = iMA(NULL, 0, SlowerMA, SlowerShift, SlowerMode, PRICE_CLOSE, i+2);
  95.       slowerMAafter    = iMA(NULL, 0, SlowerMA, SlowerShift, SlowerMode, PRICE_CLOSE, i-1);
  96.       
  97.       if ((fasterMAnow     > slowerMAnow       &&
  98.           fasterMAprevious <= slowerMAprevious  &&
  99.           fasterMAafter    > slowerMAafter     &&
  100.           mediumMAnow      > slowerMAnow     )
  101.           ||
  102.           (fasterMAnow     > slowerMAnow       &&
  103.           mediumMAnow      > slowerMAnow       &&
  104.           mediumMAprevious <= slowerMAprevious  &&
  105.           mediumMAafter    > slowerMAafter   ))
  106.        {
  107.          CrossUp[i] = Low[i] - Range*0.5;
  108.        }
  109.       
  110.       if ((fasterMAnow     < slowerMAnow       &&
  111.           fasterMAprevious >= slowerMAprevious  &&
  112.           fasterMAafter    < slowerMAafter     &&
  113.           mediumMAnow      < slowerMAnow     )
  114.           ||
  115.           (fasterMAnow     < slowerMAnow       &&
  116.           mediumMAnow      < slowerMAnow       &&
  117.           mediumMAprevious >= slowerMAprevious  &&
  118.           mediumMAafter    < slowerMAafter   ))
  119.        {
  120.          CrossDown[i] = High[i] + Range*0.5;
  121.        }
  122.       
  123.     }
  124.    
  125.       if ((CrossUp[0] > 2000) && (CrossDown[0] > 2000)) { prevtime = 0; }
  126.       
  127.       if ((CrossUp[0] == Low[0] - Range*0.5) && (prevtime != Time[0]) && (Soundalert != 0))
  128.        {
  129.          prevtime = Time[0];
  130.          alert(Symbol()," 3 MA Cross Up @  Hour ",Hour(),"  Minute ",Minute());
  131.        }
  132.       
  133.       if ((CrossDown[0] == High[0] + Range*0.5) && (prevtime != Time[0]) && (Soundalert != 0))
  134.        {
  135.          prevtime = Time[0];
  136.          alert(Symbol()," 3 MA Cross Down @  Hour ",Hour(),"  Minute ",Minute());
  137.        }
  138.    
  139.    //Comment("  CrossUp[0]  ",CrossUp[0]," ,  CrossDown[0]  ",CrossDown[0]," ,  prevtime  ",prevtime);
  140.    //Comment("");
  141.    
  142.    return(0);
  143. }
打赏