generated from EA31337/Strategy-Demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stg_Oscillator.mqh
552 lines (543 loc) · 32 KB
/
Stg_Oscillator.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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
/**
* @file
* Implements Oscillator strategy based on the Oscillator indicator.
*/
enum ENUM_STG_OSCILLATOR_TYPE {
STG_OSCILLATOR_TYPE_0_NONE = 0, // (None)
STG_OSCILLATOR_TYPE_AC, // AC: Accelerator/Decelerator
STG_OSCILLATOR_TYPE_AD, // AD: Accumulation/Distribution
STG_OSCILLATOR_TYPE_AO, // AO: Awesome
STG_OSCILLATOR_TYPE_ATR, // ATR
STG_OSCILLATOR_TYPE_BEARS, // Bears Power
STG_OSCILLATOR_TYPE_BULLS, // Bulls Power
STG_OSCILLATOR_TYPE_BWMFI, // BWMFI
STG_OSCILLATOR_TYPE_CCI, // CCI
STG_OSCILLATOR_TYPE_CHO, // CHO: Chaikin
STG_OSCILLATOR_TYPE_CHV, // CHV: Chaikin Volatility
STG_OSCILLATOR_TYPE_DEMARKER, // DeMarker
STG_OSCILLATOR_TYPE_MFI, // MFI
STG_OSCILLATOR_TYPE_MOM, // MOM: Momentum
STG_OSCILLATOR_TYPE_OBV, // OBV: On Balance Volume
STG_OSCILLATOR_TYPE_PVT, // PVT: Price and Volume Trend
STG_OSCILLATOR_TYPE_ROC, // ROC: Rate of Change
STG_OSCILLATOR_TYPE_RSI, // RSI
STG_OSCILLATOR_TYPE_STDDEV, // StdDev: Standard Deviation
STG_OSCILLATOR_TYPE_STOCH, // Stochastic
STG_OSCILLATOR_TYPE_TRIX, // TRIX: Triple Exponential Average
STG_OSCILLATOR_TYPE_UO, // UO: Ultimate Oscillator
STG_OSCILLATOR_TYPE_WAD, // WAD: Larry Williams' Accumulation/Distribution
STG_OSCILLATOR_TYPE_WPR, // WPR
STG_OSCILLATOR_TYPE_VOL, // VOL: Volumes
};
// User input params.
INPUT_GROUP("Oscillator strategy: main strategy params");
INPUT ENUM_STG_OSCILLATOR_TYPE Oscillator_Type = STG_OSCILLATOR_TYPE_CCI; // Oscillator type
INPUT_GROUP("Oscillator strategy: strategy params");
INPUT float Oscillator_LotSize = 0; // Lot size
INPUT int Oscillator_SignalOpenMethod = 6; // Signal open method
INPUT float Oscillator_SignalOpenLevel = 0; // Signal open level
INPUT int Oscillator_SignalOpenFilterMethod = 32; // Signal open filter method
INPUT int Oscillator_SignalOpenFilterTime = 3; // Signal open filter time (0-31)
INPUT int Oscillator_SignalOpenBoostMethod = 0; // Signal open boost method
INPUT int Oscillator_SignalCloseMethod = 0; // Signal close method
INPUT int Oscillator_SignalCloseFilter = 32; // Signal close filter (-127-127)
INPUT float Oscillator_SignalCloseLevel = 0; // Signal close level
INPUT int Oscillator_PriceStopMethod = 0; // Price limit method
INPUT float Oscillator_PriceStopLevel = 2; // Price limit level
INPUT int Oscillator_TickFilterMethod = 32; // Tick filter method (0-255)
INPUT float Oscillator_MaxSpread = 4.0; // Max spread to trade (in pips)
INPUT short Oscillator_Shift = 0; // Shift
INPUT float Oscillator_OrderCloseLoss = 80; // Order close loss
INPUT float Oscillator_OrderCloseProfit = 80; // Order close profit
INPUT int Oscillator_OrderCloseTime = -30; // Order close time in mins (>0) or bars (<0)
INPUT_GROUP("Oscillator strategy: AC oscillator params");
INPUT int Oscillator_Indi_AC_Shift = 0; // Shift
INPUT ENUM_IDATA_SOURCE_TYPE Oscillator_Indi_AC_SourceType = IDATA_BUILTIN; // Source type
INPUT_GROUP("Oscillator strategy: AD oscillator params");
INPUT int Oscillator_Indi_AD_Shift = 0; // Shift
INPUT ENUM_IDATA_SOURCE_TYPE Oscillator_Indi_AD_SourceType = IDATA_BUILTIN; // Source type
INPUT_GROUP("Oscillator strategy: ATR oscillator params");
INPUT int Oscillator_Indi_ATR_Period = 13; // Period
INPUT int Oscillator_Indi_ATR_Shift = 0; // Shift
INPUT ENUM_IDATA_SOURCE_TYPE Oscillator_Indi_ATR_SourceType = IDATA_BUILTIN; // Source type
INPUT_GROUP("Oscillator strategy: Awesome oscillator params");
INPUT int Oscillator_Indi_Awesome_Shift = 0; // Shift
INPUT ENUM_IDATA_SOURCE_TYPE Oscillator_Indi_Awesome_SourceType = IDATA_BUILTIN; // Source type
INPUT_GROUP("Oscillator strategy: BearsPower oscillator params");
INPUT int Oscillator_Indi_BearsPower_Period = 30; // Period
INPUT ENUM_APPLIED_PRICE Oscillator_Indi_BearsPower_Applied_Price = PRICE_CLOSE; // Applied Price
INPUT int Oscillator_Indi_BearsPower_Shift = 0; // Shift
INPUT ENUM_IDATA_SOURCE_TYPE Oscillator_Indi_BearsPower_SourceType = IDATA_BUILTIN; // Source type
INPUT_GROUP("Oscillator strategy: BullsPower oscillator params");
INPUT int Oscillator_Indi_BullsPower_Period = 30; // Period
INPUT ENUM_APPLIED_PRICE Oscillator_Indi_BullsPower_Applied_Price = PRICE_CLOSE; // Applied Price
INPUT int Oscillator_Indi_BullsPower_Shift = 0; // Shift
INPUT ENUM_IDATA_SOURCE_TYPE Oscillator_Indi_BullsPower_SourceType = IDATA_BUILTIN; // Source type
INPUT_GROUP("Oscillator strategy: BWMFI oscillator params");
INPUT int Oscillator_Indi_BWMFI_Shift = 1; // Shift
INPUT ENUM_IDATA_SOURCE_TYPE Oscillator_Indi_BWMFI_SourceType = IDATA_BUILTIN; // Source type
INPUT_GROUP("Oscillator strategy: CCI oscillator params");
INPUT int Oscillator_Indi_CCI_Period = 20; // Period
INPUT ENUM_APPLIED_PRICE Oscillator_Indi_CCI_Applied_Price = PRICE_TYPICAL; // Applied Price
INPUT int Oscillator_Indi_CCI_Shift = 0; // Shift
INPUT ENUM_IDATA_SOURCE_TYPE Oscillator_Indi_CCI_SourceType = IDATA_BUILTIN; // Source type
INPUT_GROUP("Oscillator strategy: Chaikin oscillator params");
INPUT int Oscillator_Indi_CHO_InpFastMA = 10; // Fast EMA period
INPUT int Oscillator_Indi_CHO_InpSlowMA = 30; // Slow MA period
INPUT ENUM_MA_METHOD Oscillator_Indi_CHO_InpSmoothMethod = MODE_SMMA; // MA method
INPUT ENUM_APPLIED_VOLUME Oscillator_Indi_CHO_InpVolumeType = VOLUME_TICK; // Volumes
INPUT int Oscillator_Indi_CHO_Shift = 0; // Shift
INPUT ENUM_IDATA_SOURCE_TYPE Oscillator_Indi_CHO_SourceType = IDATA_BUILTIN; // Source type
INPUT_GROUP("Oscillator strategy: Chaikin Volatility oscillator params");
INPUT unsigned int Oscillator_Indi_CHV_Smooth_Period; // Smooth period
INPUT unsigned int Oscillator_Indi_CHV_Period; // Period
INPUT ENUM_CHV_SMOOTH_METHOD Oscillator_Indi_CHV_Smooth_Method; // Smooth method
INPUT int Oscillator_Indi_CHV_Shift = 0; // Shift
INPUT ENUM_IDATA_SOURCE_TYPE Oscillator_Indi_CHV_SourceType = IDATA_BUILTIN; // Source type
INPUT_GROUP("Oscillator strategy: DeMarker indicator params");
INPUT int Oscillator_Indi_DeMarker_Period = 23; // Period
INPUT int Oscillator_Indi_DeMarker_Shift = 0; // Shift
INPUT ENUM_IDATA_SOURCE_TYPE Oscillator_Indi_DeMarker_SourceType = IDATA_BUILTIN; // Source type
INPUT_GROUP("Oscillator strategy: MFI oscillator params");
INPUT int Oscillator_Indi_MFI_MA_Period = 22; // MA Period
INPUT ENUM_APPLIED_VOLUME Oscillator_Indi_MFI_Applied_Volume = (ENUM_APPLIED_VOLUME)0; // Applied volume.
INPUT int Oscillator_Indi_MFI_Shift = 0; // Shift
INPUT ENUM_IDATA_SOURCE_TYPE Oscillator_Indi_MFI_SourceType = IDATA_BUILTIN; // Source type
INPUT_GROUP("Oscillator strategy: Momentum oscillator params");
INPUT int Oscillator_Indi_Momentum_Period = 12; // Averaging period
INPUT ENUM_APPLIED_PRICE Oscillator_Indi_Momentum_Applied_Price = PRICE_CLOSE; // Applied Price
INPUT int Oscillator_Indi_Momentum_Shift = 0; // Shift
INPUT ENUM_IDATA_SOURCE_TYPE Oscillator_Indi_Momentum_SourceType = IDATA_BUILTIN; // Source type
INPUT_GROUP("Oscillator strategy: OBV oscillator params");
INPUT ENUM_APPLIED_PRICE Oscillator_Indi_OBV_Applied_Price = PRICE_CLOSE; // Applied Price
INPUT int Oscillator_Indi_OBV_Shift = 1; // Shift
INPUT ENUM_IDATA_SOURCE_TYPE Oscillator_Indi_OBV_SourceType = IDATA_BUILTIN; // Source type
INPUT_GROUP("Oscillator strategy: PVT oscillator params");
INPUT ENUM_APPLIED_VOLUME Oscillator_Indi_PVT_InpVolumeType = VOLUME_TICK; // Volumes
INPUT int Oscillator_Indi_PVT_Shift = 0; // Shift
INPUT ENUM_IDATA_SOURCE_TYPE Oscillator_Indi_PVT_SourceType = IDATA_BUILTIN; // Source type
INPUT_GROUP("Oscillator strategy: ROC oscillator params");
INPUT int Oscillator_Indi_ROC_Period = 16; // Period
INPUT ENUM_APPLIED_PRICE Oscillator_Indi_ROC_Applied_Price = PRICE_WEIGHTED; // Applied Price
INPUT int Oscillator_Indi_ROC_Shift = 0; // Shift
INPUT ENUM_IDATA_SOURCE_TYPE Oscillator_Indi_ROC_SourceType = IDATA_BUILTIN; // Source type
INPUT_GROUP("Oscillator strategy: RSI oscillator params");
INPUT int Oscillator_Indi_RSI_Period = 16; // Period
INPUT ENUM_APPLIED_PRICE Oscillator_Indi_RSI_Applied_Price = PRICE_WEIGHTED; // Applied Price
INPUT int Oscillator_Indi_RSI_Shift = 0; // Shift
INPUT ENUM_IDATA_SOURCE_TYPE Oscillator_Indi_RSI_SourceType = IDATA_BUILTIN; // Source type
INPUT_GROUP("Oscillator strategy: StdDev oscillator params");
INPUT int Oscillator_Indi_StdDev_MA_Period = 24; // Period
INPUT int Oscillator_Indi_StdDev_MA_Shift = 0; // MA Shift
INPUT ENUM_MA_METHOD Oscillator_Indi_StdDev_MA_Method = (ENUM_MA_METHOD)3; // MA Method
INPUT ENUM_APPLIED_PRICE Oscillator_Indi_StdDev_Applied_Price = PRICE_WEIGHTED; // Applied Price
INPUT int Oscillator_Indi_StdDev_Shift = 0; // Shift
INPUT ENUM_IDATA_SOURCE_TYPE Oscillator_Indi_StdDev_SourceType = IDATA_BUILTIN; // Source type
INPUT_GROUP("Oscillator strategy: Stochastic oscillator params");
INPUT int Oscillator_Indi_Stochastic_KPeriod = 8; // K line period
INPUT int Oscillator_Indi_Stochastic_DPeriod = 12; // D line period
INPUT int Oscillator_Indi_Stochastic_Slowing = 12; // Slowing
INPUT ENUM_MA_METHOD Oscillator_Indi_Stochastic_MA_Method = MODE_EMA; // Moving Average method
INPUT ENUM_STO_PRICE Oscillator_Indi_Stochastic_Price_Field = 0; // Price (0 - Low/High or 1 - Close/Close)
INPUT int Oscillator_Indi_Stochastic_Shift = 0; // Shift
INPUT ENUM_IDATA_SOURCE_TYPE Oscillator_Indi_Stochastic_SourceType = IDATA_BUILTIN; // Source type
INPUT_GROUP("Oscillator strategy: TRIX oscillator params");
INPUT int Oscillator_Indi_TRIX_InpPeriodEMA = 14; // EMA period
INPUT ENUM_APPLIED_PRICE Oscillator_Indi_TRIX_Applied_Price = PRICE_WEIGHTED; // Applied Price
INPUT int Oscillator_Indi_TRIX_Shift = 0; // Shift
INPUT ENUM_IDATA_SOURCE_TYPE Oscillator_Indi_TRIX_SourceType = IDATA_BUILTIN; // Source type
INPUT_GROUP("Oscillator strategy: Ultimate oscillator params");
INPUT int Oscillator_Indi_UO_InpFastPeriod = 7; // Fast ATR period
INPUT int Oscillator_Indi_UO_InpMiddlePeriod = 14; // Middle ATR period
INPUT int Oscillator_Indi_UO_InpSlowPeriod = 28; // Slow ATR period
INPUT int Oscillator_Indi_UO_InpFastK = 4; // Fast K
INPUT int Oscillator_Indi_UO_InpMiddleK = 2; // Middle K
INPUT int Oscillator_Indi_UO_InpSlowK = 1; // Slow K
INPUT int Oscillator_Indi_UO_Shift = 0; // Shift
INPUT ENUM_IDATA_SOURCE_TYPE Oscillator_Indi_UO_SourceType = IDATA_BUILTIN; // Source type
INPUT_GROUP("Oscillator strategy: Williams' Accumulation/Distribution oscillator params");
INPUT int Oscillator_Indi_WAD_Shift = 0; // Shift
INPUT ENUM_IDATA_SOURCE_TYPE Oscillator_Indi_WAD_SourceType = IDATA_BUILTIN; // Source type
INPUT_GROUP("Oscillator strategy: WPR oscillator params");
INPUT int Oscillator_Indi_WPR_Period = 18; // Period
INPUT int Oscillator_Indi_WPR_Shift = 0; // Shift
INPUT ENUM_IDATA_SOURCE_TYPE Oscillator_Indi_WPR_SourceType = IDATA_BUILTIN; // Source type
INPUT_GROUP("Oscillator strategy: Volumes oscillator params");
INPUT ENUM_APPLIED_VOLUME Oscillator_Indi_VOL_InpVolumeType = VOLUME_TICK; // Volumes
INPUT int Oscillator_Indi_VOL_Shift = 0; // Shift
INPUT ENUM_IDATA_SOURCE_TYPE Oscillator_Indi_VOL_SourceType = IDATA_BUILTIN; // Source type
// Structs.
// Defines struct with default user strategy values.
struct Stg_Oscillator_Params_Defaults : StgParams {
Stg_Oscillator_Params_Defaults()
: StgParams(::Oscillator_SignalOpenMethod, ::Oscillator_SignalOpenFilterMethod, ::Oscillator_SignalOpenLevel,
::Oscillator_SignalOpenBoostMethod, ::Oscillator_SignalCloseMethod, ::Oscillator_SignalCloseFilter,
::Oscillator_SignalCloseLevel, ::Oscillator_PriceStopMethod, ::Oscillator_PriceStopLevel,
::Oscillator_TickFilterMethod, ::Oscillator_MaxSpread, ::Oscillator_Shift) {
Set(STRAT_PARAM_LS, Oscillator_LotSize);
Set(STRAT_PARAM_OCL, Oscillator_OrderCloseLoss);
Set(STRAT_PARAM_OCP, Oscillator_OrderCloseProfit);
Set(STRAT_PARAM_OCT, Oscillator_OrderCloseTime);
Set(STRAT_PARAM_SOFT, Oscillator_SignalOpenFilterTime);
}
};
class Stg_Oscillator : public Strategy {
public:
Stg_Oscillator(StgParams &_sparams, TradeParams &_tparams, ChartParams &_cparams, string _name = "")
: Strategy(_sparams, _tparams, _cparams, _name) {}
static Stg_Oscillator *Init(ENUM_TIMEFRAMES _tf = NULL, EA *_ea = NULL) {
// Initialize strategy initial values.
Stg_Oscillator_Params_Defaults stg_oscillator_defaults;
StgParams _stg_params(stg_oscillator_defaults);
// Initialize Strategy instance.
ChartParams _cparams(_tf, _Symbol);
TradeParams _tparams;
Strategy *_strat = new Stg_Oscillator(_stg_params, _tparams, _cparams, "Oscillator");
return _strat;
}
/**
* Validate soscillators's entry.
*/
bool IsValidEntry(IndicatorBase *_indi, int _shift = 0) {
bool _result = true;
switch (Oscillator_Type) {
case STG_OSCILLATOR_TYPE_AC:
_result &= dynamic_cast<Indi_AC *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift) &&
dynamic_cast<Indi_AC *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift + 1);
break;
case STG_OSCILLATOR_TYPE_AD:
_result &= dynamic_cast<Indi_AD *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift) &&
dynamic_cast<Indi_AD *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift + 1);
break;
case STG_OSCILLATOR_TYPE_AO:
_result &= dynamic_cast<Indi_AO *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift) &&
dynamic_cast<Indi_AO *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift + 1);
break;
case STG_OSCILLATOR_TYPE_ATR:
_result &= dynamic_cast<Indi_ATR *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift) &&
dynamic_cast<Indi_ATR *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift + 1);
break;
case STG_OSCILLATOR_TYPE_BEARS:
_result &= dynamic_cast<Indi_BearsPower *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift) &&
dynamic_cast<Indi_BearsPower *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift + 1);
break;
case STG_OSCILLATOR_TYPE_BULLS:
_result &= dynamic_cast<Indi_BullsPower *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift) &&
dynamic_cast<Indi_BullsPower *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift + 1);
break;
case STG_OSCILLATOR_TYPE_BWMFI:
_result &= dynamic_cast<Indi_BWMFI *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift) &&
dynamic_cast<Indi_BWMFI *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift + 1);
break;
case STG_OSCILLATOR_TYPE_CCI:
_result &= dynamic_cast<Indi_CCI *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift) &&
dynamic_cast<Indi_CCI *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift + 1);
break;
case STG_OSCILLATOR_TYPE_CHO:
_result &= dynamic_cast<Indi_CHO *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift) &&
dynamic_cast<Indi_CHO *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift + 1);
break;
case STG_OSCILLATOR_TYPE_CHV:
_result &= dynamic_cast<Indi_CHV *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift) &&
dynamic_cast<Indi_CHV *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift + 1);
break;
case STG_OSCILLATOR_TYPE_DEMARKER:
_result &= dynamic_cast<Indi_DeMarker *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift) &&
dynamic_cast<Indi_DeMarker *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift + 1);
break;
case STG_OSCILLATOR_TYPE_MFI:
_result &= dynamic_cast<Indi_MFI *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift) &&
dynamic_cast<Indi_MFI *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift + 1);
break;
case STG_OSCILLATOR_TYPE_MOM:
_result &= dynamic_cast<Indi_Momentum *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift) &&
dynamic_cast<Indi_Momentum *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift + 1);
break;
case STG_OSCILLATOR_TYPE_OBV:
_result &= dynamic_cast<Indi_OBV *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift) &&
dynamic_cast<Indi_OBV *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift + 1);
break;
case STG_OSCILLATOR_TYPE_PVT:
_result &= dynamic_cast<Indi_PriceVolumeTrend *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift) &&
dynamic_cast<Indi_PriceVolumeTrend *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift + 1);
break;
case STG_OSCILLATOR_TYPE_ROC:
_result &= dynamic_cast<Indi_RateOfChange *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift) &&
dynamic_cast<Indi_RateOfChange *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift + 1);
break;
case STG_OSCILLATOR_TYPE_RSI:
_result &= dynamic_cast<Indi_RSI *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift) &&
dynamic_cast<Indi_RSI *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift + 1);
break;
case STG_OSCILLATOR_TYPE_STDDEV:
_result &= dynamic_cast<Indi_StdDev *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift) &&
dynamic_cast<Indi_StdDev *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift + 1);
break;
case STG_OSCILLATOR_TYPE_STOCH:
_result &= dynamic_cast<Indi_Stochastic *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift) &&
dynamic_cast<Indi_Stochastic *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift + 1);
break;
case STG_OSCILLATOR_TYPE_TRIX:
_result &= dynamic_cast<Indi_TRIX *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift) &&
dynamic_cast<Indi_TRIX *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift + 1);
break;
case STG_OSCILLATOR_TYPE_UO:
_result &= dynamic_cast<Indi_UltimateOscillator *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift) &&
dynamic_cast<Indi_UltimateOscillator *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift + 1);
break;
case STG_OSCILLATOR_TYPE_WPR:
_result &= dynamic_cast<Indi_WPR *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift) &&
dynamic_cast<Indi_WPR *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift + 1);
break;
case STG_OSCILLATOR_TYPE_WAD:
_result &= dynamic_cast<Indi_WilliamsAD *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift) &&
dynamic_cast<Indi_WilliamsAD *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift + 1);
break;
case STG_OSCILLATOR_TYPE_VOL:
_result &= dynamic_cast<Indi_Volumes *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift) &&
dynamic_cast<Indi_Volumes *>(_indi).GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift + 1);
break;
default:
break;
}
return _result;
}
/**
* Event on strategy's init.
*/
void OnInit() {
// Initialize indicators.
switch (Oscillator_Type) {
case STG_OSCILLATOR_TYPE_AC: // AC
{
IndiACParams _indi_params(::Oscillator_Indi_AC_Shift);
_indi_params.SetTf(Get<ENUM_TIMEFRAMES>(STRAT_PARAM_TF));
SetIndicator(new Indi_AC(_indi_params, ::Oscillator_Indi_AC_SourceType), ::Oscillator_Type);
break;
}
case STG_OSCILLATOR_TYPE_AD: // AD
{
IndiADParams _indi_params(::Oscillator_Indi_AD_Shift);
_indi_params.SetTf(Get<ENUM_TIMEFRAMES>(STRAT_PARAM_TF));
SetIndicator(new Indi_AD(_indi_params, ::Oscillator_Indi_AD_SourceType), ::Oscillator_Type);
break;
}
case STG_OSCILLATOR_TYPE_AO: // AO
{
IndiAOParams _indi_params(::Oscillator_Indi_Awesome_Shift);
_indi_params.SetTf(Get<ENUM_TIMEFRAMES>(STRAT_PARAM_TF));
SetIndicator(new Indi_AO(_indi_params, ::Oscillator_Indi_Awesome_SourceType), ::Oscillator_Type);
break;
}
case STG_OSCILLATOR_TYPE_ATR: // ATR
{
IndiATRParams _indi_params(::Oscillator_Indi_ATR_Period, ::Oscillator_Indi_ATR_Shift);
_indi_params.SetTf(Get<ENUM_TIMEFRAMES>(STRAT_PARAM_TF));
SetIndicator(new Indi_ATR(_indi_params, ::Oscillator_Indi_ATR_SourceType), ::Oscillator_Type);
break;
}
case STG_OSCILLATOR_TYPE_BEARS: // Bears
{
IndiBearsPowerParams _indi_params(::Oscillator_Indi_BearsPower_Period,
::Oscillator_Indi_BearsPower_Applied_Price,
::Oscillator_Indi_BearsPower_Shift);
_indi_params.SetTf(Get<ENUM_TIMEFRAMES>(STRAT_PARAM_TF));
SetIndicator(new Indi_BearsPower(_indi_params, ::Oscillator_Indi_BearsPower_SourceType), ::Oscillator_Type);
break;
}
case STG_OSCILLATOR_TYPE_BULLS: // Bulls
{
IndiBullsPowerParams _indi_params(::Oscillator_Indi_BullsPower_Period,
::Oscillator_Indi_BullsPower_Applied_Price,
::Oscillator_Indi_BullsPower_Shift);
_indi_params.SetTf(Get<ENUM_TIMEFRAMES>(STRAT_PARAM_TF));
SetIndicator(new Indi_BullsPower(_indi_params, ::Oscillator_Indi_BullsPower_SourceType), ::Oscillator_Type);
break;
}
case STG_OSCILLATOR_TYPE_BWMFI: // BWMFI
{
IndiBWIndiMFIParams _indi_params(::Oscillator_Indi_BWMFI_Shift);
_indi_params.SetTf(Get<ENUM_TIMEFRAMES>(STRAT_PARAM_TF));
SetIndicator(new Indi_BWMFI(_indi_params, ::Oscillator_Indi_BWMFI_SourceType), ::Oscillator_Type);
break;
}
case STG_OSCILLATOR_TYPE_CCI: // CCI
{
IndiCCIParams _indi_params(::Oscillator_Indi_CCI_Period, ::Oscillator_Indi_CCI_Applied_Price,
::Oscillator_Indi_CCI_Shift);
_indi_params.SetTf(Get<ENUM_TIMEFRAMES>(STRAT_PARAM_TF));
SetIndicator(new Indi_CCI(_indi_params, ::Oscillator_Indi_CCI_SourceType), ::Oscillator_Type);
break;
}
case STG_OSCILLATOR_TYPE_CHO: // Chaikin (CHO)
{
IndiCHOParams _indi_params(::Oscillator_Indi_CHO_InpFastMA, ::Oscillator_Indi_CHO_InpSlowMA,
::Oscillator_Indi_CHO_InpSmoothMethod, ::Oscillator_Indi_CHO_InpVolumeType,
::Oscillator_Indi_CHO_Shift);
_indi_params.SetTf(Get<ENUM_TIMEFRAMES>(STRAT_PARAM_TF));
SetIndicator(new Indi_CHO(_indi_params, ::Oscillator_Indi_CHO_SourceType), ::Oscillator_Type);
break;
}
case STG_OSCILLATOR_TYPE_CHV: // Chaikin Volatility (CHV)
{
IndiCHVParams _indi_params(::Oscillator_Indi_CHV_Smooth_Period, ::Oscillator_Indi_CHV_Period,
::Oscillator_Indi_CHV_Smooth_Method, ::Oscillator_Indi_CHV_Shift);
_indi_params.SetTf(Get<ENUM_TIMEFRAMES>(STRAT_PARAM_TF));
SetIndicator(new Indi_CHV(_indi_params, ::Oscillator_Indi_CHV_SourceType), ::Oscillator_Type);
break;
}
case STG_OSCILLATOR_TYPE_DEMARKER: // DeMarker
{
IndiDeMarkerParams _indi_params(::Oscillator_Indi_DeMarker_Period, ::Oscillator_Indi_DeMarker_Shift);
_indi_params.SetTf(Get<ENUM_TIMEFRAMES>(STRAT_PARAM_TF));
SetIndicator(new Indi_DeMarker(_indi_params, ::Oscillator_Indi_DeMarker_SourceType), ::Oscillator_Type);
break;
}
case STG_OSCILLATOR_TYPE_MFI: // MFI
{
IndiMFIParams _indi_params(::Oscillator_Indi_MFI_MA_Period, ::Oscillator_Indi_MFI_Applied_Volume,
::Oscillator_Indi_MFI_Shift);
_indi_params.SetTf(Get<ENUM_TIMEFRAMES>(STRAT_PARAM_TF));
SetIndicator(new Indi_MFI(_indi_params, ::Oscillator_Indi_MFI_SourceType), ::Oscillator_Type);
break;
}
case STG_OSCILLATOR_TYPE_MOM: // MOM
{
IndiMomentumParams _indi_params(::Oscillator_Indi_Momentum_Period, ::Oscillator_Indi_Momentum_Applied_Price,
::Oscillator_Indi_Momentum_Shift);
_indi_params.SetTf(Get<ENUM_TIMEFRAMES>(STRAT_PARAM_TF));
SetIndicator(new Indi_Momentum(_indi_params, ::Oscillator_Indi_Momentum_SourceType), ::Oscillator_Type);
break;
}
case STG_OSCILLATOR_TYPE_OBV: // OBV
{
IndiOBVParams _indi_params(::Oscillator_Indi_OBV_Applied_Price, ::Oscillator_Indi_OBV_Shift);
_indi_params.SetTf(Get<ENUM_TIMEFRAMES>(STRAT_PARAM_TF));
SetIndicator(new Indi_OBV(_indi_params, ::Oscillator_Indi_OBV_SourceType), ::Oscillator_Type);
break;
}
case STG_OSCILLATOR_TYPE_PVT: // PVT
{
IndiPriceVolumeTrendParams _indi_params(::Oscillator_Indi_PVT_InpVolumeType, ::Oscillator_Indi_PVT_Shift);
_indi_params.SetTf(Get<ENUM_TIMEFRAMES>(STRAT_PARAM_TF));
SetIndicator(new Indi_PriceVolumeTrend(_indi_params, ::Oscillator_Indi_PVT_SourceType), ::Oscillator_Type);
break;
}
case STG_OSCILLATOR_TYPE_ROC: // ROC
{
IndiRateOfChangeParams _indi_params(::Oscillator_Indi_ROC_Period, ::Oscillator_Indi_ROC_Applied_Price,
::Oscillator_Indi_ROC_Shift);
_indi_params.SetTf(Get<ENUM_TIMEFRAMES>(STRAT_PARAM_TF));
SetIndicator(new Indi_RateOfChange(_indi_params, ::Oscillator_Indi_ROC_SourceType), ::Oscillator_Type);
break;
}
case STG_OSCILLATOR_TYPE_RSI: // RSI
{
IndiRSIParams _indi_params(::Oscillator_Indi_RSI_Period, ::Oscillator_Indi_RSI_Applied_Price,
::Oscillator_Indi_RSI_Shift);
_indi_params.SetTf(Get<ENUM_TIMEFRAMES>(STRAT_PARAM_TF));
SetIndicator(new Indi_RSI(_indi_params, ::Oscillator_Indi_RSI_SourceType), ::Oscillator_Type);
break;
}
case STG_OSCILLATOR_TYPE_STDDEV: // StdDev
{
IndiStdDevParams _indi_params(::Oscillator_Indi_StdDev_MA_Period, ::Oscillator_Indi_StdDev_MA_Shift,
::Oscillator_Indi_StdDev_MA_Method, ::Oscillator_Indi_StdDev_Applied_Price,
::Oscillator_Indi_StdDev_Shift);
_indi_params.SetTf(Get<ENUM_TIMEFRAMES>(STRAT_PARAM_TF));
SetIndicator(new Indi_StdDev(_indi_params, ::Oscillator_Indi_StdDev_SourceType), ::Oscillator_Type);
break;
}
case STG_OSCILLATOR_TYPE_STOCH: // Stochastic
{
IndiStochParams _indi_params(::Oscillator_Indi_Stochastic_KPeriod, ::Oscillator_Indi_Stochastic_DPeriod,
::Oscillator_Indi_Stochastic_Slowing, ::Oscillator_Indi_Stochastic_MA_Method,
::Oscillator_Indi_Stochastic_Price_Field, ::Oscillator_Indi_Stochastic_Shift);
_indi_params.SetTf(Get<ENUM_TIMEFRAMES>(STRAT_PARAM_TF));
SetIndicator(new Indi_Stochastic(_indi_params, ::Oscillator_Indi_Stochastic_SourceType), ::Oscillator_Type);
break;
}
case STG_OSCILLATOR_TYPE_TRIX: // TRIX
{
IndiTRIXParams _indi_params(::Oscillator_Indi_TRIX_InpPeriodEMA, ::Oscillator_Indi_TRIX_Applied_Price,
::Oscillator_Indi_TRIX_Shift);
_indi_params.SetTf(Get<ENUM_TIMEFRAMES>(STRAT_PARAM_TF));
SetIndicator(new Indi_TRIX(_indi_params, ::Oscillator_Indi_TRIX_SourceType), ::Oscillator_Type);
break;
}
case STG_OSCILLATOR_TYPE_UO: // UO
{
IndiUltimateOscillatorParams _indi_params(
::Oscillator_Indi_UO_InpFastPeriod, ::Oscillator_Indi_UO_InpMiddlePeriod,
::Oscillator_Indi_UO_InpSlowPeriod, ::Oscillator_Indi_UO_InpFastK, ::Oscillator_Indi_UO_InpMiddleK,
::Oscillator_Indi_UO_InpSlowK, ::Oscillator_Indi_UO_Shift);
_indi_params.SetTf(Get<ENUM_TIMEFRAMES>(STRAT_PARAM_TF));
SetIndicator(new Indi_UltimateOscillator(_indi_params, ::Oscillator_Indi_UO_SourceType), ::Oscillator_Type);
break;
}
case STG_OSCILLATOR_TYPE_WAD: // Williams' AD
{
IndiWilliamsADParams _indi_params(::Oscillator_Indi_WAD_Shift);
_indi_params.SetTf(Get<ENUM_TIMEFRAMES>(STRAT_PARAM_TF));
SetIndicator(new Indi_WilliamsAD(_indi_params, ::Oscillator_Indi_WAD_SourceType), ::Oscillator_Type);
break;
}
case STG_OSCILLATOR_TYPE_WPR: // WPR
{
IndiWPRParams _indi_params(::Oscillator_Indi_WPR_Period, ::Oscillator_Indi_WPR_Shift);
_indi_params.SetTf(Get<ENUM_TIMEFRAMES>(STRAT_PARAM_TF));
SetIndicator(new Indi_WPR(_indi_params, ::Oscillator_Indi_WPR_SourceType), ::Oscillator_Type);
break;
}
case STG_OSCILLATOR_TYPE_VOL: // Volumes
{
IndiVolumesParams _indi_params(::Oscillator_Indi_VOL_InpVolumeType, ::Oscillator_Indi_VOL_Shift);
_indi_params.SetTf(Get<ENUM_TIMEFRAMES>(STRAT_PARAM_TF));
SetIndicator(new Indi_Volumes(_indi_params, ::Oscillator_Indi_VOL_SourceType), ::Oscillator_Type);
break;
}
case STG_OSCILLATOR_TYPE_0_NONE: // (None)
default:
break;
}
}
/**
* Check strategy's opening signal.
*/
bool SignalOpen(ENUM_ORDER_TYPE _cmd, int _method, float _level = 0.0f, int _shift = 0) {
IndicatorData *_indi = GetIndicator(::Oscillator_Type);
// uint _ishift = _indi.GetShift();
bool _result = Oscillator_Type != STG_OSCILLATOR_TYPE_0_NONE && IsValidEntry(_indi, _shift);
if (!_result) {
// Returns false when indicator data is not valid.
return false;
}
switch (_cmd) {
case ORDER_TYPE_BUY:
// Buy signal.
_result &= _indi.IsIncreasing(1, 0, _shift);
_result &= _indi.IsIncByPct(_level, 0, _shift, 2);
if (_result && _method != 0) {
if (METHOD(_method, 0)) _result &= _indi.IsDecreasing(1, 0, _shift + 1);
if (METHOD(_method, 1)) _result &= _indi.IsIncreasing(4, 0, _shift + 3);
if (METHOD(_method, 2))
_result &= fmax4(_indi[_shift][0], _indi[_shift + 1][0], _indi[_shift + 2][0], _indi[_shift + 3][0]) ==
_indi[_shift][0];
}
break;
case ORDER_TYPE_SELL:
// Sell signal.
_result &= _indi.IsDecreasing(1, 0, _shift);
_result &= _indi.IsDecByPct(_level, 0, _shift, 2);
if (_result && _method != 0) {
if (METHOD(_method, 0)) _result &= _indi.IsIncreasing(1, 0, _shift + 1);
if (METHOD(_method, 1)) _result &= _indi.IsDecreasing(4, 0, _shift + 3);
if (METHOD(_method, 2))
_result &= fmin4(_indi[_shift][0], _indi[_shift + 1][0], _indi[_shift + 2][0], _indi[_shift + 3][0]) ==
_indi[_shift][0];
}
break;
}
return _result;
}
};