generated from EA31337/Strategy-MA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stg_MA_Cross_Shift.mqh
330 lines (321 loc) · 20.4 KB
/
Stg_MA_Cross_Shift.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
/**
* @file
* Strategy based on the moving average price indicators implementing shifted cross signal.
*/
enum ENUM_STG_MA_CROSS_SHIFT_TYPE {
STG_MA_CROSS_SHIFT_TYPE_0_NONE = 0, // (None)
STG_MA_CROSS_SHIFT_TYPE_AMA, // AMA: Adaptive Moving Average
STG_MA_CROSS_SHIFT_TYPE_DEMA, // DEMA: Double Exponential Moving Average
STG_MA_CROSS_SHIFT_TYPE_FRAMA, // FrAMA: Fractal Adaptive Moving Average
STG_MA_CROSS_SHIFT_TYPE_ICHIMOKU, // Ichimoku
STG_MA_CROSS_SHIFT_TYPE_MA, // MA: Moving Average
STG_MA_CROSS_SHIFT_TYPE_PRICE_CHANNEL, // Price Channel
STG_MA_CROSS_SHIFT_TYPE_SAR, // SAR: Parabolic Stop and Reverse
STG_MA_CROSS_SHIFT_TYPE_TEMA, // TEMA: Triple Exponential Moving Average
STG_MA_CROSS_SHIFT_TYPE_VIDYA, // VIDYA: Variable Index Dynamic Average
};
// User params.
INPUT_GROUP("MA Cross Shift strategy: main strategy params");
INPUT ENUM_STG_MA_CROSS_SHIFT_TYPE MA_Cross_Shift_Type = STG_MA_CROSS_SHIFT_TYPE_MA; // Indicator MA type
INPUT_GROUP("MA Cross Shift strategy: strategy params");
INPUT float MA_Cross_Shift_LotSize = 0; // Lot size
INPUT int MA_Cross_Shift_SignalOpenMethod = 0; // Signal open method (-127-127)
INPUT float MA_Cross_Shift_SignalOpenLevel = 0.0f; // Signal open level
INPUT int MA_Cross_Shift_SignalOpenFilterMethod = 32; // Signal open filter method
INPUT int MA_Cross_Shift_SignalOpenFilterTime = 3; // Signal open filter time
INPUT int MA_Cross_Shift_SignalOpenBoostMethod = 0; // Signal open boost method
INPUT int MA_Cross_Shift_SignalCloseMethod = 0; // Signal close method (-127-127)
INPUT int MA_Cross_Shift_SignalCloseFilter = 0; // Signal close filter (-127-127)
INPUT float MA_Cross_Shift_SignalCloseLevel = 0.0f; // Signal close level
INPUT int MA_Cross_Shift_PriceStopMethod = 1; // Price stop method (0-127)
INPUT float MA_Cross_Shift_PriceStopLevel = 2; // Price stop level
INPUT int MA_Cross_Shift_TickFilterMethod = 32; // Tick filter method
INPUT float MA_Cross_Shift_MaxSpread = 4.0; // Max spread to trade (pips)
INPUT short MA_Cross_Shift_Shift = 0; // Shift
INPUT float MA_Cross_Shift_OrderCloseLoss = 80; // Order close loss
INPUT float MA_Cross_Shift_OrderCloseProfit = 80; // Order close profit
INPUT int MA_Cross_Shift_OrderCloseTime = -30; // Order close time in mins (>0) or bars (<0)
INPUT_GROUP("MA Cross Shift strategy: AMA indicator params");
INPUT int MA_Cross_Shift_Indi_AMA_InpPeriodAMA = 20; // AMA period
INPUT int MA_Cross_Shift_Indi_AMA_InpFastPeriodEMA = 4; // Fast EMA period
INPUT int MA_Cross_Shift_Indi_AMA_InpSlowPeriodEMA = 30; // Slow EMA period
INPUT int MA_Cross_Shift_Indi_AMA_InpShiftAMA = 4; // AMA shift
INPUT int MA_Cross_Shift_Indi_AMA_Shift = 0; // Shift
INPUT int MA_Cross_Shift_Indi_AMA_Shift2 = 10; // Shift 2
INPUT ENUM_IDATA_SOURCE_TYPE MA_Cross_Shift_Indi_AMA_SourceType = IDATA_BUILTIN; // Source type
INPUT_GROUP("MA Cross Shift strategy: DEMA indicator params");
INPUT int MA_Cross_Shift_Indi_DEMA_Period = 25; // Period
INPUT int MA_Cross_Shift_Indi_DEMA_MA_Shift = 6; // MA Shift
INPUT ENUM_APPLIED_PRICE MA_Cross_Shift_Indi_DEMA_Applied_Price = PRICE_TYPICAL; // Applied Price
INPUT int MA_Cross_Shift_Indi_DEMA_Shift = 0; // Shift
INPUT int MA_Cross_Shift_Indi_DEMA_Shift2 = 10; // Shift 2
INPUT ENUM_IDATA_SOURCE_TYPE MA_Cross_Shift_Indi_DEMA_SourceType = IDATA_BUILTIN; // Source type
INPUT_GROUP("MA Cross Shift strategy: FrAMA indicator params");
INPUT int MA_Cross_Shift_Indi_FrAMA_Period = 10; // Period
INPUT ENUM_APPLIED_PRICE MA_Cross_Shift_Indi_FrAMA_Applied_Price = PRICE_MEDIAN; // Applied Price
INPUT int MA_Cross_Shift_Indi_FrAMA_MA_Shift = 0; // MA Shift
INPUT int MA_Cross_Shift_Indi_FrAMA_Shift = 0; // Shift
INPUT int MA_Cross_Shift_Indi_FrAMA_Shift2 = 10; // Shift 2
INPUT ENUM_IDATA_SOURCE_TYPE MA_Cross_Shift_Indi_FrAMA_SourceType = IDATA_BUILTIN; // Source type
INPUT_GROUP("MA Cross Shift strategy: Ichimoku indicator params");
// INPUT ENUM_ICHIMOKU_LINE MA_Cross_Shift_Indi_Ichimoku_MA_Line = LINE_TENKANSEN; // Ichimoku line for MA
INPUT int MA_Cross_Shift_Indi_Ichimoku_Period_Tenkan_Sen = 30; // Period Tenkan Sen
INPUT int MA_Cross_Shift_Indi_Ichimoku_Period_Kijun_Sen = 10; // Period Kijun Sen
INPUT int MA_Cross_Shift_Indi_Ichimoku_Period_Senkou_Span_B = 30; // Period Senkou Span B
INPUT int MA_Cross_Shift_Indi_Ichimoku_Shift = 1; // Shift
INPUT int MA_Cross_Shift_Indi_Ichimoku_Shift2 = 1; // Shift 2
INPUT ENUM_IDATA_SOURCE_TYPE MA_Cross_Shift_Indi_Ichimoku_SourceType = IDATA_BUILTIN; // Source type
INPUT_GROUP("MA Cross Shift strategy: MA indicator params");
INPUT int MA_Cross_Shift_Indi_MA_Period = 26; // Period
INPUT int MA_Cross_Shift_Indi_MA_MA_Shift = 0; // MA Shift
INPUT ENUM_MA_METHOD MA_Cross_Shift_Indi_MA_Method = MODE_LWMA; // MA Method
INPUT ENUM_APPLIED_PRICE MA_Cross_Shift_Indi_MA_Applied_Price = PRICE_WEIGHTED; // Applied Price
INPUT int MA_Cross_Shift_Indi_MA_Shift = 0; // Shift
INPUT int MA_Cross_Shift_Indi_MA_Shift2 = 10; // Shift 2
INPUT ENUM_IDATA_SOURCE_TYPE MA_Cross_Shift_Indi_MA_SourceType = IDATA_BUILTIN; // Source type
INPUT_GROUP("MA Cross Shift strategy: Price Channel indicator params");
INPUT int MA_Cross_Shift_Indi_PriceChannel_Period = 26; // Period
INPUT int MA_Cross_Shift_Indi_PriceChannel_Shift = 0; // Shift
INPUT int MA_Cross_Shift_Indi_PriceChannel_Shift2 = 10; // Shift 2
INPUT ENUM_IDATA_SOURCE_TYPE MA_Cross_Shift_Indi_PriceChannel_SourceType = IDATA_ICUSTOM; // Source type
INPUT_GROUP("MA Cross Shift strategy: SAR indicator params");
INPUT float MA_Cross_Shift_Indi_SAR_Step = 0.04f; // Step
INPUT float MA_Cross_Shift_Indi_SAR_Maximum_Stop = 0.4f; // Maximum stop
INPUT int MA_Cross_Shift_Indi_SAR_Shift = 0; // Shift
INPUT int MA_Cross_Shift_Indi_SAR_Shift2 = 10; // Shift 2
INPUT ENUM_IDATA_SOURCE_TYPE MA_Cross_Shift_Indi_SAR_SourceType = IDATA_ICUSTOM; // Source type
INPUT_GROUP("MA Cross Shift strategy: TEMA indicator params");
INPUT int MA_Cross_Shift_Indi_TEMA_Period = 10; // Period
INPUT int MA_Cross_Shift_Indi_TEMA_MA_Shift = 0; // MA Shift
INPUT ENUM_APPLIED_PRICE MA_Cross_Shift_Indi_TEMA_Applied_Price = PRICE_WEIGHTED; // Applied Price
INPUT int MA_Cross_Shift_Indi_TEMA_Shift = 0; // Shift
INPUT int MA_Cross_Shift_Indi_TEMA_Shift2 = 10; // Shift 2
INPUT ENUM_IDATA_SOURCE_TYPE MA_Cross_Shift_Indi_TEMA_SourceType = IDATA_BUILTIN; // Source type
INPUT_GROUP("MA Cross Shift strategy: VIDYA indicator params");
INPUT int MA_Cross_Shift_Indi_VIDYA_Period = 30; // Period
INPUT int MA_Cross_Shift_Indi_VIDYA_MA_Period = 20; // MA Period
INPUT int MA_Cross_Shift_Indi_VIDYA_MA_Shift = 1; // MA Shift
INPUT ENUM_APPLIED_PRICE MA_Cross_Shift_Indi_VIDYA_Applied_Price = PRICE_WEIGHTED; // Applied Price
INPUT int MA_Cross_Shift_Indi_VIDYA_Shift = 0; // Shift
INPUT int MA_Cross_Shift_Indi_VIDYA_Shift2 = 10; // Shift 2
INPUT ENUM_IDATA_SOURCE_TYPE MA_Cross_Shift_Indi_VIDYA_SourceType = IDATA_BUILTIN; // Source type
// Structs.
// Defines struct with default user strategy values.
struct Stg_MA_Cross_Shift_Params_Defaults : StgParams {
uint shift1, shift2;
Stg_MA_Cross_Shift_Params_Defaults()
: StgParams(::MA_Cross_Shift_SignalOpenMethod, ::MA_Cross_Shift_SignalOpenFilterMethod,
::MA_Cross_Shift_SignalOpenLevel, ::MA_Cross_Shift_SignalOpenBoostMethod,
::MA_Cross_Shift_SignalCloseMethod, ::MA_Cross_Shift_SignalCloseFilter,
::MA_Cross_Shift_SignalCloseLevel, ::MA_Cross_Shift_PriceStopMethod, ::MA_Cross_Shift_PriceStopLevel,
::MA_Cross_Shift_TickFilterMethod, ::MA_Cross_Shift_MaxSpread, ::MA_Cross_Shift_Shift) {
Set(STRAT_PARAM_LS, MA_Cross_Shift_LotSize);
Set(STRAT_PARAM_OCL, MA_Cross_Shift_OrderCloseLoss);
Set(STRAT_PARAM_OCP, MA_Cross_Shift_OrderCloseProfit);
Set(STRAT_PARAM_OCT, MA_Cross_Shift_OrderCloseTime);
Set(STRAT_PARAM_SOFT, MA_Cross_Shift_SignalOpenFilterTime);
}
// Getters.
uint GetShift1() { return shift1; }
uint GetShift2() { return shift2; }
// Setters.
void SetShift1(uint _value) { shift1 = _value; }
void SetShift2(uint _value) { shift2 = _value; }
};
class Stg_MA_Cross_Shift : public Strategy {
protected:
Stg_MA_Cross_Shift_Params_Defaults ssparams;
public:
Stg_MA_Cross_Shift(StgParams &_sparams, TradeParams &_tparams, ChartParams &_cparams, string _name = "")
: Strategy(_sparams, _tparams, _cparams, _name) {}
static Stg_MA_Cross_Shift *Init(ENUM_TIMEFRAMES _tf = NULL, EA *_ea = NULL) {
// Initialize strategy initial values.
Stg_MA_Cross_Shift_Params_Defaults stg_ma_defaults;
StgParams _stg_params(stg_ma_defaults);
// Initialize Strategy instance.
ChartParams _cparams(_tf, _Symbol);
TradeParams _tparams;
Strategy *_strat = new Stg_MA_Cross_Shift(_stg_params, _tparams, _cparams, "MA");
return _strat;
}
/**
* Event on strategy's init.
*/
void OnInit() {
// Initialize indicators.
switch (MA_Cross_Shift_Type) {
case STG_MA_CROSS_SHIFT_TYPE_AMA: // AMA
{
IndiAMAParams _indi_params(::MA_Cross_Shift_Indi_AMA_InpPeriodAMA, ::MA_Cross_Shift_Indi_AMA_InpFastPeriodEMA,
::MA_Cross_Shift_Indi_AMA_InpSlowPeriodEMA, ::MA_Cross_Shift_Indi_AMA_InpShiftAMA,
PRICE_TYPICAL, ::MA_Cross_Shift_Indi_AMA_Shift);
_indi_params.SetTf(Get<ENUM_TIMEFRAMES>(STRAT_PARAM_TF));
SetIndicator(new Indi_AMA(_indi_params, ::MA_Cross_Shift_Indi_AMA_SourceType), ::MA_Cross_Shift_Type);
_indi_params.SetShift(::MA_Cross_Shift_Indi_AMA_Shift2);
SetIndicator(new Indi_AMA(_indi_params, ::MA_Cross_Shift_Indi_AMA_SourceType), ::MA_Cross_Shift_Type + 1);
ssparams.SetShift1(MA_Cross_Shift_Indi_AMA_Shift);
ssparams.SetShift2(MA_Cross_Shift_Indi_AMA_Shift2);
break;
}
case STG_MA_CROSS_SHIFT_TYPE_DEMA: // DEMA
{
IndiDEIndiMAParams _indi_params(::MA_Cross_Shift_Indi_DEMA_Period, ::MA_Cross_Shift_Indi_DEMA_MA_Shift,
::MA_Cross_Shift_Indi_DEMA_Applied_Price, ::MA_Cross_Shift_Indi_DEMA_Shift);
_indi_params.SetTf(Get<ENUM_TIMEFRAMES>(STRAT_PARAM_TF));
SetIndicator(new Indi_DEMA(_indi_params, ::MA_Cross_Shift_Indi_DEMA_SourceType), ::MA_Cross_Shift_Type);
_indi_params.SetShift(::MA_Cross_Shift_Indi_DEMA_Shift2);
SetIndicator(new Indi_DEMA(_indi_params, ::MA_Cross_Shift_Indi_DEMA_SourceType), ::MA_Cross_Shift_Type + 1);
ssparams.SetShift1(MA_Cross_Shift_Indi_DEMA_Shift);
ssparams.SetShift2(MA_Cross_Shift_Indi_DEMA_Shift2);
break;
}
case STG_MA_CROSS_SHIFT_TYPE_FRAMA: // FrAMA
{
IndiFrAIndiMAParams _indi_params(::MA_Cross_Shift_Indi_FrAMA_Period, ::MA_Cross_Shift_Indi_FrAMA_MA_Shift,
::MA_Cross_Shift_Indi_FrAMA_Applied_Price, ::MA_Cross_Shift_Indi_FrAMA_Shift);
_indi_params.SetTf(Get<ENUM_TIMEFRAMES>(STRAT_PARAM_TF));
SetIndicator(new Indi_FrAMA(_indi_params, ::MA_Cross_Shift_Indi_FrAMA_SourceType), ::MA_Cross_Shift_Type);
_indi_params.SetShift(::MA_Cross_Shift_Indi_FrAMA_Shift2);
SetIndicator(new Indi_FrAMA(_indi_params, ::MA_Cross_Shift_Indi_FrAMA_SourceType), ::MA_Cross_Shift_Type + 1);
ssparams.SetShift1(MA_Cross_Shift_Indi_FrAMA_Shift);
ssparams.SetShift2(MA_Cross_Shift_Indi_FrAMA_Shift2);
break;
}
case STG_MA_CROSS_SHIFT_TYPE_ICHIMOKU: // Ichimoku
{
IndiIchimokuParams _indi_params(
::MA_Cross_Shift_Indi_Ichimoku_Period_Tenkan_Sen, ::MA_Cross_Shift_Indi_Ichimoku_Period_Kijun_Sen,
::MA_Cross_Shift_Indi_Ichimoku_Period_Senkou_Span_B, ::MA_Cross_Shift_Indi_Ichimoku_Shift);
_indi_params.SetTf(Get<ENUM_TIMEFRAMES>(STRAT_PARAM_TF));
SetIndicator(new Indi_Ichimoku(_indi_params, ::MA_Cross_Shift_Indi_Ichimoku_SourceType), ::MA_Cross_Shift_Type);
_indi_params.SetShift(::MA_Cross_Shift_Indi_Ichimoku_Shift2);
SetIndicator(new Indi_Ichimoku(_indi_params, ::MA_Cross_Shift_Indi_Ichimoku_SourceType), ::MA_Cross_Shift_Type + 1);
ssparams.SetShift1(MA_Cross_Shift_Indi_Ichimoku_Shift);
ssparams.SetShift2(MA_Cross_Shift_Indi_Ichimoku_Shift2);
break;
}
case STG_MA_CROSS_SHIFT_TYPE_MA: // MA
{
IndiMAParams _indi_params(::MA_Cross_Shift_Indi_MA_Period, ::MA_Cross_Shift_Indi_MA_MA_Shift,
::MA_Cross_Shift_Indi_MA_Method, ::MA_Cross_Shift_Indi_MA_Applied_Price,
::MA_Cross_Shift_Indi_MA_Shift);
_indi_params.SetTf(Get<ENUM_TIMEFRAMES>(STRAT_PARAM_TF));
SetIndicator(new Indi_MA(_indi_params, ::MA_Cross_Shift_Indi_MA_SourceType), ::MA_Cross_Shift_Type);
_indi_params.SetShift(::MA_Cross_Shift_Indi_MA_Shift2);
SetIndicator(new Indi_MA(_indi_params, ::MA_Cross_Shift_Indi_MA_SourceType), ::MA_Cross_Shift_Type + 1);
ssparams.SetShift1(MA_Cross_Shift_Indi_MA_Shift);
ssparams.SetShift2(MA_Cross_Shift_Indi_MA_Shift2);
break;
}
case STG_MA_CROSS_SHIFT_TYPE_PRICE_CHANNEL: // Price Channel
{
IndiPriceChannelParams _indi_params(::MA_Cross_Shift_Indi_PriceChannel_Period,
::MA_Cross_Shift_Indi_PriceChannel_Shift);
_indi_params.SetTf(Get<ENUM_TIMEFRAMES>(STRAT_PARAM_TF));
SetIndicator(new Indi_PriceChannel(_indi_params, ::MA_Cross_Shift_Indi_PriceChannel_SourceType), ::MA_Cross_Shift_Type);
_indi_params.SetShift(::MA_Cross_Shift_Indi_PriceChannel_Shift2);
SetIndicator(new Indi_PriceChannel(_indi_params, ::MA_Cross_Shift_Indi_PriceChannel_SourceType), ::MA_Cross_Shift_Type + 1);
ssparams.SetShift1(MA_Cross_Shift_Indi_PriceChannel_Shift);
ssparams.SetShift2(MA_Cross_Shift_Indi_PriceChannel_Shift2);
break;
}
case STG_MA_CROSS_SHIFT_TYPE_SAR: // SAR
{
IndiSARParams _indi_params(::MA_Cross_Shift_Indi_SAR_Step, ::MA_Cross_Shift_Indi_SAR_Maximum_Stop,
::MA_Cross_Shift_Indi_SAR_Shift);
_indi_params.SetTf(Get<ENUM_TIMEFRAMES>(STRAT_PARAM_TF));
SetIndicator(new Indi_SAR(_indi_params, ::MA_Cross_Shift_Indi_SAR_SourceType), ::MA_Cross_Shift_Type);
_indi_params.SetShift(::MA_Cross_Shift_Indi_SAR_Shift2);
SetIndicator(new Indi_SAR(_indi_params, ::MA_Cross_Shift_Indi_SAR_SourceType), ::MA_Cross_Shift_Type + 1);
ssparams.SetShift1(MA_Cross_Shift_Indi_SAR_Shift);
ssparams.SetShift2(MA_Cross_Shift_Indi_SAR_Shift2);
break;
}
case STG_MA_CROSS_SHIFT_TYPE_TEMA: // TEMA
{
IndiTEMAParams _indi_params(::MA_Cross_Shift_Indi_TEMA_Period, ::MA_Cross_Shift_Indi_TEMA_MA_Shift,
::MA_Cross_Shift_Indi_TEMA_Applied_Price, ::MA_Cross_Shift_Indi_TEMA_Shift);
_indi_params.SetTf(Get<ENUM_TIMEFRAMES>(STRAT_PARAM_TF));
SetIndicator(new Indi_TEMA(_indi_params, ::MA_Cross_Shift_Indi_TEMA_SourceType), ::MA_Cross_Shift_Type);
_indi_params.SetShift(::MA_Cross_Shift_Indi_TEMA_Shift2);
SetIndicator(new Indi_TEMA(_indi_params, ::MA_Cross_Shift_Indi_TEMA_SourceType), ::MA_Cross_Shift_Type + 1);
ssparams.SetShift1(MA_Cross_Shift_Indi_TEMA_Shift);
ssparams.SetShift2(MA_Cross_Shift_Indi_TEMA_Shift2);
break;
}
case STG_MA_CROSS_SHIFT_TYPE_VIDYA: // VIDYA
{
IndiVIDYAParams _indi_params(::MA_Cross_Shift_Indi_VIDYA_Period, ::MA_Cross_Shift_Indi_VIDYA_MA_Period,
::MA_Cross_Shift_Indi_VIDYA_MA_Shift, ::MA_Cross_Shift_Indi_VIDYA_Applied_Price,
::MA_Cross_Shift_Indi_VIDYA_Shift);
_indi_params.SetTf(Get<ENUM_TIMEFRAMES>(STRAT_PARAM_TF));
SetIndicator(new Indi_VIDYA(_indi_params, ::MA_Cross_Shift_Indi_VIDYA_SourceType), ::MA_Cross_Shift_Type);
_indi_params.SetShift(::MA_Cross_Shift_Indi_VIDYA_Shift2);
SetIndicator(new Indi_VIDYA(_indi_params, ::MA_Cross_Shift_Indi_VIDYA_SourceType), ::MA_Cross_Shift_Type + 1);
ssparams.SetShift1(MA_Cross_Shift_Indi_VIDYA_Shift);
ssparams.SetShift2(MA_Cross_Shift_Indi_VIDYA_Shift2);
break;
}
case STG_MA_CROSS_SHIFT_TYPE_0_NONE: // (None)
default:
break;
}
}
/**
* Check strategy's opening signal.
*/
bool SignalOpen(ENUM_ORDER_TYPE _cmd, int _method = 0, float _level = 0.0f, int _shift = 0) {
IndicatorData *_indi1 = GetIndicator(::MA_Cross_Shift_Type);
IndicatorData *_indi2 = GetIndicator(::MA_Cross_Shift_Type + 1);
// uint _ishift1 = _indi1.GetParams().GetShift(); // @todo: Convert into Get().
// uint _ishift2 = _indi2.GetParams().GetShift(); // @todo: Convert into Get().
uint _ishift1 = ssparams.GetShift1();
uint _ishift2 = ssparams.GetShift2();
// bool _result = _indi.GetFlag(INDI_ENTRY_FLAG_IS_VALID, _shift); // @fixme
bool _result = true;
if (!_result) {
// Returns false when indicator data is not valid.
return false;
}
// float _level_pips = (float)(_level * _chart.GetPipSize());
double _value1 = _indi1[_ishift1][0];
double _value2 = _indi2[_ishift2][0];
switch (_cmd) {
case ORDER_TYPE_BUY:
// Buy signal.
_result &= _indi1.IsIncreasing(1, 0, _ishift1);
_result &= _indi1[_ishift1][0] > _indi2[_ishift2][0];
_result &= _indi1[_ishift1 + 1][0] < _indi2[_ishift2 + 1][0];
//_result &= Math::ChangeInPct(_indi1[_ishift1 + 1][0], _indi1[_ishift1][0], true) > _level;
if (_result && _method != 0) {
if (METHOD(_method, 0)) _result &= _indi1[_ishift1][0] < _indi1[_ishift1 + 3][0];
if (METHOD(_method, 1)) _result &= _indi2[_ishift2][0] < _indi2[_ishift2 + 3][0];
if (METHOD(_method, 2))
_result &= fmax4(_indi1[_ishift1][0], _indi1[_ishift1 + 1][0], _indi1[_ishift1 + 2][0],
_indi1[_ishift1 + 3][0]) == _indi1[_ishift1][0];
if (METHOD(_method, 3))
_result &= fmax4(_indi2[_ishift2][0], _indi2[_ishift2 + 1][0], _indi2[_ishift2 + 2][0],
_indi2[_ishift2 + 3][0]) == _indi2[_ishift2][0];
}
break;
case ORDER_TYPE_SELL:
// Sell signal.
_result &= _indi1.IsDecreasing(1, 0, _ishift1);
_result &= _indi1[_ishift1][0] < _indi2[_ishift2][0];
_result &= _indi1[_ishift1 + 1][0] > _indi2[_ishift2 + 1][0];
//_result &= Math::ChangeInPct(_indi1[_ishift1 + 1][0], _indi1[_ishift1][0], true) < _level;
if (_result && _method != 0) {
if (METHOD(_method, 0)) _result &= _indi1[_ishift1][0] > _indi1[_ishift1 + 3][0];
if (METHOD(_method, 1)) _result &= _indi2[_ishift2][0] > _indi2[_ishift2 + 3][0];
if (METHOD(_method, 2))
_result &= fmin4(_indi1[_ishift1][0], _indi1[_ishift1 + 1][0], _indi1[_ishift1 + 2][0],
_indi1[_ishift1 + 3][0]) == _indi1[_ishift1][0];
if (METHOD(_method, 3))
_result &= fmin4(_indi2[_ishift2][0], _indi2[_ishift2 + 1][0], _indi2[_ishift2 + 2][0],
_indi2[_ishift2 + 3][0]) == _indi2[_ishift2][0];
}
break;
}
return _result;
}
};