generated from EA31337/Strategy-Demo
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Indi_SVE_Bollinger_Bands.mqh
124 lines (114 loc) · 4.67 KB
/
Indi_SVE_Bollinger_Bands.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
//+------------------------------------------------------------------+
//| 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_SVE_BOLLINGER_BANDS_MQH
#define INDI_SVE_BOLLINGER_BANDS_MQH
// Defines.
#define INDI_SVEBB_PATH "indicators-other\\Oscillator"
// Indicator line identifiers used in the indicator.
enum ENUM_SVE_BAND_LINE {
SVE_BAND_MAIN = 0, // Main line.
SVE_BAND_UPPER = 1, // Upper limit.
SVE_BAND_LOWER = 2, // Lower limit.
FINAL_SVE_BAND_LINE_ENTRY,
};
// Structs.
// Defines struct to store indicator parameter values.
struct IndiSVEBBParams : public IndicatorParams {
// Indicator params.
int TEMAPeriod;
int SvePeriod;
double BBUpDeviations;
double BBDnDeviations;
int DeviationsPeriod;
// Struct constructors.
void IndiSVEBBParams(int _tema_period = 8, int _sve_period = 18, double _deviations_up = 1.6,
double _deviations_down = 1.6, int _deviations_period = 63, int _shift = 0)
: TEMAPeriod(_tema_period),
SvePeriod(_sve_period),
BBUpDeviations(_deviations_up),
BBDnDeviations(_deviations_down),
DeviationsPeriod(_deviations_period) {
#ifdef __resource__
custom_indi_name = "::" + INDI_SVEBB_PATH + "\\SVE_Bollinger_Bands";
#else
custom_indi_name = "SVE_Bollinger_Bands";
#endif
};
void IndiSVEBBParams(IndiSVEBBParams &_params, ENUM_TIMEFRAMES _tf) {
THIS_REF = _params;
tf = _tf;
}
// Getters.
int GetTEMAPeriod() { return TEMAPeriod; }
int GetSvePeriod() { return SvePeriod; }
double GetBBUpDeviations() { return BBUpDeviations; }
double GetBBDnDeviations() { return BBDnDeviations; }
int GetDeviationsPeriod() { return DeviationsPeriod; }
// Setters.
void SetTEMAPeriod(int _value) { TEMAPeriod = _value; }
void SetSvePeriod(int _value) { SvePeriod = _value; }
void SetBBUpDeviations(double _value) { BBUpDeviations = _value; }
void SetBBDnDeviations(double _value) { BBDnDeviations = _value; }
void SetDeviationsPeriod(int _value) { DeviationsPeriod = _value; }
};
/**
* Implements indicator class.
*/
class Indi_SVE_Bollinger_Bands : public Indicator<IndiSVEBBParams> {
public:
/**
* Class constructor.
*/
Indi_SVE_Bollinger_Bands(IndiSVEBBParams &_p, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_ICUSTOM,
IndicatorBase *_indi_src = NULL, int _indi_src_mode = 0)
: Indicator<IndiSVEBBParams>(_p,
IndicatorDataParams::GetInstance(FINAL_SVE_BAND_LINE_ENTRY, TYPE_DOUBLE, _idstype,
IDATA_RANGE_MIXED, _indi_src_mode),
_indi_src) {}
Indi_SVE_Bollinger_Bands(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT) : Indicator(INDI_SVE_BB, _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, iparams.GetTEMAPeriod(),
iparams.GetSvePeriod(), iparams.GetBBUpDeviations(), iparams.GetBBDnDeviations(),
iparams.GetDeviationsPeriod(), _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) {
return Indicator<IndiSVEBBParams>::IsValidEntry(_entry) && _entry.GetMin<double>() > 0 &&
_entry.values[(int)SVE_BAND_UPPER].IsGt<double>(SVE_BAND_LOWER);
}
};
#endif // INDI_SVE_BOLLINGER_BANDS_MQH