-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathcrossover_2ema.mq5
167 lines (167 loc) · 5.88 KB
/
crossover_2ema.mq5
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
//+------------------------------------------------------------------+
//| Crossover_2EMA.mq5 |
//| Copyright 2010, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2010, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property version "1.00"
//+------------------------------------------------------------------+
//| Include |
//+------------------------------------------------------------------+
#include <Expert\Expert.mqh>
#include <Expert\Signal\SignalCrossEMA.mqh>
#include <Expert\Trailing\TrailingNone.mqh>
#include <Expert\Money\MoneyFixedLot.mqh>
//+------------------------------------------------------------------+
//| Inputs |
//+------------------------------------------------------------------+
//--- inputs for expert
input string Inp_Expert_Title ="Crossover_2EMA";
int Expert_MagicNumber =14395;
bool Expert_EveryTick =false;
//--- inputs for signal
input int Inp_Signal_CrossEMA_FastPeriod=12;
input int Inp_Signal_CrossEMA_SlowPeriod=24;
//--- inputs for money
input double Inp_Money_FixLot_Percent =10.0;
input double Inp_Money_FixLot_Lots =0.1;
//+------------------------------------------------------------------+
//| Global expert object |
//+------------------------------------------------------------------+
CExpert ExtExpert;
//+------------------------------------------------------------------+
//| Initialization function of the expert |
//+------------------------------------------------------------------+
int OnInit()
{
//--- Initializing expert
if(!ExtExpert.Init(Symbol(),Period(),Expert_EveryTick,Expert_MagicNumber))
{
//--- failed
printf(__FUNCTION__+": error initializing expert");
ExtExpert.Deinit();
return(-1);
}
//--- Creation of signal object
CSignalCrossEMA *signal=new CSignalCrossEMA;
if(signal==NULL)
{
//--- failed
printf(__FUNCTION__+": error creating signal");
ExtExpert.Deinit();
return(-2);
}
//--- Add signal to expert (will be deleted automatically))
if(!ExtExpert.InitSignal(signal))
{
//--- failed
printf(__FUNCTION__+": error initializing signal");
ExtExpert.Deinit();
return(-3);
}
//--- Set signal parameters
signal.FastPeriod(Inp_Signal_CrossEMA_FastPeriod);
signal.SlowPeriod(Inp_Signal_CrossEMA_SlowPeriod);
//--- Check signal parameters
if(!signal.ValidationSettings())
{
//--- failed
printf(__FUNCTION__+": error signal parameters");
ExtExpert.Deinit();
return(-4);
}
//--- Creation of trailing object
CTrailingNone *trailing=new CTrailingNone;
if(trailing==NULL)
{
//--- failed
printf(__FUNCTION__+": error creating trailing");
ExtExpert.Deinit();
return(-5);
}
//--- Add trailing to expert (will be deleted automatically))
if(!ExtExpert.InitTrailing(trailing))
{
//--- failed
printf(__FUNCTION__+": error initializing trailing");
ExtExpert.Deinit();
return(-6);
}
//--- Set trailing parameters
//--- Check trailing parameters
if(!trailing.ValidationSettings())
{
//--- failed
printf(__FUNCTION__+": error trailing parameters");
ExtExpert.Deinit();
return(-7);
}
//--- Creation of money object
CMoneyFixedLot *money=new CMoneyFixedLot;
if(money==NULL)
{
//--- failed
printf(__FUNCTION__+": error creating money");
ExtExpert.Deinit();
return(-8);
}
//--- Add money to expert (will be deleted automatically))
if(!ExtExpert.InitMoney(money))
{
//--- failed
printf(__FUNCTION__+": error initializing money");
ExtExpert.Deinit();
return(-9);
}
//--- Set money parameters
money.Percent(Inp_Money_FixLot_Percent);
money.Lots(Inp_Money_FixLot_Lots);
//--- Check money parameters
if(!money.ValidationSettings())
{
//--- failed
printf(__FUNCTION__+": error money parameters");
ExtExpert.Deinit();
return(-10);
}
//--- Tuning of all necessary indicators
if(!ExtExpert.InitIndicators())
{
//--- failed
printf(__FUNCTION__+": error initializing indicators");
ExtExpert.Deinit();
return(-11);
}
//--- ok
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Deinitialization function of the expert |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
ExtExpert.Deinit();
}
//+------------------------------------------------------------------+
//| Function-event handler "tick" |
//+------------------------------------------------------------------+
void OnTick()
{
ExtExpert.OnTick();
}
//+------------------------------------------------------------------+
//| Function-event handler "trade" |
//+------------------------------------------------------------------+
void OnTrade()
{
ExtExpert.OnTrade();
}
//+------------------------------------------------------------------+
//| Function-event handler "timer" |
//+------------------------------------------------------------------+
void OnTimer()
{
ExtExpert.OnTimer();
}
//+------------------------------------------------------------------+