-
Notifications
You must be signed in to change notification settings - Fork 12
/
exp_multic.mq5
159 lines (158 loc) · 5.88 KB
/
exp_multic.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
//+------------------------------------------------------------------+
//| exp_multic.mq5 |
//| Copyright 2012-2016, DC2008 |
//| http://www.mql5.com/ru/users/dc2008 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012-2016, DC2008"
#property link "http://www.mql5.com/ru/users/dc2008"
#property version "1.00"
#property description "Expert implements the strategy of multi-currency trading"
#property description "without using technical analysis indicators"
//---
#include <Trade\Trade.mqh>
//---
#define EURUSD "EURUSD"
#define GBPUSD "GBPUSD"
#define USDJPY "USDJPY"
#define USDCHF "USDCHF"
#define USDCAD "USDCAD"
#define AUDUSD "AUDUSD"
#define EURGBP "EURGBP"
#define EURJPY "EURJPY"
#define EURAUD "EURAUD"
#define GBPJPY "GBPJPY"
//---
MqlTick last_tick;
CTrade trade;
//---
input int loss=1900; // óáûòîê â âàëþòå äåïîçèòà
input int profit=4000; // ïðèáûëü â âàëþòå äåïîçèòà
input int margin=5000; // ìèíèìàëüíûé ðàçìåð äåïîçèòà, ïðè êîòîðîì âîçìîæíà òîðãîâëÿ
input double minLot=0.01; // ìèíèìàëüíûé îáú¸ì ïîçèöèè
input int k_change=2100; // êîýôôèöèåíò äëÿ ðàñ÷¸òà óáûòêà ïðè èçìåíåíèè ïîçèöèè
input int k_closse=4600; // êîýôôèöèåíò äëÿ ðàñ÷¸òà ïðèáûëè ïðè çàêðûòèè ïîçèöèè
//---
string valuta[10]=
{
EURUSD,
GBPUSD,
USDJPY,
USDCHF,
USDCAD,
AUDUSD,
EURGBP,
EURJPY,
EURAUD,
GBPJPY
};
int N; // êîëè÷åñòâî âàëþòíûõ ïàð
bool Type[10]; // íàïðàâëåíèå òîðãîâëè äëÿ êàæäîé âàëþòíîé ïàðû: BUY èëè SELL
double Lot[10]; // ðàçìåð ëîòà äëÿ êàæäîé âàëþòíîé ïàðû
string main_comment; // ñòðîêà êîììåíòàðèÿ
bool on_trade; // ðàçðåøàåì èëè çàïðåùàåì òîðãîâëþ
double realEquity; // ñòàðòîâûé áàëàíñ
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
Comment("");
realEquity=AccountInfoDouble(ACCOUNT_BALANCE);
main_comment="exp_multic: ";
N=ArraySize(valuta);
on_trade=true;
for(int i=0;i<N; i++)
{
Type[i]=true;
Lot[i]=minLot;
}
return(0);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Comment("");
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
double Balans=AccountInfoDouble(ACCOUNT_BALANCE);
double Equity=AccountInfoDouble(ACCOUNT_EQUITY);
double FreeMargin=AccountInfoDouble(ACCOUNT_MARGIN_FREE);
Comment("Ñòàðòîâûé áàëàíñ: ",NormalizeDouble(realEquity,2),
"\n","Òåêóùèé áàëàíñ: ",NormalizeDouble(Balans,2),
"\n","Ðåçóëüòàò òîðãîâëè ðîáîòà: ",NormalizeDouble(Balans-realEquity,2));
//---
if(Balans-Equity>loss) on_trade=false; // ïðè äîñòèæåíèè çàäàííîãî óáûòêà âñå ïîçèöèè çàêðûâàþòñÿ
if(Equity-Balans>profit) on_trade=false; // ïðè äîñòèæåíèè çàäàííîé ïðèáûëè âñå ïîçèöèè çàêðûâàþòñÿ
//--- Çàêðûòèå âñåõ ïîçèöèé ïðèíóäèòåëüíî
if(!on_trade)
{
for(int i=0;i<N; i++)
{
trade.PositionClose(valuta[i]);
Lot[i]=minLot;
}
on_trade=true;
}
//---
if(on_trade)
{
for(int i=0;i<N; i++)
{
if(PositionSelect(valuta[i]))
{
//--- Åñëè ïîçèöèÿ ïðèáûëüíàÿ, òî íàðàùèâàåì îáú¸ì
if(PositionGetDouble(POSITION_PROFIT)>Lot[i]*k_change)
{
Lot[i]=Lot[i]+minLot;
double lot=minLot;
if(Type[i])
{
SymbolInfoTick(valuta[i],last_tick);
double price=last_tick.ask;
trade.PositionOpen(valuta[i],ORDER_TYPE_BUY,NormalizeDouble(lot,2),price,0,0,main_comment+valuta[i]);
}
else
{
SymbolInfoTick(valuta[i],last_tick);
double price=last_tick.bid;
trade.PositionOpen(valuta[i],ORDER_TYPE_SELL,NormalizeDouble(lot,2),price,0,0,main_comment+valuta[i]);
}
}
//--- Åñëè ïîçèöèÿ óáûòî÷íàÿ, òî çàêðûâàåì å¸ è äà¸ì êîìàíäó íà ðàçâîðîò
if(PositionGetDouble(POSITION_PROFIT)<-Lot[i]*k_change)
{
Type[i]=!Type[i];
trade.PositionClose(valuta[i]);
}
//--- Çàêðûâàåì ïðèáûëüíóþ ïîçèöèþ
if(PositionGetDouble(POSITION_PROFIT)>minLot*k_closse)
trade.PositionClose(valuta[i]);
}
//--- Îòêðûòèå íîâûõ ïîçèöèé
if(!PositionSelect(valuta[i]) && FreeMargin>margin)
{
Lot[i]=minLot;
double lot=minLot;
if(Type[i])
{
SymbolInfoTick(valuta[i],last_tick);
double price=last_tick.ask;
trade.PositionOpen(valuta[i],ORDER_TYPE_BUY,NormalizeDouble(lot,2),price,0,0,main_comment+valuta[i]);
}
else
{
SymbolInfoTick(valuta[i],last_tick);
double price=last_tick.bid;
trade.PositionOpen(valuta[i],ORDER_TYPE_SELL,NormalizeDouble(lot,2),price,0,0,main_comment+valuta[i]);
}
}
}
}
}
//+------------------------------------------------------------------+