Repository navigation
Expand file tree
/
Copy pathToIndicator.mqh
More file actions
290 lines (272 loc) · 8.74 KB
/
Copy pathToIndicator.mqh
File metadata and controls
290 lines (272 loc) · 8.74 KB
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* https://github.com/Roffild/RoffildLibrary
*/
struct SToIndicator_Data
{
double number;
datetime time;
ushort plot;
uchar color_index;
char buffer;
};
struct SToIndicator_Parameter
{
double double_value;
int index;
int property;
int int_value;
int modifier;
ushort text[256];
};
enum ENUM_TOINDICATOR
{
TOINDICATOR_DATA = 55,
TOINDICATOR_PARAMETER_MIN,
TOINDICATOR_PLOT_ADD,
TOINDICATOR_PLOT_INTEGER,
TOINDICATOR_PLOT_INTEGER_MOD,
TOINDICATOR_PLOT_DOUBLE,
TOINDICATOR_PLOT_STRING,
TOINDICATOR_INDIC_INTEGER,
TOINDICATOR_INDIC_INTEGER_MOD,
TOINDICATOR_INDIC_DOUBLE,
TOINDICATOR_INDIC_DOUBLE_MOD,
TOINDICATOR_INDIC_STRING,
TOINDICATOR_INDIC_STRING_MOD,
TOINDICATOR_PARAMETER_MAX
};
/**
* Displaying data from Expert or Script using functions for indicators.
*
* Example:
* https://github.com/Roffild/RoffildLibrary/blob/master/Experts/Roffild/Examples/ToIndicator_Example.mq5
*/
class CToIndicator
{
public:
string id;
bool window;
int handleFile, handleIndicator;
CToIndicator() : handleFile(INVALID_HANDLE), handleIndicator(INVALID_HANDLE)
{}
~CToIndicator()
{
close();
}
/**
* (First) Creating an indicator file.
*/
int init(const string _id, const bool _window = false, const bool ignore_visual = false)
{
id = _id;
if (MQLInfoInteger(MQL_TESTER) == 0 || (ignore_visual || MQLInfoInteger(MQL_VISUAL_MODE))) {
handleFile = FileOpen("ToIndicator/" + id, FILE_BIN|FILE_WRITE|FILE_SHARE_READ|FILE_SHARE_WRITE);
window = _window;
return handleFile;
}
return INVALID_HANDLE;
}
/**
* Show the indicator on the graph.
* It is recommended to call at the end of testing, but you can not use it in OnDeinit().
*/
int show()
{
if (handleFile != INVALID_HANDLE && handleIndicator == INVALID_HANDLE) {
flush();
handleIndicator = iCustom(Symbol(), Period(), "Roffild/ToIndicator" + (window ? "_window" : ""), id);
}
return handleIndicator;
}
/**
* (Second) Add plot to indicator.
*/
bool addPlot(ENUM_DRAW_TYPE type, string name, double empty_value = 0)
{
if (handleFile != INVALID_HANDLE) {
FileWriteInteger(handleFile, TOINDICATOR_PLOT_ADD, CHAR_VALUE);
SToIndicator_Parameter param = {0};
param.property = type;
param.double_value = empty_value;
StringToShortArray(name, param.text);
FileWriteStruct(handleFile, param);
return true;
}
return false;
}
/**
* Assigning a value to the indicator's buffer.
* @param value
* @param plot index of plot
* @param color_index index of color
* @param buffer index of buffer (-1 = the rules for assigning values depend on the type of the plot)
* @param time
*/
void buffer(double value, ushort plot, uchar color_index = 0, char buffer = -1, datetime time = 0)
{
if (handleFile != INVALID_HANDLE) {
FileWriteInteger(handleFile, TOINDICATOR_DATA, CHAR_VALUE);
SToIndicator_Data data = {0};
data.number = value;
data.color_index = color_index;
data.plot = plot;
data.buffer = buffer;
data.time = time > 0 ? time : TimeCurrent();
FileWriteStruct(handleFile, data);
}
return;
}
void flush()
{
if (handleFile != INVALID_HANDLE) {
FileFlush(handleFile);
}
}
void close()
{
if (handleFile != INVALID_HANDLE) {
FileClose(handleFile);
}
}
bool plotIndexSetInteger(int plot_index, ENUM_PLOT_PROPERTY_INTEGER prop_id,
int prop_modifier, int prop_value)
{
if (handleFile != INVALID_HANDLE) {
FileWriteInteger(handleFile, TOINDICATOR_PLOT_INTEGER_MOD, CHAR_VALUE);
SToIndicator_Parameter param = {0};
param.index = plot_index;
param.property = prop_id;
param.modifier = prop_modifier;
param.int_value = prop_value;
FileWriteStruct(handleFile, param);
return true;
}
return false;
}
bool plotIndexSetInteger(int plot_index, ENUM_PLOT_PROPERTY_INTEGER prop_id, int prop_value)
{
if (handleFile != INVALID_HANDLE) {
FileWriteInteger(handleFile, TOINDICATOR_PLOT_INTEGER, CHAR_VALUE);
SToIndicator_Parameter param = {0};
param.index = plot_index;
param.property = prop_id;
param.int_value = prop_value;
FileWriteStruct(handleFile, param);
return true;
}
return false;
}
bool plotIndexSetDouble(int plot_index, ENUM_PLOT_PROPERTY_DOUBLE prop_id, double prop_value)
{
if (handleFile != INVALID_HANDLE) {
FileWriteInteger(handleFile, TOINDICATOR_PLOT_DOUBLE, CHAR_VALUE);
SToIndicator_Parameter param = {0};
param.index = plot_index;
param.property = prop_id;
param.double_value = prop_value;
FileWriteStruct(handleFile, param);
return true;
}
return false;
}
bool plotIndexSetString(int plot_index, ENUM_PLOT_PROPERTY_STRING prop_id, string prop_value)
{
if (handleFile != INVALID_HANDLE) {
FileWriteInteger(handleFile, TOINDICATOR_PLOT_STRING, CHAR_VALUE);
SToIndicator_Parameter param = {0};
param.index = plot_index;
param.property = prop_id;
StringToShortArray(prop_value, param.text);
FileWriteStruct(handleFile, param);
return true;
}
return false;
}
bool indicatorSetInteger(ENUM_CUSTOMIND_PROPERTY_INTEGER prop_id, int prop_modifier, int prop_value)
{
if (handleFile != INVALID_HANDLE) {
FileWriteInteger(handleFile, TOINDICATOR_INDIC_INTEGER_MOD, CHAR_VALUE);
SToIndicator_Parameter param = {0};
param.property = prop_id;
param.modifier = prop_modifier;
param.int_value = prop_value;
FileWriteStruct(handleFile, param);
return true;
}
return false;
}
bool indicatorSetInteger(ENUM_CUSTOMIND_PROPERTY_INTEGER prop_id, int prop_value)
{
if (handleFile != INVALID_HANDLE) {
FileWriteInteger(handleFile, TOINDICATOR_INDIC_INTEGER, CHAR_VALUE);
SToIndicator_Parameter param = {0};
param.property = prop_id;
param.int_value = prop_value;
FileWriteStruct(handleFile, param);
return true;
}
return false;
}
bool indicatorSetDouble(ENUM_CUSTOMIND_PROPERTY_DOUBLE prop_id, int prop_modifier, double prop_value)
{
if (handleFile != INVALID_HANDLE) {
FileWriteInteger(handleFile, TOINDICATOR_INDIC_DOUBLE_MOD, CHAR_VALUE);
SToIndicator_Parameter param = {0};
param.property = prop_id;
param.modifier = prop_modifier;
param.double_value = prop_value;
FileWriteStruct(handleFile, param);
return true;
}
return false;
}
bool indicatorSetDouble(ENUM_CUSTOMIND_PROPERTY_DOUBLE prop_id, double prop_value)
{
if (handleFile != INVALID_HANDLE) {
FileWriteInteger(handleFile, TOINDICATOR_INDIC_DOUBLE, CHAR_VALUE);
SToIndicator_Parameter param = {0};
param.property = prop_id;
param.double_value = prop_value;
FileWriteStruct(handleFile, param);
return true;
}
return false;
}
bool indicatorSetString(ENUM_CUSTOMIND_PROPERTY_STRING prop_id, int prop_modifier, string prop_value)
{
if (handleFile != INVALID_HANDLE) {
FileWriteInteger(handleFile, TOINDICATOR_INDIC_STRING_MOD, CHAR_VALUE);
SToIndicator_Parameter param = {0};
param.property = prop_id;
param.modifier = prop_modifier;
StringToShortArray(prop_value, param.text);
FileWriteStruct(handleFile, param);
return true;
}
return false;
}
bool indicatorSetString(ENUM_CUSTOMIND_PROPERTY_STRING prop_id, string prop_value)
{
if (handleFile != INVALID_HANDLE) {
FileWriteInteger(handleFile, TOINDICATOR_INDIC_STRING, CHAR_VALUE);
SToIndicator_Parameter param = {0};
param.property = prop_id;
StringToShortArray(prop_value, param.text);
FileWriteStruct(handleFile, param);
return true;
}
return false;
}
};