|
|
@@ -0,0 +1,134 @@
|
|
|
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
|
+
|
|
|
17
|
+input string string_1 = "<><><><><><> General SETTINGS <><><><><><>"; //__
|
|
|
18
|
+input double threshold = 0.00001; // Threshold Value
|
|
|
19
|
+
|
|
|
20
|
+sinput string atrSettings = " <><><><><> Atr Settings <><><><><> "; //_
|
|
|
21
|
+input int atrPeriod = 14; // ATR Period
|
|
|
22
|
+
|
|
|
23
|
+input string string_2_2 = "<><><><><><> Color Setting <><><><><><>"; //__
|
|
|
24
|
+input color atr_line_color = clrAqua; // Atr Line Color
|
|
|
25
|
+input color signal_color = clrLimeGreen; // Signal Color
|
|
|
26
|
+input color no_signal_color = clrSlateGray; // No Signal Color
|
|
|
27
|
+
|
|
|
28
|
+// Global Variables
|
|
|
29
|
+double atrPercentageBuffer[];
|
|
|
30
|
+double signalBuffer[];
|
|
|
31
|
+double noSignalBuffer[];
|
|
|
32
|
+string short_name="";
|
|
|
33
|
+int OnInit()
|
|
|
34
|
+ {
|
|
|
35
|
+//--- indicator buffers mapping
|
|
|
36
|
+ SetIndexBuffer(0, atrPercentageBuffer);
|
|
|
37
|
+ SetIndexBuffer(1, signalBuffer);
|
|
|
38
|
+ SetIndexBuffer(2, noSignalBuffer);
|
|
|
39
|
+
|
|
|
40
|
+//--- Set buffer names
|
|
|
41
|
+ SetIndexLabel(0, "Atr %");
|
|
|
42
|
+ SetIndexLabel(1, "Signal");
|
|
|
43
|
+ SetIndexLabel(2, "No Signal");
|
|
|
44
|
+
|
|
|
45
|
+ SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2, atr_line_color);
|
|
|
46
|
+ SetIndexStyle(1, DRAW_HISTOGRAM, STYLE_SOLID, 4, signal_color);
|
|
|
47
|
+ SetIndexStyle(2, DRAW_HISTOGRAM, STYLE_SOLID, 4, no_signal_color);
|
|
|
48
|
+
|
|
|
49
|
+ short_name = "atr_momentum_indicator_mt4";
|
|
|
50
|
+ IndicatorShortName(short_name);
|
|
|
51
|
+//---
|
|
|
52
|
+ return(INIT_SUCCEEDED);
|
|
|
53
|
+ }
|
|
|
54
|
+//+------------------------------------------------------------------+
|
|
|
55
|
+//| Custom indicator iteration function |
|
|
|
56
|
+//+------------------------------------------------------------------+
|
|
|
57
|
+int OnCalculate(const int rates_total,
|
|
|
58
|
+ const int prev_calculated,
|
|
|
59
|
+ const datetime &time[],
|
|
|
60
|
+ const double &open[],
|
|
|
61
|
+ const double &high[],
|
|
|
62
|
+ const double &low[],
|
|
|
63
|
+ const double &close[],
|
|
|
64
|
+ const long &tick_volume[],
|
|
|
65
|
+ const long &volume[],
|
|
|
66
|
+ const int &spread[])
|
|
|
67
|
+ {
|
|
|
68
|
+//---
|
|
|
69
|
+ int i, Counted_bars;
|
|
|
70
|
+ Counted_bars=IndicatorCounted(); // Number of counted bars
|
|
|
71
|
+ if(prev_calculated == 0)
|
|
|
72
|
+ i=Bars-Counted_bars-10;
|
|
|
73
|
+ else
|
|
|
74
|
+ i=Bars-Counted_bars-1;
|
|
|
75
|
+
|
|
|
76
|
+ while(i >= 0)
|
|
|
77
|
+ {
|
|
|
78
|
+ double atrValueIs = atrValue(i);
|
|
|
79
|
+ double candle_0 = iClose(Symbol(), PERIOD_CURRENT, 0);
|
|
|
80
|
+ double candle_1 = iClose(Symbol(), PERIOD_CURRENT, 0 + 1);
|
|
|
81
|
+ double candle_2 = iClose(Symbol(), PERIOD_CURRENT, 0 + 2);
|
|
|
82
|
+
|
|
|
83
|
+ double value_1 = ((atrPercentageValue(i + 1) - atrPercentageValue(i + 2)) / atrPercentageValue(i + 2));
|
|
|
84
|
+ double value_2 = ((atrPercentageValue(i) - atrPercentageValue(i + 1)) / atrPercentageValue(i + 1));
|
|
|
85
|
+ double value_3 = ((atrPercentageValue(i) - atrPercentageValue(i + 2)) / atrPercentageValue(i + 2));
|
|
|
86
|
+
|
|
|
87
|
+ double totalSum = value_1 + value_2 + value_3;
|
|
|
88
|
+
|
|
|
89
|
+ atrPercentageBuffer[i] = ((atrValueIs / candle_1) * 100);
|
|
|
90
|
+
|
|
|
91
|
+ if(totalSum > threshold)
|
|
|
92
|
+ {
|
|
|
93
|
+ signalBuffer[i] = totalSum;
|
|
|
94
|
+ }
|
|
|
95
|
+ else
|
|
|
96
|
+ {
|
|
|
97
|
+ noSignalBuffer[i] = totalSum;
|
|
|
98
|
+ }
|
|
|
99
|
+
|
|
|
100
|
+ Print("Time Current Candle: ", iClose(Symbol(), PERIOD_CURRENT,0),
|
|
|
101
|
+ " | Time Candle 1: ", iClose(Symbol(), PERIOD_CURRENT, 0 + 1),
|
|
|
102
|
+ " | Time Candle 2: ", iClose(Symbol(), PERIOD_CURRENT, 0 + 2),
|
|
|
103
|
+ " | ATR Value: ", atrValueIs,
|
|
|
104
|
+ " | value_1: ", value_1,
|
|
|
105
|
+ " | value_2: ", value_2,
|
|
|
106
|
+ " | value_3: ", value_3,
|
|
|
107
|
+ " | Sum: ", NormalizeDouble(totalSum, Digits()),
|
|
|
108
|
+ " | i: ", i);
|
|
|
109
|
+
|
|
|
110
|
+ i--;
|
|
|
111
|
+ }
|
|
|
112
|
+//--- return value of prev_calculated for next call
|
|
|
113
|
+ return(rates_total);
|
|
|
114
|
+ }
|
|
|
115
|
+//+------------------------------------------------------------------+
|
|
|
116
|
+//+------------------------------------------------------------------+
|
|
|
117
|
+//| |
|
|
|
118
|
+//+------------------------------------------------------------------+
|
|
|
119
|
+double atrValue(int index)
|
|
|
120
|
+ {
|
|
|
121
|
+ return NormalizeDouble(iATR(Symbol(), PERIOD_CURRENT, atrPeriod, index), Digits());
|
|
|
122
|
+ }
|
|
|
123
|
+//+------------------------------------------------------------------+
|
|
|
124
|
+//| |
|
|
|
125
|
+//+------------------------------------------------------------------+
|
|
|
126
|
+double atrPercentageValue(int index)
|
|
|
127
|
+ {
|
|
|
128
|
+ return (iATR(Symbol(), PERIOD_CURRENT, atrPeriod, index) / iClose(Symbol(), PERIOD_CURRENT, index)) * 100;
|
|
|
129
|
+ }
|
|
|
130
|
+//+------------------------------------------------------------------+
|
|
|
131
|
+//| |
|
|
|
132
|
+//+------------------------------------------------------------------+
|
|
|
133
|
+
|
|
|
134
|
+//+------------------------------------------------------------------+
|