-
Notifications
You must be signed in to change notification settings - Fork 0
/
Russia.c
435 lines (401 loc) · 15.5 KB
/
Russia.c
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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
//+-------------------------------------------------------------------------------+
//| 彦眵嚓钼 惕踵桦. [email protected]
//| 泥眄 镳钿箨?疣琊噌铗囗 镳钽疣祆桉蝾?疣琊噌铗麒觐?彦眵嚓钼 惕踵桦铎
//| 镳?镱滗屦骊??耧铐耔痤忄龛?戾驿箜囵钿眍泐 钺滂礤龛 蝠彘溴痤?
//| 埋?镳噔?玎睇 (?.
//+-------------------------------------------------------------------------------+
extern string 桎屙蜩翳赅蝾= "_1";
extern string _info="软纛痨屦";
extern bool 怅隷桧纛 = true;
extern string s__ ="锣膻蝽 镟瘥";
extern string 镟疣_1 = "EURUSD";
extern string 镟疣_2 = "GBPUSD";
extern string 镟疣_3 = "USDJPY";
extern string din = "蔫磬扈麇耜桢 镟疣戾蝠";
extern double 镳铞屙騙腩騙镟疣_1 = 1;
extern double 镳铞屙騙腩騙镟疣_2 = 1;
extern double 镳铞屙騙腩騙镟疣_3 = 1;
extern string t1 ="--------------------------------------";
extern double 镳铞屙騙玎牮 = 10;
extern string t2 ="--------------------------------------";
extern string tf_ = "朽犷麒?蜞殪-麴彘?潆 赅驿铋 忄膻蝽铋 镟瘥";
extern int 以_镟疣_1 = 240;
extern int 以_镟疣_2 = 240;
extern int 以_镟疣_3 = 240;
extern string tf__= "朽犷麒?蜞殪-麴彘?桧滂赅蝾疣 褥矬朦";
extern int _以_镟疣_1 = 240;
extern int _以_镟疣_2 = 240;
extern int _以_镟疣_3 = 240;
extern string l_ = "暑翳鲨屙?玎忤耔祛耱?腩蜞 铗 褥矬朦襦 (0-恹觌)";
extern double 觐_镟疣_1 = 1.2;
extern double 觐_镟疣_2 = 1.2;
extern double 觐_镟疣_3 = 1.2;
extern string p_ = "襄痂钿 篑疱漤屙? 桧滂赅蝾疣";
extern int 镥痂钿_镟疣_1 = 6;
extern int 镥痂钿_镟疣_2 = 6;
extern int 镥痂钿_镟疣_3 = 6;
extern string s_ ="绣骅?疣犷螓";
extern bool 蝈牦開徉 = true;
extern bool 耦忪妁屙睇開疱骅= false;
extern string magics = "箜桕嚯 眍戾?";
extern int magic = 1;
extern string dop_ = "青镳弪 篑蜞眍怅?耩噻?镱耠?玎牮?";
extern bool 玎镳弪 = false;
//+------------------------------------------------------------------+
int kol;
//+------------------------------------------------------------------+
int init()
{
check();
if (kol>0)
{
if (GlobalVariableGet(桎屙蜩翳赅蝾,"_balance")==0)
GlobalVariableSet(桎屙蜩翳赅蝾,"_balance",AccountBalance());
}
return(0);
}
//+------------------------------------------------------------------+
void check()
{
kol=0;
int total = OrdersTotal() - 1;
for (int i = total; i >= 0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderMagicNumber()==magic)
kol++;
}
}
}
//+------------------------------------------------------------------+
double value_profit(int magic)
{
double ld_0 = 0;
int l_ord_total_8 = OrdersTotal();
if (l_ord_total_8 > 0)
{
for (int l_pos_12 = l_ord_total_8 - 1; l_pos_12 >= 0; l_pos_12--)
{
if (OrderSelect(l_pos_12, SELECT_BY_POS, MODE_TRADES))
{
if (OrderMagicNumber() == magic)
ld_0 += OrderProfit() + OrderSwap()+OrderCommission();
}
}
}
return(ld_0);
}
//+------------------------------------------------------------------+
void CloseAll(int magic)
{
int total = OrdersTotal() - 1;
for (int i = total; i >= 0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderMagicNumber() == magic)
{
if (OrderType() == OP_SELL || OrderType() == OP_BUY)
OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 20, Yellow);
}
}
}
}
//+------------------------------------------------------------------+
double 褥矬朦(string 镟疣, int 以_桧濑赅, int 镥痂钿, int 徉, string type)
{
double dot1,dot2;
int 觐隷腩磴 =0;
int 觐隷痱 =0;
double sum_long =0;
double sum_short=0;
for(int j=徉?j<徉?镥痂钿; j++)
{
dot1=iClose(镟疣,以_桧濑赅,j);
dot2=iOpen(镟疣,以_桧濑赅,j+2);
if(dot1>dot2)
{
sum_long+=MathAbs(dot1-dot2);
觐隷腩磴++;
} else
if(dot1<dot2)
{
sum_short+=MathAbs(dot1-dot2);
觐隷痱++;
}
}
if (觐隷腩磴==0) 觐隷腩磴=1;
if (觐隷痱==0) 觐隷痱=1;
if (type=="long")
return(sum_long/觐隷腩磴); else
if (type=="short")
return(sum_short/觐隷痱);
}
//+------------------------------------------------------------------+
double cost(string 镟疣, int digits, double _lot)
{
double kf;
if (digits<=4) kf=1; else kf=10;
double tickvalue =kf*MarketInfo(镟疣, MODE_TICKVALUE);
return(tickvalue * _lot);
}
//+------------------------------------------------------------------+
void 篑蜞眍怅?string 镟疣, double 腩? int 以, int 以_桧濑赅, double 觐, int 镥痂钿)
{
double bid =MarketInfo(镟疣,MODE_BID);
double ask =MarketInfo(镟疣,MODE_ASK);
int digits=MarketInfo(镟疣,MODE_DIGITS);
double pp;
int dd;
if (digits < 4)
{
pp = 0.01;
dd = 100;
}
else
{
pp = 0.0001;
dd = 10000;
}
double necessary_=(腩?100)*GlobalVariableGet(桎屙蜩翳赅蝾?"_balance");
double lot;
double minlot=MarketInfo(镟疣,MODE_MINLOT);
double sumlot=0;
double tmp_profit=0;
double range;
double _dot=ask+30*pp;
while(tmp_profit<necessary_)
{
tmp_profit=0;
sumlot+=minlot;
range=ask;
tmp_profit+=(_dot-range)*dd*cost(镟疣,digits,sumlot);
}
lot=sumlot;
double dot1,dot2,dot3;
double dot4,dot5,dot6;
int n,Ticket;
if (蝈牦開徉?=true || 耦忪妁屙睇開疱骅?=true)
{
if (GlobalVariableGet(桎屙蜩翳赅蝾,镟疣+"_time_long")!=iTime(镟疣,以,0))
{
dot1=褥矬朦(镟疣,以_桧濑赅,镥痂钿,0,"long");
dot2=褥矬朦(镟疣,以_桧濑赅,镥痂钿,1,"long");
dot3=褥矬朦(镟疣,以_桧濑赅,镥痂钿,2,"long");
if (dot2>=dot3 && dot1>dot2)
{
dot4=褥矬朦(镟疣,以_桧濑赅,镥痂钿,0,"short");
dot5=褥矬朦(镟疣,以_桧濑赅,镥痂钿,1,"short");
dot6=褥矬朦(镟疣,以_桧濑赅,镥痂钿,2,"short");
if (dot6>=dot5 && dot5>=dot4)
{
GlobalVariableSet(桎屙蜩翳赅蝾,镟疣+"_time_long",iTime(镟疣,以,0));
if (觐>0) lot=sumlot*(((dot1-dot2)*100+1)*觐);
while (IsTradeAllowed()==false) Sleep(0);
n=3;
Ticket=-1;
while (Ticket<0 && n>0)
{
Ticket=OrderSend(镟疣,OP_BUY,NormalizeDouble(lot,2),NormalizeDouble(ask,digits),3,0,0,"铕溴?腩磴 铗 瘥黻?:"+TimeToStr(TimeCurrent(),TIME_MINUTES),magic,0,Blue);
n--;
}
}
}
}
if (GlobalVariableGet(桎屙蜩翳赅蝾,镟疣+"_time_short")!=iTime(镟疣,以,0))
{
dot1=褥矬朦(镟疣,以_桧濑赅,镥痂钿,0,"short");
dot2=褥矬朦(镟疣,以_桧濑赅,镥痂钿,1,"short");
dot3=褥矬朦(镟疣,以_桧濑赅,镥痂钿,2,"short");
if (dot2>=dot3 && dot1>dot2)
{
dot4=褥矬朦(镟疣,以_桧濑赅,镥痂钿,0,"long");
dot5=褥矬朦(镟疣,以_桧濑赅,镥痂钿,1,"long");
dot6=褥矬朦(镟疣,以_桧濑赅,镥痂钿,2,"long");
if (dot6>=dot5 && dot5>=dot4)
{
GlobalVariableSet(桎屙蜩翳赅蝾?镟疣+"_time_short",iTime(镟疣,以,0));
if (觐>0) lot=sumlot*(((dot1-dot2)*100+1)*觐);
while (IsTradeAllowed()==false) Sleep(0);
n=3;
Ticket=-1;
while (Ticket<0 && n>0)
{
Ticket=OrderSend(镟疣,OP_SELL,NormalizeDouble(lot,2),NormalizeDouble(bid,digits),3,0,0,"铕溴?痱 铗 瘥黻?:"+TimeToStr(TimeCurrent(),TIME_MINUTES),magic,0,Red);
n--;
}
}
}
}
}
if (蝈牦開徉?=false || 耦忪妁屙睇開疱骅?=true)
{
if (GlobalVariableGet(桎屙蜩翳赅蝾,镟疣+"_time")!=iTime(镟疣,以,0))
{
GlobalVariableSet(桎屙蜩翳赅蝾,镟疣+"_time",iTime(镟疣,以,0));
dot1=褥矬朦(镟疣,以_桧濑赅,镥痂钿,1,"long");
dot2=褥矬朦(镟疣,以_桧濑赅,镥痂钿,2,"long");
dot3=褥矬朦(镟疣,以_桧濑赅,镥痂钿,3,"long");
if (dot2>=dot3 && dot1>dot2)
{
dot4=褥矬朦(镟疣,以_桧濑赅,镥痂钿,1,"short");
dot5=褥矬朦(镟疣,以_桧濑赅,镥痂钿,2,"short");
dot6=褥矬朦(镟疣,以_桧濑赅,镥痂钿,3,"short");
if (dot6>=dot5 && dot5>=dot4)
{
if (觐>0) lot=sumlot*(((dot1-dot2)*100+1)*觐);
while (IsTradeAllowed()==false) Sleep(0);
n=3;
Ticket=-1;
while (Ticket<0 && n>0)
{
Ticket=OrderSend(镟疣,OP_BUY,NormalizeDouble(lot,2),NormalizeDouble(ask,digits),3,0,0,"铕溴?腩磴 铗 瘥黻?:"+TimeToStr(TimeCurrent(),TIME_MINUTES),magic,0,Blue);
n--;
}
}
}
dot1=褥矬朦(镟疣,以_桧濑赅,镥痂钿,1,"short");
dot2=褥矬朦(镟疣,以_桧濑赅,镥痂钿,2,"short");
dot3=褥矬朦(镟疣,以_桧濑赅,镥痂钿,3,"short");
if (dot2>=dot3 && dot1>dot2)
{
dot4=褥矬朦(镟疣,以_桧濑赅,镥痂钿,1,"long");
dot5=褥矬朦(镟疣,以_桧濑赅,镥痂钿,2,"long");
dot6=褥矬朦(镟疣,以_桧濑赅,镥痂钿,3,"long");
if (dot6>=dot5 && dot5>=dot4)
{
if (觐>0) lot=sumlot*(((dot1-dot2)*100+1)*觐);
while (IsTradeAllowed()==false) Sleep(0);
n=3;
Ticket=-1;
while (Ticket<0 && n>0)
{
Ticket=OrderSend(镟疣,OP_SELL,NormalizeDouble(lot,2),NormalizeDouble(bid,digits),3,0,0,"铕溴?痱 铗 瘥黻?:"+TimeToStr(TimeCurrent(),TIME_MINUTES),magic,0,Red);
n--;
}
}
}
}
}
}
//+------------------------------------------------------------------+
int start()
{
check();
if (怅隷桧纛==true)
{
Display_Info(kol);
DrawStats(kol);
}
if (kol==0)
{
GlobalVariableSet(桎屙蜩翳赅蝾,"_balance",AccountBalance());
if (玎镳弪==false)
{
GlobalVariableSet(桎屙蜩翳赅蝾,镟疣_1+"_time_long",0);
GlobalVariableSet(桎屙蜩翳赅蝾,镟疣_1+"_time_short",0);
GlobalVariableSet(桎屙蜩翳赅蝾,镟疣_1+"_time",0);
GlobalVariableSet(桎屙蜩翳赅蝾,镟疣_2+"_time_long",0);
GlobalVariableSet(桎屙蜩翳赅蝾,镟疣_2+"_time_short",0);
GlobalVariableSet(桎屙蜩翳赅蝾,镟疣_2+"_time",0);
GlobalVariableSet(桎屙蜩翳赅蝾,镟疣_3+"_time_long",0);
GlobalVariableSet(桎屙蜩翳赅蝾,镟疣_3+"_time_short",0);
GlobalVariableSet(桎屙蜩翳赅蝾,镟疣_3+"_time",0);
}
}
if (镟疣_1!="") 篑蜞眍怅(镟疣_1,镳铞屙騙腩騙镟疣_1,以_镟疣_1,_以_镟疣_1,觐_镟疣_1,镥痂钿_镟疣_1);
if (镟疣_2!="") 篑蜞眍怅(镟疣_2,镳铞屙騙腩騙镟疣_2,以_镟疣_2,_以_镟疣_2,觐_镟疣_2,镥痂钿_镟疣_2);
if (镟疣_3!="") 篑蜞眍怅(镟疣_3,镳铞屙騙腩騙镟疣_3,以_镟疣_3,_以_镟疣_3,觐_镟疣_3,镥痂钿_镟疣_3);
if (kol>0)
{
double profit=(value_profit(magic)*100)/GlobalVariableGet(桎屙蜩翳赅蝾,"_balance");
double close_=镳铞屙騙玎牮;
if (profit>=close_)
{
CloseAll(magic);
Sleep(5000);
}
}
return(0);
}
//+------------------------------------------------------------------+
void Display_Info(int k) { // 蔓忸?桧纛痨圉梃 ?筱塍 铌磬
double profit=(value_profit(magic)*100)/AccountBalance();
Comment(
" 彦疴屦: ", AccountServer(),
"\n", " 吗屐 C屦忮疣: ", TimeToStr(TimeCurrent(), TIME_MINUTES), // |TIME_SECONDS
"\n", " 想鬻? ", "1:" + DoubleToStr(AccountLeverage(), 0),
"\n", " 拎豚眈: ", DoubleToStr(AccountBalance(), 2),
"\n", " 佯邃耱忄: ", DoubleToStr(AccountEquity(), 2),
"\n", " 砚钺钿眍: ", DoubleToStr(AccountFreeMargin(), 2),
"\n", " 橡栳? ", DoubleToStr(AccountProfit(), 2),
"\n", " 橡铖噤赅|橡铘栩 % : "+DoubleToStr(profit, 2),
"\n", " 暑腓麇耱忸 铕溴痤? ", DoubleToStr(k, 2),
"\n");
}
//+------------------------------------------------------------------+
string _140 = "lblfin_";
void DrawStats(int k) {
double profit=(value_profit(magic)*100)/AccountBalance();
double ld_0 = GetProfitForDay(0);
string _8 = _140 + "1";
if (ObjectFind(_8) == -1) {
ObjectCreate(_8, OBJ_LABEL, 0, 0, 0);
ObjectSet(_8, OBJPROP_CORNER, 1);
ObjectSet(_8, OBJPROP_XDISTANCE, 10);
ObjectSet(_8, OBJPROP_YDISTANCE, 15);
}
ObjectSetText(_8, "青疣犷蝾?皴泐漤: " + DoubleToStr(ld_0, 2), 12, "Courier New", Red);
ld_0 = GetProfitForDay(1);
_8 = _140 + "2";
if (ObjectFind(_8) == -1) {
ObjectCreate(_8, OBJ_LABEL, 0, 0, 0);
ObjectSet(_8, OBJPROP_CORNER, 1);
ObjectSet(_8, OBJPROP_XDISTANCE, 10);
ObjectSet(_8, OBJPROP_YDISTANCE, 30);
}
ObjectSetText(_8, "青疣犷蝾?怊屦? " + DoubleToStr(ld_0, 2), 12, "Courier New", Red);
ld_0 = GetProfitForDay(2);
_8 = _140 + "3";
if (ObjectFind(_8) == -1) {
ObjectCreate(_8, OBJ_LABEL, 0, 0, 0);
ObjectSet(_8, OBJPROP_CORNER, 1);
ObjectSet(_8, OBJPROP_XDISTANCE, 10);
ObjectSet(_8, OBJPROP_YDISTANCE, 45);
}
ObjectSetText(_8, "青疣犷蝾?镱玎怊屦? " + DoubleToStr(ld_0, 2), 12, "Courier New", Red);
_8 = _140 + "4";
if (ObjectFind(_8) == -1) {
ObjectCreate(_8, OBJ_LABEL, 0, 0, 0);
ObjectSet(_8, OBJPROP_CORNER, 1);
ObjectSet(_8, OBJPROP_XDISTANCE, 10);
ObjectSet(_8, OBJPROP_YDISTANCE, 75);
}
ObjectSetText(_8, "拎豚眈: " + DoubleToStr(AccountBalance(), 2), 14, "Courier New", Red);
_8 = _140 + "5";
if (ObjectFind(_8) == -1) {
ObjectCreate(_8, OBJ_LABEL, 0, 0, 0);
ObjectSet(_8, OBJPROP_CORNER, 1);
ObjectSet(_8, OBJPROP_XDISTANCE, 10);
ObjectSet(_8, OBJPROP_YDISTANCE, 105);
}
ObjectSetText(_8, "橡铖噤赅: " + DoubleToStr(profit, 2), 14, "Courier New", Red);
_8 = _140 + "6";
if (ObjectFind(_8) == -1) {
ObjectCreate(_8, OBJ_LABEL, 0, 0, 0);
ObjectSet(_8, OBJPROP_CORNER, 1);
ObjectSet(_8, OBJPROP_XDISTANCE, 10);
ObjectSet(_8, OBJPROP_YDISTANCE, 135);
}
ObjectSetText(_8, "暑腓麇耱忸 铕溴痤? " + DoubleToStr(k, 2), 14, "Courier New", Red);
}
double GetProfitForDay(int ai_0) {
double ld_ret_4 = 0;
for (int l_pos_12 = 0; l_pos_12 < OrdersHistoryTotal(); l_pos_12++) {
if (!(OrderSelect(l_pos_12, SELECT_BY_POS, MODE_HISTORY))) break;
if (OrderCloseTime() >= iTime(Symbol(), PERIOD_D1, ai_0) && OrderCloseTime() < iTime(Symbol(), PERIOD_D1, ai_0) + 86400) ld_ret_4 += OrderProfit() + OrderSwap() + OrderCommission();
}
return (ld_ret_4);
}
//+------------------------------------------------------------------+