-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy path1-EUR_Grid 4.1.mq4
342 lines (335 loc) · 12.6 KB
/
1-EUR_Grid 4.1.mq4
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
//+------------------------------------------------------------------+
//| swb grid 4 .mq4 |
//| totom sukopratomo |
//| [email protected] |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//+----- belum punya account fxopen? --------------------------------+
//+----- buka di http://fxind.com?agent=123621 ----------------------+
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//+----- ingin bisa scalping dengan real tp 3 pips? -----------------+
//+----- ingin dapat bonus $30 dengan deposit awal $100? ------------+
//+----- buka account di http://instaforex.com/index.php?x=NQW ------+
//+------------------------------------------------------------------+
#property copyright "totom sukopratomo"
#property link "[email protected]"
#define buy -2
#define sell 2
//---- input parameters
extern string strcom="Grid";
extern bool use_daily_target=false;
extern double daily_target=100;
extern bool trade_in_fri=true;
extern int magic=1;
extern double start_lot=0.01;
extern double range=25;
extern int level=10;
extern bool lot_multiplier=true;
extern double multiplier=2.0;
extern double increament=0.1;
extern bool use_sl_and_tp=true;
extern double sl=60;
extern double tp=30;
extern double tp_in_money=5.0;
extern bool stealth_mode=true;
extern bool use_bb=true;
extern int bb_period=20;
extern int bb_deviation=2;
extern int bb_shift=0;
extern bool use_stoch=true;
extern int k=5;
extern int d=3;
extern int slowing=3;
extern int price_field=0;
extern int stoch_shift=0;
extern int lo_level=30;
extern int up_level=70;
extern bool use_rsi=true;
extern int rsi_period=12;
extern int rsi_shift=0;
extern int lower=30;
extern int upper=70;
double pt;
double minlot;
double stoplevel;
int prec=0;
int a=0;
int ticket=0;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
if(Digits==3 || Digits==5) pt=10*Point;
else pt=Point;
minlot = MarketInfo(Symbol(),MODE_MINLOT);
stoplevel=MarketInfo(Symbol(),MODE_STOPLEVEL);
if(start_lot<minlot) Print("lotsize is to small.");
if(sl<stoplevel) Print("stoploss is to tight.");
if(tp<stoplevel) Print("takeprofit is to tight.");
if(minlot==0.01) prec=2;
if(minlot==0.1) prec=1;
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
// start_lot= NormalizeDouble(AccountBalance() / 1000.0 * 0.01 * 1, 2);
if(use_daily_target && dailyprofit()>=daily_target)
{
Comment("\ndaily target achieved.");
return(0);
}
if(!trade_in_fri && DayOfWeek()==5 && total()==0)
{
Comment("\nstop trading in Friday.");
return(0);
}
if(total()==0 && a==0)
{
if(signal()==sell)
{
if(stealth_mode)
{
if(use_sl_and_tp) ticket=OrderSend(Symbol(),0,start_lot,Ask,3,Ask-sl*pt,Ask+tp*pt,strcom,magic,0,Blue);
else ticket=OrderSend(Symbol(),0,start_lot,Ask,3, 0, 0,strcom,magic,0,Blue);
}
else
{
if(use_sl_and_tp)
{
if(OrderSend(Symbol(),0,start_lot,Ask,3,Ask-sl*pt,Ask+tp*pt,strcom,magic,0,Blue)>0)
{
for(int i=1; i<level; i++)
{
if(lot_multiplier) ticket=OrderSend(Symbol(),2,NormalizeDouble(start_lot*MathPow(multiplier,i),prec),Ask-(range*i)*pt,3,(Ask-(range*i)*pt)-sl*pt,(Ask-(range*i)*pt)+tp*pt,strcom,magic,0,Blue);
else ticket=OrderSend(Symbol(),2,NormalizeDouble(start_lot+increament*i,prec) ,Ask-(range*i)*pt,3,(Ask-(range*i)*pt)-sl*pt,(Ask-(range*i)*pt)+tp*pt,strcom,magic,0,Blue);
}
}
}
else
{
if(OrderSend(Symbol(),0,start_lot,Ask,3,0,0,strcom,magic,0,Blue)>0)
{
for(i=1; i<level; i++)
{
if(lot_multiplier) ticket=OrderSend(Symbol(),2,NormalizeDouble(start_lot*MathPow(multiplier,i),prec),Ask-(range*i)*pt,3,0,0,strcom,magic,0,Blue);
else ticket=OrderSend(Symbol(),2,NormalizeDouble(start_lot+increament*i,prec) ,Ask-(range*i)*pt,3,0,0,strcom,magic,0,Blue);
}
}
}
}
}
if(signal()==buy)
{
if(stealth_mode)
{
if(use_sl_and_tp) ticket=OrderSend(Symbol(),1,start_lot,Bid,3,Bid+sl*pt,Bid-tp*pt,strcom,magic,0,Red);
else ticket=OrderSend(Symbol(),1,start_lot,Bid,3, 0, 0,strcom,magic,0,Red);
}
else
{
if(use_sl_and_tp)
{
if(OrderSend(Symbol(),1,start_lot,Bid,3,Bid+sl*pt,Bid-tp*pt,strcom,magic,0,Red)>0)
{
for(i=1; i<level; i++)
{
if(lot_multiplier) ticket=OrderSend(Symbol(),3,NormalizeDouble(start_lot*MathPow(multiplier,i),prec),Bid+(range*i)*pt,3,(Bid+(range*i)*pt)+sl*pt,(Bid+(range*i)*pt)-tp*pt,strcom,magic,0,Red);
else ticket=OrderSend(Symbol(),3,NormalizeDouble(start_lot+increament*i,prec) ,Bid+(range*i)*pt,3,(Bid+(range*i)*pt)+sl*pt,(Bid+(range*i)*pt)-tp*pt,strcom,magic,0,Red);
}
}
}
else
{
if(OrderSend(Symbol(),1,start_lot,Bid,3,0,0,strcom,magic,0,Red)>0)
{
for(i=1; i<level; i++)
{
if(lot_multiplier) ticket=OrderSend(Symbol(),3,NormalizeDouble(start_lot*MathPow(multiplier,i),prec),Bid+(range*i)*pt,3,0,0,strcom,magic,0,Red);
else ticket=OrderSend(Symbol(),3,NormalizeDouble(start_lot+increament*i,prec) ,Bid+(range*i)*pt,3,0,0,strcom,magic,0,Red);
}
}
}
}
}
}
if(stealth_mode && total()>0 && total()<level)
{
int type; double op, lastlot;
for(i=0; i<OrdersTotal(); i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=magic) continue;
type=OrderType();
op=OrderOpenPrice();
lastlot=OrderLots();
}
if(type==0 && Ask<=op-range*pt)
{
if(use_sl_and_tp)
{
if(lot_multiplier) ticket=OrderSend(Symbol(),0,NormalizeDouble(lastlot*multiplier,prec),Ask,3,Ask-sl*pt,Ask+tp*pt,strcom,magic,0,Blue);
else ticket=OrderSend(Symbol(),0,NormalizeDouble(lastlot+increament,prec),Ask,3,Ask-sl*pt,Ask+tp*pt,strcom,magic,0,Blue);
}
else
{
if(lot_multiplier) ticket=OrderSend(Symbol(),0,NormalizeDouble(lastlot*multiplier,prec),Ask,3,0,0,strcom,magic,0,Blue);
else ticket=OrderSend(Symbol(),0,NormalizeDouble(lastlot+increament,prec),Ask,3,0,0,strcom,magic,0,Blue);
}
}
if(type==1 && Bid>=op+range*pt)
{
if(use_sl_and_tp)
{
if(lot_multiplier) ticket=OrderSend(Symbol(),1,NormalizeDouble(lastlot*multiplier,prec),Bid,3,Bid+sl*pt,Bid-tp*pt,strcom,magic,0,Red);
else ticket=OrderSend(Symbol(),1,NormalizeDouble(lastlot+increament,prec),Bid,3,Bid+sl*pt,Bid-tp*pt,strcom,magic,0,Red);
}
else
{
if(lot_multiplier) ticket=OrderSend(Symbol(),1,NormalizeDouble(lastlot*multiplier,prec),Bid,3,0,0,strcom,magic,0,Red);
else ticket=OrderSend(Symbol(),1,NormalizeDouble(lastlot+increament,prec),Bid,3,0,0,strcom,magic,0,Red);
}
}
}
if(use_sl_and_tp && total()>1)
{
double s_l, t_p;
for(i=0; i<OrdersTotal(); i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=magic || OrderType()>1) continue;
type=OrderType();
s_l=OrderStopLoss();
t_p=OrderTakeProfit();
}
for(i=OrdersTotal()-1; i>=0; i--)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=magic || OrderType()>1) continue;
if(OrderType()==type)
{
if(OrderStopLoss()!=s_l || OrderTakeProfit()!=t_p)
{
OrderModify(OrderTicket(),OrderOpenPrice(),s_l,t_p,0,CLR_NONE);
}
}
}
}
double profit=0;
for(i=0; i<OrdersTotal(); i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=magic || OrderType()>1) continue;
profit+=OrderProfit();
}
if(profit>=tp_in_money || a>0)
{
closeall();
closeall();
closeall();
a++;
if(total()==0) a=0;
}
if(!stealth_mode && use_sl_and_tp && total()<level) closeall();
//----
//----
return(0);
}
//+------------------------------------------------------------------+
double dailyprofit()
{
int day=Day(); double res=0;
for(int i=0; i<OrdersHistoryTotal(); i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=magic) continue;
if(TimeDay(OrderOpenTime())==day) res+=OrderProfit();
}
return(res);
}
//+------------------------------------------------------------------+
int total()
{
int total=0;
for(int i=0; i<OrdersTotal(); i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=magic) continue;
total++;
}
return(total);
}
//+------------------------------------------------------------------+
int signal()
{
double upBB=iBands(Symbol(),0,bb_period,bb_deviation,0,PRICE_CLOSE,MODE_UPPER,bb_shift);
double loBB=iBands(Symbol(),0,bb_period,bb_deviation,0,PRICE_CLOSE,MODE_LOWER,bb_shift);
double stoch=iStochastic(Symbol(),0,k,d,slowing,MODE_SMA,price_field,MODE_SIGNAL,stoch_shift);
double rsi=iRSI(Symbol(),0,rsi_period,PRICE_CLOSE,rsi_shift);
if(use_bb && use_stoch && use_rsi)
{
if(High[bb_shift]>upBB && stoch>up_level && rsi>upper) return(sell);
if(Low[bb_shift]<loBB && stoch<lo_level && rsi<lower) return(buy);
}
if(use_bb && use_stoch && !use_rsi)
{
if(High[bb_shift]>upBB && stoch>up_level) return(sell);
if(Low[bb_shift]<loBB && stoch<lo_level) return(buy);
}
if(use_bb && !use_stoch && !use_rsi)
{
if(High[bb_shift]>upBB) return(sell);
if(Low[bb_shift]<loBB) return(buy);
}
if(!use_bb && use_stoch && use_rsi)
{
if(stoch>up_level && rsi>upper) return(sell);
if(stoch<lo_level && rsi<lower) return(buy);
}
if(!use_bb && use_stoch && !use_rsi)
{
if(stoch>up_level) return(sell);
if(stoch<lo_level) return(buy);
}
if(use_bb && !use_stoch && use_rsi)
{
if(High[bb_shift]>upBB && rsi>upper) return(sell);
if(Low[bb_shift]<loBB && rsi<lower) return(buy);
}
if(!use_bb && !use_stoch && use_rsi)
{
if(rsi>upper) return(sell);
if(rsi<lower) return(buy);
}
return(0);
}
//+------------------------------------------------------------------+
void closeall()
{
for(int i=OrdersTotal()-1; i>=0; i--)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=magic) continue;
if(OrderType()>1) OrderDelete(OrderTicket());
else
{
if(OrderType()==0) OrderClose(OrderTicket(),OrderLots(),Bid,3,CLR_NONE);
else OrderClose(OrderTicket(),OrderLots(),Ask,3,CLR_NONE);
}
}
}