-
-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathIndi_Drawer.mqh
227 lines (192 loc) · 6.66 KB
/
Indi_Drawer.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
//+------------------------------------------------------------------+
//| 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/>.
*
*/
// Forward declaration.
struct IndicatorParams;
// Includes.
#include "../DictStruct.mqh"
#include "../Indicator/IndicatorTickOrCandleSource.h"
#include "../Redis.mqh"
#include "../Task/TaskAction.h"
#include "Indi_Drawer.struct.h"
#include "Price/Indi_Price.mqh"
/**
* Implements the Relative Strength Index indicator.
*/
class Indi_Drawer : public IndicatorTickOrCandleSource<IndiDrawerParams> {
Redis redis;
public:
/**
* Class constructor.
*/
Indi_Drawer(const IndiDrawerParams &_p, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN,
IndicatorData *_indi_src = NULL, int _indi_src_mode = 0)
: IndicatorTickOrCandleSource(
_p, IndicatorDataParams::GetInstance(0, TYPE_DOUBLE, _idstype, IDATA_RANGE_UNKNOWN, _indi_src_mode),
_indi_src),
redis(true) {
Init();
}
Indi_Drawer(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0)
: IndicatorTickOrCandleSource(INDI_DRAWER, _tf, _shift), redis(true) {
Init();
}
void Init() {
// Drawer is always ready.
/*
string msg_text =
"*3\r\n"
"$7\r\n"
"message\r\n"
"$14\r\n"
"INDICATOR_DRAW\r\n"
"$67\r\n"
"{\"flags\":2,\"last_success\":0,\"action_id\":6,\"type\":11,\"frequency\":34}\r\n";
redis.Messages().Enqueue(msg);
redis.Messages().Enqueue(msg_text);
*/
}
virtual bool ExecuteAction(ENUM_INDICATOR_ACTION _action, DataParamEntry &_args[]) {
int num_args = ArraySize(_args), i;
int _max_modes = Get<int>(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES));
IndicatorDataEntry entry(num_args - 1);
if (_action == INDI_ACTION_SET_VALUE) {
Set<int>(STRUCT_ENUM(IndicatorDataParams, IDATA_PARAM_MAX_MODES), num_args - 1);
if (num_args - 1 > _max_modes) {
GetLogger().Error(
StringFormat("Too many data for buffers for action %s!", EnumToString(_action), __FUNCTION_LINE__));
return false;
}
for (i = 1; i < num_args; ++i) {
entry.values[i - 1].Set(_args[i].double_value);
}
// Assuming that passed values are correct.
entry.AddFlags(INDI_ENTRY_FLAG_IS_VALID);
idata.Add(entry, _args[0].integer_value);
return true;
}
return false;
}
virtual void OnTick() {
Indicator<IndiDrawerParams>::OnTick();
/* @fixme
TaskActionEntry action(INDI_ACTION_SET_VALUE);
ArrayResize(action.args, 3);
action.args[0].type = TYPE_LONG;
action.args[0].integer_value = GetBarTime();
action.args[1].type = TYPE_DOUBLE;
action.args[1].double_value = 1.2;
action.args[2].type = TYPE_DOUBLE;
action.args[2].double_value = 1.25;
*/
//string json = SerializerConverter::FromObject(action).ToString<SerializerJson>(/*SERIALIZER_JSON_NO_WHITESPACES*/);
/* @fixme
RedisMessage msg;
msg.Add("message");
msg.Add("INDICATOR_DRAW");
msg.Add(json);
redis.Messages().Enqueue(msg);
while (redis.HasData()) {
// Parsing commands.
RedisMessage message = redis.ReadMessage();
#ifdef __debug__
Print("Got: ", message.Message);
#endif
if (message.Command == "message" && message.Channel == "INDICATOR_DRAW") {
TaskActionEntry action_entry;
SerializerConverter::FromString<SerializerJson>(message.Message).ToObject(action_entry);
ExecuteAction((ENUM_INDICATOR_ACTION)action_entry.action_id, action_entry.args);
#ifdef __debug__
Print("Deserialized action: ",
SerializerConverter::FromObject(action_entry).ToString<SerializerJson>(SERIALIZER_JSON_NO_WHITESPACES));
#endif
// Drawing on the buffer.
}
}
*/
}
Redis *Redis() { return &redis; }
/**
* Returns the indicator value.
*
* @docs
* - https://docs.mql4.com/indicators/irsi
* - https://www.mql5.com/en/docs/indicators/irsi
*/
static double iDrawer(string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0,
IndicatorData *_obj = NULL) {
return 1.0;
}
/**
* Performs drawing on data from other indicator.
*/
static double iDrawerOnIndicator(IndicatorData *_indi, Indi_Drawer *_obj, string _symbol = NULL,
ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0) {
// This method is not yet implemented.
return 1.0;
}
/**
* Performs drawing from data in array.
*/
static double iDrawerOnArray(double &array[], int total, int period, int shift) { return 0; }
/* Getters */
/**
* Returns the indicator's value.
*/
virtual 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:
_value = Indi_Drawer::iDrawer(GetSymbol(), GetTf(), _ishift, THIS_PTR);
break;
case IDATA_INDICATOR:
_value = Indi_Drawer::iDrawerOnIndicator(GetDataSource(), THIS_PTR, GetSymbol(), GetTf(), _ishift);
break;
default:
SetUserError(ERR_INVALID_PARAMETER);
break;
}
return _value;
}
/**
* Get period value.
*/
unsigned int GetPeriod() { return iparams.period; }
/**
* Get applied price value.
*/
ENUM_APPLIED_PRICE GetAppliedPrice() { return iparams.applied_price; }
/* Setters */
/**
* Set period value.
*/
void SetPeriod(unsigned int _period) {
istate.is_changed = true;
iparams.period = _period;
}
/**
* Set applied price value.
*/
void SetAppliedPrice(ENUM_APPLIED_PRICE _applied_price) {
istate.is_changed = true;
iparams.applied_price = _applied_price;
}
};