Advertisement
sairavi

stepma color

Sep 21st, 2017
1,682
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.42 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.  
  26. datetime LastAlertTime = D'01.01.1970';
  27. int LastAlertDirection = 0;
  28. //---- indicator buffers
  29. double UpBuffer[];
  30. double DownBuffer[];
  31. //+------------------------------------------------------------------+
  32. //| Custom indicator initialization function |
  33. //+------------------------------------------------------------------+
  34. int init()
  35. {
  36. string short_name;
  37. //---- indicator line
  38. SetIndexStyle(0,DRAW_ARROW);
  39. SetIndexStyle(1,DRAW_ARROW);
  40. SetIndexArrow(0,159);
  41. SetIndexArrow(1,159);
  42. SetIndexShift(0,Advance);
  43. SetIndexShift(1,Advance);
  44. SetIndexBuffer(0,UpBuffer);
  45. SetIndexBuffer(1,DownBuffer);
  46. IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
  47. //---- name for DataWindow and indicator subwindow label
  48. short_name="StepMA("+PeriodWATR+")";
  49. IndicatorShortName(short_name);
  50. SetIndexLabel(0,"UpTrendStepMA");
  51. SetIndexLabel(1,"DownTrendStepMA");
  52. //----
  53. SetIndexDrawBegin(0,PeriodWATR);
  54. SetIndexDrawBegin(1,PeriodWATR);
  55. //----
  56. return(0);
  57. }
  58.  
  59. //+------------------------------------------------------------------+
  60. //| StepMA_v2 |
  61. //+------------------------------------------------------------------+
  62. int start()
  63. {
  64. int i,shift,trend;
  65. double smin0,smax0,smin1,smax1,AvgRange,dK,WATR;
  66.  
  67. AvgRange=0;
  68. for (i=PeriodWATR-1;i>=0;i--)
  69. {
  70. dK = 1+(PeriodWATR-i)/PeriodWATR;
  71. AvgRange=AvgRange+ dK*MathAbs(High[i]-Low[i]);
  72. }
  73. WATR = AvgRange/PeriodWATR;
  74. int StepSize=Kwatr*WATR/Point;
  75. Comment(" StepSize = ", StepSize);
  76.  
  77.  
  78. for(shift=Bars-1;shift>=0;shift--)
  79. {
  80. if (HighLow>0)
  81. {
  82. smax0=Low[shift]+2*StepSize*Point;
  83. smin0=High[shift]-2*StepSize*Point;
  84.  
  85. if(Close[shift]>smax1) trend=1;
  86. if(Close[shift]<smin1) trend=-1;
  87. }
  88.  
  89. if (HighLow == 0)
  90. {
  91. smax0=Close[shift]+2*StepSize*Point;
  92. smin0=Close[shift]-2*StepSize*Point;
  93.  
  94. if (Close[shift]>smax1) trend=1;
  95. if (Close[shift]<smin1) trend=-1;
  96. }
  97.  
  98. if(trend>0 && smin0<smin1) smin0=smin1;
  99. if(trend<0 && smax0>smax1) smax0=smax1;
  100.  
  101. if (trend>0)
  102. {
  103. UpBuffer[shift]=smin0+StepSize*Point;
  104. DownBuffer[shift]=-1.0;
  105. }
  106. if (trend<0)
  107. {
  108. DownBuffer[shift]=smax0-StepSize*Point;
  109. UpBuffer[shift]=-1.0;
  110. }
  111.  
  112. smin1=smin0;
  113. smax1=smax0;
  114. }
  115. if (((TriggerCandle > 0) && (Time[0] > LastAlertTime)) || (TriggerCandle == 0))
  116. {
  117. string Text;
  118. // Up Arrow Alert
  119. if ((UpBuffer[TriggerCandle] > 0) && ((TriggerCandle > 0) || ((TriggerCandle == 0) && (LastAlertDirection != 1))))
  120. {
  121. Text = AlertText + "StepMAcolor_v2: " + Symbol() + " - " + EnumToString((ENUM_TIMEFRAMES)Period()) + " - Up.";
  122. if (EnableNativeAlerts) Alert(Text);
  123. if (EnableEmailAlerts) SendMail(AlertEmailSubject + "StepMAcolor_v2 Alert", Text);
  124. if (EnableSoundAlerts) PlaySound(SoundFileName);
  125. LastAlertTime = Time[0];
  126. LastAlertDirection = 1;
  127. }
  128. // Down Arrow Alert
  129. if ((DownBuffer[TriggerCandle] > 0) && ((TriggerCandle > 0) || ((TriggerCandle == 0) && (LastAlertDirection != -1))))
  130. {
  131. Text = AlertText + "StepMAcolor_v2: " + Symbol() + " - " + EnumToString((ENUM_TIMEFRAMES)Period()) + " - Down.";
  132. if (EnableNativeAlerts) Alert(Text);
  133. if (EnableEmailAlerts) SendMail(AlertEmailSubject + "StepMAcolor_v2 Alert", Text);
  134. if (EnableSoundAlerts) PlaySound(SoundFileName);
  135. LastAlertTime = Time[0];
  136. LastAlertDirection = -1;
  137. }
  138. }
  139. return(0);
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement