Guest User

step ma alert

a guest
Sep 25th, 2017
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.51 KB | None | 0 0
  1. //+------------------------------------------------------------------+
  2. //| StepMA_Color_v2.mq4 |
  3. //| Copyright © 2005, TrendLaboratory Ltd. |
  4. //| E-mail: igorad2004@list.ru |
  5. //+------------------------------------------------------------------+
  6. #property copyright "Copyright © 2005, TrendLaboratory Ltd."
  7. #property link "E-mail: igorad2004@list.ru"
  8.  
  9. #property indicator_chart_window
  10. #property indicator_buffers 2
  11. #property indicator_color1 Blue
  12. #property indicator_color2 Red
  13. //---- input parameters
  14. extern int PeriodWATR=100;
  15. extern double Kwatr=1.0000;
  16. extern int Advance=0;
  17. extern int HighLow=0;
  18. input int TriggerCandle = 1;
  19. input bool EnableNativeAlerts = true;
  20. input bool EnableSoundAlerts = true;
  21. input bool EnableEmailAlerts = true;
  22. input string AlertEmailSubject = "";
  23. input string AlertText = "";
  24. input string SoundFileName = "alert.wav";
  25. datetime LastAlertTime = D'01.01.1970';
  26. int LastAlertDirection = 0;
  27. //---- indicator buffers
  28. double UpBuffer[];
  29. double DownBuffer[];
  30. //+------------------------------------------------------------------+
  31. //| Custom indicator initialization function |
  32. //+------------------------------------------------------------------+
  33. int init()
  34. {
  35. string short_name;
  36. //---- indicator line
  37. SetIndexStyle(0,DRAW_ARROW);
  38. SetIndexStyle(1,DRAW_ARROW);
  39. SetIndexArrow(0,159);
  40. SetIndexArrow(1,159);
  41. SetIndexShift(0,Advance);
  42. SetIndexShift(1,Advance);
  43. SetIndexBuffer(0,UpBuffer);
  44. SetIndexBuffer(1,DownBuffer);
  45. IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
  46. //---- name for DataWindow and indicator subwindow label
  47. short_name="StepMA("+PeriodWATR+")";
  48. IndicatorShortName(short_name);
  49. SetIndexLabel(0,"UpTrendStepMA");
  50. SetIndexLabel(1,"DownTrendStepMA");
  51. //----
  52. SetIndexDrawBegin(0,PeriodWATR);
  53. SetIndexDrawBegin(1,PeriodWATR);
  54. //----
  55. return(0);
  56. }
  57.  
  58. //+------------------------------------------------------------------+
  59. //| StepMA_v2 |
  60. //+------------------------------------------------------------------+
  61. int start()
  62. {
  63. int i,shift,trend;
  64. double smin0,smax0,smin1,smax1,AvgRange,dK,WATR;
  65.  
  66. AvgRange=0;
  67. for (i=PeriodWATR-1;i>=0;i--)
  68. {
  69. dK = 1+(PeriodWATR-i)/PeriodWATR;
  70. AvgRange=AvgRange+ dK*MathAbs(High[i]-Low[i]);
  71. }
  72. WATR = AvgRange/PeriodWATR;
  73. int StepSize=Kwatr*WATR/Point;
  74. Comment(" StepSize = ", StepSize);
  75.  
  76.  
  77. for(shift=Bars-1;shift>=0;shift--)
  78. {
  79. if (HighLow>0)
  80. {
  81. smax0=Low[shift]+2*StepSize*Point;
  82. smin0=High[shift]-2*StepSize*Point;
  83.  
  84. if(Close[shift]>smax1) trend=1;
  85. if(Close[shift]<smin1) trend=-1;
  86. }
  87.  
  88. if (HighLow == 0)
  89. {
  90. smax0=Close[shift]+2*StepSize*Point;
  91. smin0=Close[shift]-2*StepSize*Point;
  92.  
  93. if (Close[shift]>smax1) trend=1;
  94. if (Close[shift]<smin1) trend=-1;
  95. }
  96.  
  97. if(trend>0 && smin0<smin1) smin0=smin1;
  98. if(trend<0 && smax0>smax1) smax0=smax1;
  99.  
  100. if (trend>0)
  101. {
  102. UpBuffer[shift]=smin0+StepSize*Point;
  103. DownBuffer[shift]=-1.0;
  104. }
  105. if (trend<0)
  106. {
  107. DownBuffer[shift]=smax0-StepSize*Point;
  108. UpBuffer[shift]=-1.0;
  109. }
  110.  
  111. smin1=smin0;
  112. smax1=smax0;
  113. }
  114. if (((TriggerCandle > 0) && (Time[0] > LastAlertTime)) || (TriggerCandle == 0))
  115. {
  116. string Text;
  117. // Above Zero Alert
  118. if (((UpBuffer[TriggerCandle] > 0) && (UpBuffer[TriggerCandle+ 1] <= 0)) && ((TriggerCandle > 0) || ((TriggerCandle == 0) && (LastAlertDirection != 1))))
  119. {
  120. Text = AlertText + "stepma_color_v2: " + Symbol() + " - " + EnumToString((ENUM_TIMEFRAMES)Period()) + " - Buy signal.";
  121. if (EnableNativeAlerts) Alert(Text);
  122. if (EnableEmailAlerts) SendMail(AlertEmailSubject + "stepma_color_v2 Alert", Text);
  123. if (EnableSoundAlerts) PlaySound(SoundFileName);
  124. LastAlertTime = Time[0];
  125. LastAlertDirection = 1;
  126. }
  127. // Below Zero Alert
  128. if (((UpBuffer[TriggerCandle] < 0) && (UpBuffer[TriggerCandle+ 1] >= 0)) && ((TriggerCandle > 0) || ((TriggerCandle == 0) && (LastAlertDirection != -1))))
  129. {
  130. Text = AlertText + "stepma_color_v2: " + Symbol() + " - " + EnumToString((ENUM_TIMEFRAMES)Period()) + " - Sell signal.";
  131. if (EnableNativeAlerts) Alert(Text);
  132. if (EnableEmailAlerts) SendMail(AlertEmailSubject + "stepma_color_v2 Alert", Text);
  133. if (EnableSoundAlerts) PlaySound(SoundFileName);
  134. LastAlertTime = Time[0];
  135. LastAlertDirection = -1;
  136. }
  137. }
  138. return(0);
  139. }
Add Comment
Please, Sign In to add comment