-
-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathIndi_RS.mqh
120 lines (108 loc) · 4.01 KB
/
Indi_RS.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
//+------------------------------------------------------------------+
//| EA31337 framework |
//| 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/>.
*
*/
// Includes.
#include "../BufferStruct.mqh"
#include "../Indicator/IndicatorTickOrCandleSource.h"
#include "OHLC/Indi_OHLC.mqh"
#include "Special/Indi_Math.mqh"
// Structs.
struct IndiRSParams : IndicatorParams {
ENUM_APPLIED_VOLUME applied_volume;
// Struct constructor.
IndiRSParams(ENUM_APPLIED_VOLUME _applied_volume = VOLUME_TICK, int _shift = 0) : IndicatorParams(INDI_RS) {
applied_volume = _applied_volume;
shift = _shift;
};
IndiRSParams(IndiRSParams &_params, ENUM_TIMEFRAMES _tf) {
THIS_REF = _params;
tf = _tf;
};
};
/**
* Implements the Bill Williams' Accelerator/Decelerator oscillator.
*/
class Indi_RS : public IndicatorTickOrCandleSource<IndiRSParams> {
DictStruct<int, Ref<Indi_Math>> imath;
public:
/**
* Class constructor.
*/
Indi_RS(IndiRSParams &_p, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_MATH, IndicatorData *_indi_src = NULL,
int _indi_src_mode = 0)
: IndicatorTickOrCandleSource(
_p, IndicatorDataParams::GetInstance(2, TYPE_DOUBLE, _idstype, IDATA_RANGE_PRICE_DIFF, _indi_src_mode),
_indi_src) {
Init();
};
Indi_RS(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) : IndicatorTickOrCandleSource(INDI_RS, _tf, _shift) {
Init();
};
void Init() {
if (Get<ENUM_IDATA_SOURCE_TYPE>(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE)) == IDATA_MATH) {
IndiOHLCParams _iohlc_params();
// @todo Symbol should be already defined for a chart.
// @todo If it's not, move initialization to GetValue()/GetEntry() method.
Indi_OHLC *_iohlc = Indi_OHLC::GetCached(GetSymbol(), GetTf(), 0);
IndiMathParams _imath0_p(MATH_OP_SUB, INDI_OHLC_CLOSE, 0, INDI_OHLC_CLOSE, 1);
IndiMathParams _imath1_p(MATH_OP_SUB, INDI_OHLC_CLOSE, 1, INDI_OHLC_CLOSE, 0);
_imath0_p.SetTf(GetTf());
_imath1_p.SetTf(GetTf());
Ref<Indi_Math> _imath0 = new Indi_Math(_imath0_p);
Ref<Indi_Math> _imath1 = new Indi_Math(_imath1_p);
_imath0.Ptr().SetDataSource(_iohlc, 0);
_imath1.Ptr().SetDataSource(_iohlc, 0);
imath.Set(0, _imath0);
imath.Set(1, _imath1);
}
}
/**
* Returns the indicator's value.
*/
virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) {
int _ishift = _shift >= 0 ? _shift : iparams.GetShift();
switch (Get<ENUM_IDATA_SOURCE_TYPE>(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_IDSTYPE))) {
case IDATA_MATH:
return imath[_mode].Ptr().GetEntryValue();
break;
default:
SetUserError(ERR_INVALID_PARAMETER);
break;
}
return EMPTY_VALUE;
}
/**
* Checks if indicator entry values are valid.
*/
virtual bool IsValidEntry(IndicatorDataEntry &_entry) { return true; }
/* Getters */
/**
* Get applied volume.
*/
ENUM_APPLIED_VOLUME GetAppliedVolume() { return iparams.applied_volume; }
/* Setters */
/**
* Set applied volume.
*/
void SetAppliedVolume(ENUM_APPLIED_VOLUME _applied_volume) {
istate.is_changed = true;
iparams.applied_volume = _applied_volume;
}
};