Advertisement
Guest User

Untitled

a guest
Apr 5th, 2017
651
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.68 KB | None | 0 0
  1. //+------------------------------------------------------------------+
  2. //| Indicator: Stochastic Alert.mq4 |
  3. //| Created with EABuilder.com |
  4. //| http://eabuilder.com |
  5. //+------------------------------------------------------------------+
  6. #property copyright "Created with EABuilder.com"
  7. #property link "http://eabuilder.com"
  8. #property version "1.00"
  9. #property description ""
  10.  
  11. #include
  12. #include
  13.  
  14. //--- indicator settings
  15. #property indicator_chart_window
  16. #property indicator_buffers 2
  17.  
  18. #property indicator_type1 DRAW_ARROW
  19. #property indicator_width1 3
  20. #property indicator_color1 0x1A7D29
  21. #property indicator_label1 "Buy"
  22.  
  23. #property indicator_type2 DRAW_ARROW
  24. #property indicator_width2 3
  25. #property indicator_color2 0x0000FF
  26. #property indicator_label2 "Sell"
  27.  
  28. //--- indicator buffers
  29. double Buffer1[];
  30. double Buffer2[];
  31.  
  32. extern int LookBack = 5000;
  33. datetime time_alert; //used when sending alert
  34. extern bool Audible_Alerts = true;
  35. input bool EnableNativeAlerts = true;
  36. input string SoundFileName = "Bicycle-Bell-Ringingt.wav";
  37. double myPoint; //initialized in OnInit
  38.  
  39. void myAlert(string type, string message)
  40. {
  41. if(type == "print")
  42. Print(message);
  43. else if(type == "error")
  44. {
  45. Print(type+" | Stochastic Alert @ "+Symbol()+","+Period()+" | "+message);
  46. }
  47. else if(type == "order")
  48. {
  49. }
  50. else if(type == "modify")
  51. {
  52. }
  53. else if(type == "indicator")
  54. {
  55. if(Audible_Alerts) { PlaySound("Bicycle-Bell-Ringing.wav"); Alert(type+" | Stochastic Alert @ "+Symbol()+","+Period()+" | "+message); }
  56. }
  57. }
  58.  
  59. //+------------------------------------------------------------------+
  60. //| Custom indicator initialization function |
  61. //+------------------------------------------------------------------+
  62. int OnInit()
  63. {
  64. IndicatorBuffers(2);
  65. SetIndexBuffer(0, Buffer1);
  66. SetIndexEmptyValue(0, 0);
  67. SetIndexArrow(0, 241);
  68. SetIndexBuffer(1, Buffer2);
  69. SetIndexEmptyValue(1, 0);
  70. SetIndexArrow(1, 242);
  71. //initialize myPoint
  72. myPoint = Point();
  73. if(Digits() == 5 || Digits() == 3)
  74. {
  75. myPoint *= 10;
  76. }
  77. return(INIT_SUCCEEDED);
  78. }
  79.  
  80. //+------------------------------------------------------------------+
  81. //| Custom indicator iteration function |
  82. //+------------------------------------------------------------------+
  83. int OnCalculate(const int rates_total,
  84. const int prev_calculated,
  85. const datetime& time[],
  86. const double& open[],
  87. const double& high[],
  88. const double& low[],
  89. const double& close[],
  90. const long& tick_volume[],
  91. const long& volume[],
  92. const int& spread[])
  93. {
  94. int limit = rates_total - prev_calculated;
  95. //--- counting from 0 to rates_total
  96. ArraySetAsSeries(Buffer1, true);
  97. ArraySetAsSeries(Buffer2, true);
  98. //--- initial zero
  99. if(prev_calculated = 0; i--)
  100. {
  101. if (i >= MathMin(LookBack, rates_total-1-50)) continue; //omit some old rates to prevent "Array out of range" or slow calculation
  102. //Indicator Buffer 1
  103. if(iStochastic(NULL, PERIOD_CURRENT, 13, 1, 3, MODE_SMA, 0, MODE_MAIN, i) > 20
  104. && iStochastic(NULL, PERIOD_CURRENT, 13, 1, 3, MODE_SMA, 0, MODE_MAIN, i+1) = 20 //Stochastic Oscillator >= fixed value
  105. )
  106. {
  107. Buffer1[i] = Low[i] - iATR(NULL, PERIOD_CURRENT, 14, i); //Set indicator value at Candlestick Low - Average True Range
  108. if(i == 0 && Time[0] != time_alert) { myAlert("indicator", "Buy"); time_alert = Time[0]; PlaySound("Bicycle-Bell-Ringing.wav"); } //Instant alert, only once per bar
  109. }
  110. else
  111. {
  112. Buffer1[i] = 0;
  113. }
  114. //Indicator Buffer 2
  115. if(iStochastic(NULL, PERIOD_CURRENT, 13, 1, 3, MODE_SMA, 0, MODE_MAIN, i) 80 //Stochastic Oscillator crosses below fixed value
  116. && iStochastic(NULL, PERIOD_CURRENT, 8, 1, 3, MODE_SMA, 0, MODE_MAIN, i) <= 80 //Stochastic Oscillator <= fixed value
  117. )
  118. {
  119. Buffer2[i] = High[i] + iATR(NULL, PERIOD_CURRENT, 14, i); //Set indicator value at Candlestick High + Average True Range
  120. if(i == 0 && Time[0] != time_alert) { myAlert(&quot;indicator&quot;, &quot;Sell&quot;); time_alert = Time[0]; PlaySound(&quot;Bicycle-Bell-Ringing.wav&quot;); } //Instant alert, only once per bar
  121. }
  122. else
  123. {
  124. Buffer2[i] = 0;
  125. }
  126. }
  127. return(rates_total);
  128. }
  129. //+------------------------------------------------------------------+
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement