Advertisement
Guest User

Untitled

a guest
Mar 16th, 2018
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. //+------------------------------------------------------------------+
  2. //| Beginner |
  3. //| Copyright © 2009-2017, EarnForex.com |
  4. //| https://www.earnforex.com/ |
  5. //+------------------------------------------------------------------+
  6. #property copyright "Copyright © 2009-2017, EarnForex.com"
  7. #property link "https://www.earnforex.com/metatrader-indicators/Beginner/"
  8. #property version "1.02"
  9. #property description "Beginner - basic indicator for marking chart's highs and lows."
  10. #property description "Repaints."
  11.  
  12. #property indicator_chart_window
  13. #property indicator_buffers 2
  14. #property indicator_plots 1
  15. #property indicator_color1 clrBlue, clrRed
  16. #property indicator_type1 DRAW_COLOR_ARROW
  17. #property indicator_style1 STYLE_SOLID
  18. #property indicator_width1 8
  19.  
  20. #define SH_BUY 1
  21. #define SH_SELL -1
  22.  
  23. input int AllBars = 0; // AllBars: How many bars to calculate on. 0 - all.
  24. input int Otstup = 30; // Otstup: Percentage distance to consider new low/high.
  25. input int Per = 9; // Period: Number of bars to seek high/low on.
  26.  
  27. // Indicator buffers.
  28. double Buf[];
  29. double BufCol[];
  30.  
  31. // Global variables.
  32. int NB, UD;
  33.  
  34. //+------------------------------------------------------------------+
  35. //| Custom indicator initialization function |
  36. //+------------------------------------------------------------------+
  37. void OnInit()
  38. {
  39. IndicatorSetString(INDICATOR_SHORTNAME, "Beginner(" + IntegerToString(Per) + ")");
  40.  
  41. PlotIndexSetInteger(0, PLOT_ARROW, 159);
  42.  
  43. SetIndexBuffer(0, Buf, INDICATOR_DATA);
  44. SetIndexBuffer(1, BufCol, INDICATOR_COLOR_INDEX);
  45. }
  46.  
  47. //+------------------------------------------------------------------+
  48. //| Custom Beginner |
  49. //+------------------------------------------------------------------+
  50. int OnCalculate(const int rates_total,
  51. const int prev_calculated,
  52. const datetime &time[],
  53. const double &open[],
  54. const double &High[],
  55. const double &Low[],
  56. const double &Close[],
  57. const long &tick_volume[],
  58. const long &volume[],
  59. const int &spread[])
  60. {
  61. double dbOtstup = Otstup;
  62.  
  63. ArraySetAsSeries(High, true);
  64. ArraySetAsSeries(Low, true);
  65. ArraySetAsSeries(Close, true);
  66.  
  67. // NB will hold the number of bars for indicator calculation.
  68. if ((rates_total < (AllBars + Per)) || (AllBars == 0)) NB = rates_total - Per;
  69. else NB = AllBars;
  70.  
  71. int CB = prev_calculated;
  72.  
  73. if (CB < 0) return(-1);
  74. else if (NB > (rates_total - CB)) NB = rates_total - CB + 100;
  75.  
  76. for (int SH = 1; SH < NB; SH++) // R is needed for distance between chart and arrows.
  77. {
  78. double R;
  79. int i;
  80.  
  81. for (R = 0, i = SH; i < SH + 10; i++)
  82. R += (10 + SH - i) * (High[i] - Low[i]);
  83.  
  84. R /= 55;
  85.  
  86. double SHMax = High[ArrayMaximum(High, SH, Per)];
  87. double SHMin = Low[ArrayMinimum(Low, SH, Per)];
  88. double diff = (SHMax - SHMin) * dbOtstup / 100.0;
  89.  
  90. Buf[rates_total - SH - 1] = EMPTY_VALUE;
  91.  
  92. if ((Close[SH] < (SHMin + diff)) && (UD != SH_SELL))
  93. {
  94. Buf[rates_total - SH - 1] = Low[SH] - R * 0.5;
  95. BufCol[rates_total - SH - 1] = 0;
  96. UD = SH_SELL;
  97. }
  98. else if ((Close[SH] > (SHMax - diff)) && (UD != SH_BUY))
  99. {
  100. Buf[rates_total - SH - 1] = High[SH] + R * 0.5;
  101. BufCol[rates_total - SH - 1] = 1;
  102. UD = SH_BUY;
  103. }
  104. }
  105.  
  106. return(rates_total);
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement