-
Notifications
You must be signed in to change notification settings - Fork 3
/
Indi_ATR_MA_Trend.mqh
176 lines (155 loc) · 4.39 KB
/
Indi_ATR_MA_Trend.mqh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/**
* @file
* Implements indicator class.
*/
// Defines
#define INDI_ATR_MA_TREND_PATH "indicators-other\\Misc"
// Enums.
// Indicator mode identifiers used in ATR MA Trend indicator.
enum ENUM_INDI_ATR_MA_TREND_MODE {
INDI_ATR_MA_TREND_UP = 0,
INDI_ATR_MA_TREND_DOWN,
INDI_ATR_MA_TREND_UP2,
INDI_ATR_MA_TREND_DOWN2,
FINAL_INDI_ATR_MA_TREND_ENTRY,
};
// Structs.
struct Indi_ATR_MA_Trend_Params : IndicatorParams {
int period;
double shift_percent;
int atr_period;
double atr_sensitivity;
int indi_shift;
ENUM_APPLIED_PRICE applied_price;
// Struct constructor.
void Indi_ATR_MA_Trend_Params(int _period = 13, double _shift_percent = 0, int _atr_period = 15,
double _atr_sensitivity = 1.5, int _indi_shift = 0, int _shift = 0)
: period(_period),
shift_percent(_shift_percent),
atr_period(_atr_period),
atr_sensitivity(_atr_sensitivity),
indi_shift(_indi_shift) {
#ifdef __resource__
custom_indi_name = "::" + INDI_ATR_MA_TREND_PATH + "\\ATR_MA_Trend";
#else
custom_indi_name = "ATR_MA_Trend";
#endif
itype = INDI_ATR;
};
void Indi_ATR_MA_Trend_Params(Indi_ATR_MA_Trend_Params &_params, ENUM_TIMEFRAMES _tf) {
this = _params;
_params.tf = _tf;
}
};
/**
* Indicator class.
*/
class Indi_ATR_MA_Trend : public Indicator<Indi_ATR_MA_Trend_Params> {
public:
/**
* Class constructor.
*/
Indi_ATR_MA_Trend(Indi_ATR_MA_Trend_Params &_p, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_ICUSTOM,
IndicatorBase *_indi_src = NULL, int _indi_src_mode = 0)
: Indicator<Indi_ATR_MA_Trend_Params>(
_p,
IndicatorDataParams::GetInstance(FINAL_INDI_ATR_MA_TREND_ENTRY, TYPE_DOUBLE, _idstype, IDATA_RANGE_MIXED,
_indi_src_mode),
_indi_src) {}
Indi_ATR_MA_Trend(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_ATR, _tf){};
/**
* Returns the indicator's value.
*/
IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = -1) {
double _value = EMPTY_VALUE;
int _ishift = _shift >= 0 ? _shift : iparams.GetShift();
switch (Get<ENUM_IDATA_SOURCE_TYPE>(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) {
case IDATA_BUILTIN:
break;
case IDATA_ICUSTOM:
istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle;
_value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.custom_indi_name, GetTf(), GetPeriod(),
GetShiftPercent(), GetATRPeriod(), GetATRSensitivity(), GetIndiShift(), _mode, _ishift);
break;
case IDATA_INDICATOR:
// @todo: Add custom calculation.
break;
}
return _value;
}
/* Getters */
/**
* Gets period value.
*/
int GetPeriod() { return iparams.period; }
/**
* Gets indicator shift in percent.
*/
double GetShiftPercent() { return iparams.shift_percent; }
/**
* Gets ATR indicator period.
*/
int GetATRPeriod() { return iparams.atr_period; }
/**
* Gets ATR indicator sensitivity.
*/
double GetATRSensitivity() { return iparams.atr_sensitivity; }
/**
* Gets indicator shift.
*/
int GetIndiShift() { return iparams.indi_shift; }
/**
* Gets buffer shift.
*/
int GetShift() { return iparams.shift; }
/* Setters */
/**
* Sets period value.
*/
void SetPeriod(int _period) {
istate.is_changed = true;
iparams.period = _period;
}
/**
* Sets applied price value.
*/
void SetAppliedPrice(ENUM_APPLIED_PRICE _applied_price) {
istate.is_changed = true;
iparams.applied_price = _applied_price;
}
/**
* Sets indicator shift in percent.
*/
void GetShiftPercent(double _shift_percent) {
istate.is_changed = true;
iparams.shift_percent = _shift_percent;
}
/**
* Sets ATR indicator period.
*/
void GetATRPeriod(int _atr_period) {
istate.is_changed = true;
iparams.atr_period = _atr_period;
}
/**
* Sets ATR indicator sensitivity.
*/
void GetATRSensitivity(double _atr_sensitivity) {
istate.is_changed = true;
iparams.atr_sensitivity = _atr_sensitivity;
}
/**
* Gets indicator shift.
*/
void GetIndiShift(int _indi_shift) {
istate.is_changed = true;
iparams.indi_shift = _indi_shift;
}
/**
* Gets buffer shift.
*/
void GetShift(int _shift) {
istate.is_changed = true;
iparams.shift = _shift;
}
};