Ingen beskrivning

atr_momentum_indicator_mt4.mq4 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. //+------------------------------------------------------------------+
  2. //| atr_momentum_indicator_mt4.mq4 |
  3. //| Copyright 2025, MQL Development |
  4. //| https://www.mqldevelopment.com/ |
  5. //+------------------------------------------------------------------+
  6. #property copyright "Copyright 2025, MQL Development"
  7. #property link "https://www.mqldevelopment.com/"
  8. #property version "1.00"
  9. #property strict
  10. #property indicator_separate_window
  11. #property indicator_buffers 3
  12. #property indicator_minimum 0.0
  13. //+------------------------------------------------------------------+
  14. //| Custom indicator initialization function |
  15. //+------------------------------------------------------------------+
  16. input string string_1 = "<><><><><><> General SETTINGS <><><><><><>"; //__
  17. input double threshold = 0.00001; // Threshold Value
  18. sinput string atrSettings = " <><><><><> Atr Settings <><><><><> "; //_
  19. input int atrPeriod = 14; // ATR Period
  20. input string string_2_2 = "<><><><><><> Color Setting <><><><><><>"; //__
  21. input color atr_line_color = clrAqua; // Atr Line Color
  22. input color signal_color = clrLimeGreen; // Signal Color
  23. input color no_signal_color = clrSlateGray; // No Signal Color
  24. // Global Variables
  25. double atrPercentageBuffer[];
  26. double signalBuffer[];
  27. double noSignalBuffer[];
  28. string short_name="";
  29. int OnInit()
  30. {
  31. //--- indicator buffers mapping
  32. SetIndexBuffer(0, atrPercentageBuffer);
  33. SetIndexBuffer(1, signalBuffer);
  34. SetIndexBuffer(2, noSignalBuffer);
  35. //--- Set buffer names
  36. SetIndexLabel(0, "Atr %");
  37. SetIndexLabel(1, "Signal");
  38. SetIndexLabel(2, "No Signal");
  39. SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2, atr_line_color);
  40. SetIndexStyle(1, DRAW_HISTOGRAM, STYLE_SOLID, 4, signal_color);
  41. SetIndexStyle(2, DRAW_HISTOGRAM, STYLE_SOLID, 4, no_signal_color);
  42. short_name = "atr_momentum_indicator_mt4";
  43. IndicatorShortName(short_name);
  44. //---
  45. return(INIT_SUCCEEDED);
  46. }
  47. //+------------------------------------------------------------------+
  48. //| Custom indicator iteration function |
  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. //---
  62. int i, Counted_bars;
  63. Counted_bars=IndicatorCounted(); // Number of counted bars
  64. if(prev_calculated == 0)
  65. i=Bars-Counted_bars-10;
  66. else
  67. i=Bars-Counted_bars-1;
  68. while(i >= 0)
  69. {
  70. double atrValueIs = atrValue(i);
  71. double candle_0 = iClose(Symbol(), PERIOD_CURRENT, 0);
  72. double candle_1 = iClose(Symbol(), PERIOD_CURRENT, 0 + 1);
  73. double candle_2 = iClose(Symbol(), PERIOD_CURRENT, 0 + 2);
  74. double value_1 = ((atrPercentageValue(i + 1) - atrPercentageValue(i + 2)) / atrPercentageValue(i + 2));
  75. double value_2 = ((atrPercentageValue(i) - atrPercentageValue(i + 1)) / atrPercentageValue(i + 1));
  76. double value_3 = ((atrPercentageValue(i) - atrPercentageValue(i + 2)) / atrPercentageValue(i + 2));
  77. double totalSum = value_1 + value_2 + value_3;
  78. atrPercentageBuffer[i] = ((atrValueIs / candle_1) * 100);
  79. if(totalSum > threshold)
  80. {
  81. signalBuffer[i] = totalSum;
  82. }
  83. else
  84. {
  85. noSignalBuffer[i] = totalSum;
  86. }
  87. Print("Time Current Candle: ", iClose(Symbol(), PERIOD_CURRENT,0),
  88. " | Time Candle 1: ", iClose(Symbol(), PERIOD_CURRENT, 0 + 1),
  89. " | Time Candle 2: ", iClose(Symbol(), PERIOD_CURRENT, 0 + 2),
  90. " | ATR Value: ", atrValueIs,
  91. " | value_1: ", value_1,
  92. " | value_2: ", value_2,
  93. " | value_3: ", value_3,
  94. " | Sum: ", NormalizeDouble(totalSum, Digits()),
  95. " | i: ", i);
  96. i--;
  97. }
  98. //--- return value of prev_calculated for next call
  99. return(rates_total);
  100. }
  101. //+------------------------------------------------------------------+
  102. //+------------------------------------------------------------------+
  103. //| |
  104. //+------------------------------------------------------------------+
  105. double atrValue(int index)
  106. {
  107. return NormalizeDouble(iATR(Symbol(), PERIOD_CURRENT, atrPeriod, index), Digits());
  108. }
  109. //+------------------------------------------------------------------+
  110. //| |
  111. //+------------------------------------------------------------------+
  112. double atrPercentageValue(int index)
  113. {
  114. return (iATR(Symbol(), PERIOD_CURRENT, atrPeriod, index) / iClose(Symbol(), PERIOD_CURRENT, index)) * 100;
  115. }
  116. //+------------------------------------------------------------------+
  117. //| |
  118. //+------------------------------------------------------------------+
  119. //+------------------------------------------------------------------+