generated from EA31337/Strategy-Demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIndi_ATR_MA_Slope.mqh
125 lines (112 loc) · 4.54 KB
/
Indi_ATR_MA_Slope.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
//+------------------------------------------------------------------+
//| Copyright 2016-2023, EA31337 Ltd |
//| https://github.com/EA31337 |
//+------------------------------------------------------------------+
/*
* This file is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
// Prevents processing the same indicator file twice.
#ifndef INDI_ATR_MA_SLOPE_MQH
#define INDI_ATR_MA_SLOPE_MQH
// Defines
#define INDI_ATR_MA_SLOPE_PATH "indicators-other\\Oscillators\\Arrows"
// Indicator line identifiers used in the indicator.
enum ENUM_ATR_MA_SLOPE_MODE {
ATR_MA_SLOPE_SLOPE = 0, // Slope
ATR_MA_SLOPE_LONG = 1, // Long signal
ATR_MA_SLOPE_SHORT = 2, // Short signal
ATR_MA_SLOPE_FLAT = 3, // Neutral plot
FINAL_ATR_MA_SLOPE_MODE_ENTRY, // n/a
};
// Structs.
// Defines struct to store indicator parameter values.
struct IndiAtrMaSlopeParams : public IndicatorParams {
// Indicator params.
int number_of_bars;
double slope_threshold;
int slope_ma_period;
int slope_atr_period;
// Struct constructors.
IndiAtrMaSlopeParams(int _number_of_bars = 100, double _slope_threshold = 2.0, int _slope_ma_period = 7,
int _slope_atr_period = 50, int _shift = 0)
: number_of_bars(_number_of_bars),
slope_threshold(_slope_threshold),
slope_ma_period(_slope_ma_period),
slope_atr_period(_slope_atr_period) {
#ifdef __resource__
custom_indi_name = "::" + INDI_ATR_MA_SLOPE_PATH + "\\ATR_MA_Slope";
#else
custom_indi_name = "ATR_MA_Slope";
#endif
};
IndiAtrMaSlopeParams(IndiAtrMaSlopeParams &_params, ENUM_TIMEFRAMES _tf) {
THIS_REF = _params;
tf = _tf;
}
// Getters.
int GetNumberOfBars() { return number_of_bars; }
double GetThreshold() { return slope_threshold; }
int GetMaPeriod() { return slope_ma_period; }
int GetAtrPeriod() { return slope_atr_period; }
// Setters.
void SetNumberOfBars(int _value) { number_of_bars = _value; }
void SetThreshold(double _value) { slope_threshold = _value; }
void SetMaPeriod(int _value) { slope_ma_period = _value; }
void SetAtrPeriod(int _value) { slope_atr_period = _value; }
};
/**
* Implements indicator class.
*/
class Indi_ATR_MA_Slope : public Indicator<IndiAtrMaSlopeParams> {
public:
/**
* Class constructor.
*/
Indi_ATR_MA_Slope(IndiAtrMaSlopeParams &_p, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_ICUSTOM,
IndicatorBase *_indi_src = NULL, int _indi_src_mode = 0)
: Indicator<IndiAtrMaSlopeParams>(_p,
IndicatorDataParams::GetInstance(FINAL_ATR_MA_SLOPE_MODE_ENTRY, TYPE_DOUBLE,
_idstype, IDATA_RANGE_PRICE, _indi_src_mode),
_indi_src) {}
Indi_ATR_MA_Slope(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_CUSTOM, _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_ICUSTOM:
_value =
iCustom(istate.handle, GetSymbol(), GetTf(), iparams.custom_indi_name, GetTf(), iparams.GetNumberOfBars(),
iparams.GetThreshold(), iparams.GetMaPeriod(), iparams.GetAtrPeriod(), _mode, _ishift);
break;
default:
SetUserError(ERR_INVALID_PARAMETER);
_value = EMPTY_VALUE;
break;
}
return _value;
}
/**
* Checks if indicator entry values are valid.
*/
virtual bool IsValidEntry(IndicatorDataEntry &_entry) {
// Slope value needs to be positive exempt DBL_MAX.
return _entry.values[(int)ATR_MA_SLOPE_SLOPE].IsGt(0) && _entry.values[(int)ATR_MA_SLOPE_SLOPE] != DBL_MAX;
}
};
#endif // INDI_ATR_MA_SLOPE_MQH