-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathMTC _ombo v2.mq5
378 lines (367 loc) · 26.2 KB
/
MTC _ombo v2.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
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
//+------------------------------------------------------------------+
//| MTC Сombo v2(barabashkakvn's edition).mq5 |
//| Copyright © 2008, Yury V. Reshetov |
//| http://bigforex.biz/load/2-1-0-171 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, Yury V. Reshetov"
#property link "http://bigforex.biz/load/2-1-0-171"
#property version "2.002"
#property description "Тетсирование разных индикаторов, смещений..."
#include <Trade\AccountInfo.mqh>
#include <Trade\SymbolInfo.mqh>
#include <Trade\PositionInfo.mqh>
#include <Trade\Trade.mqh>
CAccountInfo m_account; // account info wrapper
CSymbolInfo m_symbol; // symbol info object
CPositionInfo m_position; // trade position object
CTrade m_trade; // trading object
//---- input parameters
input uchar bar=0;
input int ma_period = 2; // averaging period
input int ma_shift=0; // horizontal shift
input ENUM_MA_METHOD ma_method=MODE_SMA; // smoothing type
input ENUM_APPLIED_PRICE applied_price=PRICE_CLOSE; // type of price or handle
input double tp1 = 50;
input double sl1 = 50;
//input int p1=10;
input int x12 = 100;
input int x22 = 100;
input int x32 = 100;
input int x42 = 100;
input double tp2 = 50;
input double sl2 = 50;
input int p2=20;
input int x13 = 100;
input int x23 = 100;
input int x33 = 100;
input int x43 = 100;
input double tp3 = 50;
input double sl3 = 50;
input int p3=20;
input int x14 = 100;
input int x24 = 100;
input int x34 = 100;
input int x44 = 100;
input int p4=20;
input int pass=10;
input double m_lots=0.01;
input ulong mn=888;
static datetime prevtime=0;
static double m_sl = 100;
static double m_tp = 100;
//---
int handle_iCCI; // variable for storing the handle of the iCCI indicator
int handle_iMA; // variable for storing the handle of the iMA indicator
string WindowExpertName="";
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
if(m_lots<=0.0)
{
Print("The \"volume transaction\" can't be smaller or equal to zero");
return(INIT_PARAMETERS_INCORRECT);
}
////--- create handle of the indicator iCCI
// handle_iCCI=iCCI(Symbol(),Period(),p1,PRICE_OPEN);
////--- if the handle is not created
// if(handle_iCCI==INVALID_HANDLE)
// {
// //--- tell about the failure and output the error code
// PrintFormat("Failed to create handle of the iCCI indicator for the symbol %s/%s, error code %d",
// Symbol(),
// EnumToString(Period()),
// GetLastError());
// //--- the indicator is stopped early
// return(INIT_FAILED);
// }
//--- create handle of the indicator iMA
handle_iMA=iMA(Symbol(),Period(),ma_period,ma_shift,ma_method,applied_price);
//--- if the handle is not created
if(handle_iMA==INVALID_HANDLE)
{
//--- tell about the failure and output the error code
PrintFormat("Failed to create handle of the iMA indicator for the symbol %s/%s, error code %d",
Symbol(),
EnumToString(Period()),
GetLastError());
//--- the indicator is stopped early
return(INIT_FAILED);
}
m_trade.SetExpertMagicNumber(mn); // sets magic number
m_trade.SetDeviationInPoints(10); // sets deviation
m_symbol.Name(Symbol()); // sets symbol name
RefreshRates();
WindowExpertName=MQLInfoString(MQL_PROGRAM_NAME);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(iTime(Symbol(),Period(),0)==prevtime)
return;
prevtime=iTime(Symbol(),Period(),0);
if(!IsTradeAllowed())
{
again();
return;
}
//---
int total=PositionsTotal();
for(int i=total-1; i>=0; i--)
{
if(!m_position.SelectByIndex(i))
return;
if(m_position.Symbol()==Symbol() && m_position.Magic()==mn)
{
return;
}
}
m_sl = sl1;
m_tp = tp1;
ulong m_ticket=0;
if(!RefreshRates())
return;
if(Supervisor()>0)
{
if(m_trade.Buy(m_lots,Symbol(),m_symbol.Ask(),
m_symbol.Ask()-m_sl*Point(),m_symbol.Ask()+m_tp*Point(),WindowExpertName))
{
m_ticket=m_trade.ResultDeal();
}
if(m_ticket==0)
{
again();
}
}
else
{
if(m_trade.Sell(m_lots,Symbol(),m_symbol.Bid(),
m_symbol.Bid()+m_sl*Point(),m_symbol.Bid()-m_tp*Point(),WindowExpertName))
{
m_ticket=m_trade.ResultDeal();
}
if(m_ticket==0)
{
again();
}
}
//--- exit ---
return;
}
//+------------------------------------------------------------------+
//| getLots |
//+------------------------------------------------------------------+
double Supervisor()
{
if(pass==4)
{
if(perceptron3()>0)
{
if(perceptron2()>0)
{
m_sl = sl3;
m_tp = tp3;
return(1.0);
}
}
else
{
if(perceptron1()<0)
{
m_sl = sl2;
m_tp = tp2;
return(-1.0);
}
}
return(basicTradingSystem());
}
if(pass==3)
{
if(perceptron2()>0)
{
m_sl = sl3;
m_tp = tp3;
return(1.0);
}
else
{
return(basicTradingSystem());
}
}
if(pass==2)
{
if(perceptron1()<0)
{
m_sl = sl2;
m_tp = tp2;
return(-1.0);
}
else
{
return(basicTradingSystem());
}
}
return(basicTradingSystem());
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double perceptron1()
{
double w1 = x12 - 100;
double w2 = x22 - 100;
double w3 = x32 - 100;
double w4 = x42 - 100;
double a1 = iClose(Symbol(),Period(),0) - iOpen(Symbol(),Period(),p2);
double a2 = iOpen(Symbol(),Period(),p2) - iOpen(Symbol(),Period(),p2 * 2);
double a3 = iOpen(Symbol(),Period(),p2 * 2) - iOpen(Symbol(),Period(),p2 * 3);
double a4 = iOpen(Symbol(),Period(),p2 * 3) - iOpen(Symbol(),Period(),p2 * 4);
return(w1 * a1 + w2 * a2 + w3 * a3 + w4 * a4);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double perceptron2()
{
double w1 = x13 - 100;
double w2 = x23 - 100;
double w3 = x33 - 100;
double w4 = x43 - 100;
double a1 = iClose(Symbol(),Period(),0) - iOpen(Symbol(),Period(),p3);
double a2 = iOpen(Symbol(),Period(),p3) - iOpen(Symbol(),Period(),p3 * 2);
double a3 = iOpen(Symbol(),Period(),p3 * 2) - iOpen(Symbol(),Period(),p3 * 3);
double a4 = iOpen(Symbol(),Period(),p3 * 3) - iOpen(Symbol(),Period(),p3 * 4);
return(w1 * a1 + w2 * a2 + w3 * a3 + w4 * a4);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double perceptron3()
{
double w1 = x14 - 100;
double w2 = x24 - 100;
double w3 = x34 - 100;
double w4 = x44 - 100;
double a1 = iClose(Symbol(),Period(),0) - iOpen(Symbol(),Period(),p4);
double a2 = iOpen(Symbol(),Period(),p4) - iOpen(Symbol(),Period(),p4 * 2);
double a3 = iOpen(Symbol(),Period(),p4 * 2) - iOpen(Symbol(),Period(),p4 * 3);
double a4 = iOpen(Symbol(),Period(),p4 * 3) - iOpen(Symbol(),Period(),p4 * 4);
return(w1 * a1 + w2 * a2 + w3 * a3 + w4 * a4);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double basicTradingSystem()
{
//return(iCCIGet(0));
return(iMAGet(bar));
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void again()
{
prevtime=iTime(Symbol(),Period(),1);
Sleep(30000);
}
//+------------------------------------------------------------------+
//| Get value of buffers for the iCCI |
//+------------------------------------------------------------------+
double iCCIGet(const int index)
{
double CCI[];
ArraySetAsSeries(CCI,true);
//--- reset error code
ResetLastError();
//--- fill a part of the iCCIBuffer array with values from the indicator buffer that has 0 index
if(CopyBuffer(handle_iCCI,0,0,index+1,CCI)<0)
{
//--- if the copying fails, tell the error code
PrintFormat("Failed to copy data from the iCCI indicator, error code %d",GetLastError());
//--- quit with zero result - it means that the indicator is considered as not calculated
return(0.0);
}
return(CCI[index]);
}
//+------------------------------------------------------------------+
//| Gets the information about permission to trade |
//+------------------------------------------------------------------+
bool IsTradeAllowed()
{
if(!TerminalInfoInteger(TERMINAL_TRADE_ALLOWED))
{
Alert("Check if automated trading is allowed in the terminal settings!");
return(false);
}
if(!TerminalInfoInteger(TERMINAL_TRADE_ALLOWED))
{
Alert("Check if automated trading is allowed in the terminal settings!");
return(false);
}
else
{
if(!MQLInfoInteger(MQL_TRADE_ALLOWED))
{
Alert("Automated trading is forbidden in the program settings for ",__FILE__);
return(false);
}
}
if(!AccountInfoInteger(ACCOUNT_TRADE_EXPERT))
{
Alert("Automated trading is forbidden for the account ",AccountInfoInteger(ACCOUNT_LOGIN),
" at the trade server side");
return(false);
}
if(!AccountInfoInteger(ACCOUNT_TRADE_ALLOWED))
{
Comment("Trading is forbidden for the account ",AccountInfoInteger(ACCOUNT_LOGIN),
".\n Perhaps an investor password has been used to connect to the trading account.",
"\n Check the terminal journal for the following entry:",
"\n\'",AccountInfoInteger(ACCOUNT_LOGIN),"\': trading has been disabled - investor mode.");
return(false);
}
//---
return(true);
}
//+------------------------------------------------------------------+
//| Refreshes the symbol quotes data |
//+------------------------------------------------------------------+
bool RefreshRates()
{
//--- refresh rates
if(!m_symbol.RefreshRates())
return(false);
//--- protection against the return value of "zero"
if(m_symbol.Ask()==0 || m_symbol.Bid()==0)
return(false);
//---
return(true);
}
//+------------------------------------------------------------------+
//| Get value of buffers for the iMA |
//+------------------------------------------------------------------+
double iMAGet(const int index)
{
double MA[];
ArraySetAsSeries(MA,true);
//--- reset error code
ResetLastError();
//--- fill a part of the iMABuffer array with values from the indicator buffer that has 0 index
if(CopyBuffer(handle_iMA,0,0,index+2,MA)<0)
{
//--- if the copying fails, tell the error code
PrintFormat("Failed to copy data from the iMA indicator, error code %d",GetLastError());
//--- quit with zero result - it means that the indicator is considered as not calculated
return(0.0);
}
double right=MA[index];
double left=MA[index+1];
return(right-left);
}
//+------------------------------------------------------------------+