Advertisement
Torrik20

Untitled

Jul 15th, 2019
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.02 KB | None | 0 0
  1.  
  2. //+------------------------------------------------------------------+
  3. //| NHNL.mq5 |
  4. //| Copyright 2018, MetaQuotes Software Corp. |
  5. //| https://mql5.com |
  6. //+------------------------------------------------------------------+
  7. #property copyright "Copyright 2018, MetaQuotes Software Corp."
  8. #property link "https://mql5.com"
  9. #property version "1.00"
  10. #property indicator_separate_window
  11. #property indicator_buffers 3
  12. #property indicator_plots 3
  13. //--- plot High
  14. #property indicator_label1 "High Index"
  15. #property indicator_type1 DRAW_LINE
  16. #property indicator_color1 clrGreen
  17. #property indicator_style1 STYLE_SOLID
  18. #property indicator_width1 1
  19. //--- plot Low
  20. #property indicator_label2 "Low Index"
  21. #property indicator_type2 DRAW_LINE
  22. #property indicator_color2 clrRed
  23. #property indicator_style2 STYLE_SOLID
  24. #property indicator_width2 1
  25. //--- plot High+Low
  26. #property indicator_label3 "Index HL"
  27. #property indicator_type3 DRAW_LINE
  28. #property indicator_color3 clrBlue
  29. #property indicator_style3 STYLE_SOLID
  30. #property indicator_width3 1
  31. //--- input parameters
  32. input uint InpPeriod=20;
  33. //--- indicator buffers
  34. double BufferHigh[];
  35. double BufferLow[];
  36. double BufferHL[];
  37. //--- global variables
  38. int period;
  39. //+------------------------------------------------------------------+
  40. //| Custom indicator initialization function |
  41. //+------------------------------------------------------------------+
  42. int OnInit()
  43. {
  44. //--- setting global variables
  45. period=int(InpPeriod<1 ? 1 : InpPeriod);
  46. //--- indicator buffers mapping
  47. SetIndexBuffer(0,BufferHigh,INDICATOR_DATA);
  48. SetIndexBuffer(1,BufferLow,INDICATOR_DATA);
  49. SetIndexBuffer(2,BufferHL,INDICATOR_DATA);
  50. //--- settings indicators parameters
  51. IndicatorSetInteger(INDICATOR_DIGITS,Digits());
  52. IndicatorSetString(INDICATOR_SHORTNAME,"New High, New Low Index("+(string)period+")");
  53. //--- setting buffer arrays as timeseries
  54. ArraySetAsSeries(BufferHigh,true);
  55. ArraySetAsSeries(BufferLow,true);
  56. ArraySetAsSeries(BufferHL,true);
  57. //---
  58. return(INIT_SUCCEEDED);
  59. }
  60. //+------------------------------------------------------------------+
  61. //| Custom indicator iteration function |
  62. //+------------------------------------------------------------------+
  63. int OnCalculate(const int rates_total,
  64. const int prev_calculated,
  65. const datetime &time[],
  66. const double &open[],
  67. const double &high[],
  68. const double &low[],
  69. const double &close[],
  70. const long &tick_volume[],
  71. const long &volume[],
  72. const int &spread[])
  73. {
  74. //--- Проверка на минимальное количество баров для расчёта
  75. if(rates_total<period) return 0;
  76. //--- Установка индексации массивов как таймсерий
  77. ArraySetAsSeries(high,true);
  78. ArraySetAsSeries(low,true);
  79. //--- Проверка и расчёт количества просчитываемых баров
  80. int limit=rates_total-prev_calculated;
  81. if(limit>1)
  82. {
  83. limit=rates_total-period-2;
  84. ArrayInitialize(BufferHigh,EMPTY_VALUE);
  85. ArrayInitialize(BufferLow,EMPTY_VALUE);
  86. ArrayInitialize(BufferHL,EMPTY_VALUE);
  87. }
  88. //--- Расчёт индикатора
  89. for(int i=limit; i>=0 && !IsStopped(); i--)
  90. {
  91. int count_h=0;
  92. int count_l=0;
  93. for(int n=0; n<period; n++)
  94. {
  95. if(high[i+n]>high[i+n+1]) count_h++;
  96. if(low[i+n]<low[i+n+1]) count_l--;
  97. }
  98. BufferHigh[i]=count_h;
  99. BufferLow[i]=count_l;
  100. BufferHL[i]=count_h+count_l;
  101. }
  102.  
  103. //--- return value of prev_calculated for next call
  104. return(rates_total);
  105. }
  106. //+------------------------------------------------------------------+
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement