forked from EA31337/EA31337-classes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimeseries.mqh
278 lines (259 loc) · 7.98 KB
/
Timeseries.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
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
/*
* Timeseries class
* Docs: https://docs.mql4.com/series
*/
class Timeseries
{
public:
#ifdef __MQL5__
static ENUM_TIMEFRAMES TFMigrate(int tf) {
switch(tf) {
case 0: return(PERIOD_CURRENT);
case 1: return(PERIOD_M1);
case 5: return(PERIOD_M5);
case 15: return(PERIOD_M15);
case 30: return(PERIOD_M30);
case 60: return(PERIOD_H1);
case 240: return(PERIOD_H4);
case 1440: return(PERIOD_D1);
case 10080: return(PERIOD_W1);
case 43200: return(PERIOD_MN1);
case 2: return(PERIOD_M2);
case 3: return(PERIOD_M3);
case 4: return(PERIOD_M4);
case 6: return(PERIOD_M6);
case 10: return(PERIOD_M10);
case 12: return(PERIOD_M12);
case 16385: return(PERIOD_H1);
case 16386: return(PERIOD_H2);
case 16387: return(PERIOD_H3);
case 16388: return(PERIOD_H4);
case 16390: return(PERIOD_H6);
case 16392: return(PERIOD_H8);
case 16396: return(PERIOD_H12);
case 16408: return(PERIOD_D1);
case 32769: return(PERIOD_W1);
case 49153: return(PERIOD_MN1);
default: return(PERIOD_CURRENT);
}
}
#endif
static bool RefreshRates ()
{
#ifdef __MQL5__
return true;
#else
return RefreshRates();
#endif
}
static int iBars(string symbol, int tf) {
#ifdef __MQL5__
ENUM_TIMEFRAMES timeframe = TFMigrate (tf);
return(Bars(symbol, timeframe));
#else
return iBars(symbol, tf);
#endif
}
static int iBarShift (string symbol, int tf, datetime time, bool exact = false) {
#ifdef __MQL5__
if (time < 0)
return -1;
ENUM_TIMEFRAMES timeframe = TFMigrate (tf);
datetime Arr[], time1;
CopyTime (symbol, timeframe, 0, 1, Arr);
time1 = Arr[0];
if (CopyTime (symbol, timeframe, time, time1, Arr) > 0)
{
if (ArraySize (Arr) > 2)
return ArraySize (Arr) - 1;
if (time < time1)
return 1;
else
return 0;
}
else
return -1;
#else
return iBarShift(symbol, tf, time, exact);
#endif
}
static double iClose(string symbol,int tf,int index) {
#ifdef __MQL5__
if(index < 0) return(-1);
double Arr[];
ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
if(CopyClose(symbol,timeframe, index, 1, Arr)>0)
return(Arr[0]);
else return(-1);
#else
return iClose(symbol, tf, index);
#endif
}
static double iHigh(string symbol,int tf,int index) {
#ifdef __MQL5__
if(index < 0) return(-1);
double Arr[];
ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
if(CopyHigh(symbol,timeframe, index, 1, Arr)>0)
return(Arr[0]);
else return(-1);
#else
return iHigh(symbol, tf, index);
#endif
}
static int iHighest(string symbol, int tf, int type, int count=WHOLE_ARRAY, int start=0) {
#ifdef __MQL5__
if(start<0) return(-1);
ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
if(count<=0) count=Bars(symbol,timeframe);
if(type<=MODE_OPEN)
{
double Open[];
ArraySetAsSeries(Open,true);
CopyOpen(symbol,timeframe,start,count,Open);
return(ArrayMaximum(Open,0,count)+start);
}
if(type==MODE_LOW)
{
double Low[];
ArraySetAsSeries(Low,true);
CopyLow(symbol,timeframe,start,count,Low);
return(ArrayMaximum(Low,0,count)+start);
}
if(type==MODE_HIGH)
{
double High[];
ArraySetAsSeries(High,true);
CopyHigh(symbol,timeframe,start,count,High);
return(ArrayMaximum(High,0,count)+start);
}
if(type==MODE_CLOSE)
{
double Close[];
ArraySetAsSeries(Close,true);
CopyClose(symbol,timeframe,start,count,Close);
return(ArrayMaximum(Close,0,count)+start);
}
if(type==MODE_VOLUME)
{
long Volume[];
ArraySetAsSeries(Volume,true);
CopyTickVolume(symbol,timeframe,start,count,Volume);
return(ArrayMaximum(Volume,0,count)+start);
}
if(type>=MODE_TIME)
{
datetime Time[];
ArraySetAsSeries(Time,true);
CopyTime(symbol,timeframe,start,count,Time);
return(ArrayMaximum(Time,0,count)+start);
}
return(0);
#else
return iHighest(symbol, tf, type, count, start);
#endif
}
static double iLow(string symbol,int tf,int index) {
#ifdef __MQL5__
if(index < 0) return(-1);
double Arr[];
ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
if(CopyLow(symbol,timeframe, index, 1, Arr)>0)
return(Arr[0]);
else return(-1);
#else
return iLow(symbol, tf, index);
#endif
}
static int iLowest(string symbol, int tf, int type, int count=WHOLE_ARRAY, int start=0) {
#ifdef __MQL5__
if(start<0) return(-1);
ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
if(count<=0) count=Bars(symbol,timeframe);
if(type<=MODE_OPEN)
{
double Open[];
ArraySetAsSeries(Open,true);
CopyOpen(symbol,timeframe,start,count,Open);
return(ArrayMinimum(Open,0,count)+start);
}
if(type==MODE_LOW)
{
double Low[];
ArraySetAsSeries(Low,true);
CopyLow(symbol,timeframe,start,count,Low);
return(ArrayMinimum(Low,0,count)+start);
}
if(type==MODE_HIGH)
{
double High[];
ArraySetAsSeries(High,true);
CopyHigh(symbol,timeframe,start,count,High);
return(ArrayMinimum(High,0,count)+start);
}
if(type==MODE_CLOSE)
{
double Close[];
ArraySetAsSeries(Close,true);
CopyClose(symbol,timeframe,start,count,Close);
return(ArrayMinimum(Close,0,count)+start);
}
if(type==MODE_VOLUME)
{
long Volume[];
ArraySetAsSeries(Volume,true);
CopyTickVolume(symbol,timeframe,start,count,Volume);
return(ArrayMinimum(Volume,0,count)+start);
}
if(type>=MODE_TIME)
{
datetime Time[];
ArraySetAsSeries(Time,true);
CopyTime(symbol,timeframe,start,count,Time);
return(ArrayMinimum(Time,0,count)+start);
}
return(0);
#else
return iLowest(symbol, tf, type, count, start);
#endif
}
static double iOpen(string symbol,int tf,int index)
{
#ifdef __MQL5__
if(index < 0) return(-1);
double Arr[];
ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
if(CopyOpen(symbol,timeframe, index, 1, Arr)>0)
return(Arr[0]);
else return(-1);
#else
return iOpen(symbol, tf, index);
#endif
}
static datetime iTime(string symbol,int tf,int index)
{
#ifdef __MQL5__
if(index < 0) return(-1);
ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
datetime Arr[];
if(CopyTime(symbol, timeframe, index, 1, Arr)>0)
return(Arr[0]);
else return(-1);
#else
return iTime(symbol, tf, index);
#endif
}
static long iVolume(string symbol,int tf,int index)
{
#ifdef __MQL5__
if(index < 0) return(-1);
long Arr[];
ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
if(CopyTickVolume(symbol, timeframe, index, 1, Arr)>0)
return(Arr[0]);
else return(-1);
#else
return iVolume(symbol, tf, index);
#endif
}
};