-
Notifications
You must be signed in to change notification settings - Fork 1
/
EnigmaG12~.mq4
1078 lines (1052 loc) · 37.8 KB
/
EnigmaG12~.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
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
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
Website: http://purebeam.biz
E-mail : [email protected]
*/
#import "EnigmaG12Core.dll"
int Initialize(string a0, int a1, int a2, string a3, int a4);
int GetSettings(string a0, int& a1[], int& a2[], int& a3[], int& a4[], int& a5[], int& a6[], int& a7[], int& a8[], int& a9[], int& a10[], int& a11[], int& a12[], int& a13[], int& a14[], int& a15[], int& a16[], double& a17[], double& a18[], double& a19[], double& a20[], double& a21[], double& a22[], int& a23[], int& a24[]);
void GetVersionInfo(int& a0[], int& a1[], int& a2[], int& a3[]);
#import
bool gi_76 = FALSE;
bool gi_80 = FALSE;
int gi_84 = 0;
int gi_88 = -1;
int gi_92 = -1;
int gi_96 = -1;
int gi_100 = -1;
extern double mmRisk = 0.05;
extern bool hedgingWorkaround = FALSE;
int gi_116 = 0;
int gi_120 = 0;
int gi_124 = 0;
int gi_128 = 0;
int gi_132 = 0;
int gi_136 = 0;
int gi_140 = 0;
int gi_144 = 0;
int gi_148 = 0;
int gi_152 = 0;
int gi_156 = 0;
int gi_160 = 0;
int gi_164 = 0;
int gi_168 = 0;
int gi_172 = 0;
int gi_176 = 0;
double gd_180 = 0.0;
double gd_188 = 0.0;
double gd_196 = 0.0;
double gd_204 = 0.0;
double gd_212 = 0.0;
double gd_220 = 0.0;
int gi_228 = 0;
double gda_232[5];
int gi_236 = 0;
int gia_240[6] = {0, 0, 20, 40, 60, 80};
int gi_244 = 0;
int g_cmd_248 = -1;
int gi_unused_252 = -1;
bool gi_256 = FALSE;
bool gi_260 = FALSE;
double g_ihigh_264 = 0.0;
double g_ilow_272 = 200.0;
double g_price_280 = 0.0;
double g_price_288 = 200.0;
int gi_296 = 0;
int gi_300 = 0;
bool gi_304 = TRUE;
bool gi_308 = TRUE;
double g_ihigh_312 = 0.0;
double g_ilow_320 = 200.0;
int g_datetime_328 = 0;
int g_datetime_332 = 0;
bool gi_336 = TRUE;
bool gi_340 = TRUE;
bool gi_344 = FALSE;
bool gi_348 = FALSE;
int gi_352 = 0;
double gd_356 = 0.0;
bool gi_364 = FALSE;
int g_hour_368 = -1;
bool isDayBlacklisted(int ai_unused_0) {
return (FALSE);
}
void validateInputParameters() {
if (gi_116 < 0 || gi_116 > 24 || gi_120 < 0 || gi_120 > 24 || gi_124 < 0 || gi_124 > 24) {
gi_256 = FALSE;
return;
}
int li_0 = 60 * gi_116;
int li_4 = 60 * gi_120;
if (li_4 < li_0) {
gi_256 = FALSE;
return;
}
if (MathAbs(gi_136) > 50.0 || MathAbs(gi_132) > 50.0) gi_256 = FALSE;
if (gi_140 != 1 && gi_140 != 2 && gi_140 != 3) gi_256 = FALSE;
if (MathAbs(gi_144) > 50.0 || MathAbs(gi_148) > 50.0 || MathAbs(gi_152) > 50.0 || MathAbs(gi_156) > 50.0 || MathAbs(gi_160) > 50.0 || MathAbs(gi_164) > 50.0) gi_256 = FALSE;
if (gi_168 != 1) gi_256 = FALSE;
if (MathAbs(gi_172) > 150.0) gi_256 = FALSE;
gi_256 = TRUE;
}
void analyzeYesterday() {
analyzeYesterdayHourly();
}
void analyzeToday() {
double l_ihigh_0;
double l_ilow_8;
int l_datetime_16 = iTime(Symbol(), PERIOD_D1, 0);
int li_20 = 0;
int l_datetime_24 = iTime(Symbol(), PERIOD_H1, li_20);
g_ihigh_312 = 0.0;
g_ilow_320 = 300.0;
while (l_datetime_24 >= l_datetime_16) {
l_ihigh_0 = iHigh(Symbol(), PERIOD_H1, li_20);
l_ilow_8 = iLow(Symbol(), PERIOD_H1, li_20);
if (l_ihigh_0 > g_ihigh_312) g_ihigh_312 = l_ihigh_0;
if (l_ilow_8 < g_ilow_320) g_ilow_320 = l_ilow_8;
li_20++;
l_datetime_24 = iTime(Symbol(), PERIOD_H1, li_20);
}
}
void analyzeYesterdayHourly() {
double l_ihigh_0;
double l_ilow_8;
bool li_16 = FALSE;
if (TimeHour(TimeCurrent()) >= 24 - gi_84 && TimeDayOfWeek(TimeCurrent()) != 0) li_16 = TRUE;
int l_datetime_20 = iTime(Symbol(), PERIOD_D1, 0);
int li_24 = l_datetime_20 - 3600 * gi_84;
if (li_16) li_24 += 86400;
int l_datetime_28 = iTime(Symbol(), PERIOD_D1, 1);
int li_32 = l_datetime_28 - 3600 * gi_84;
if (li_16) li_32 += 86400;
if (StringFind(AccountCompany(), "Alpari") == -1) {
if (TimeDayOfWeek(li_24) == 0 || TimeDayOfWeek(li_24) == 1) {
if (TimeDayOfWeek(li_32) == 0 || TimeDayOfWeek(li_32) == 6) {
l_datetime_28 = iTime(Symbol(), PERIOD_D1, 2);
li_32 = l_datetime_28 - 3600 * gi_84;
if (li_16) li_32 += 86400;
}
}
}
g_ihigh_264 = 0.0;
g_ilow_272 = 300.0;
int li_36 = gi_84 + 73;
int l_datetime_40 = 0;
while (true) {
l_datetime_40 = iTime(Symbol(), PERIOD_H1, li_36);
if (l_datetime_40 >= li_32) break;
li_36--;
if (li_36 > 0) continue;
break;
}
int li_44 = l_datetime_40 + 3600 * gi_116;
int li_48 = l_datetime_40 + 3600 * gi_120;
if (li_36 > 0) {
}
int li_52 = 0;
int li_56 = 0;
while (true) {
l_datetime_40 = iTime(Symbol(), PERIOD_H1, li_36);
if (l_datetime_40 >= li_24) break;
l_ihigh_0 = iHigh(Symbol(), PERIOD_H1, li_36);
l_ilow_8 = iLow(Symbol(), PERIOD_H1, li_36);
if (l_ihigh_0 >= g_ihigh_264) {
g_ihigh_264 = l_ihigh_0;
li_52 = l_datetime_40;
}
if (l_ilow_8 <= g_ilow_272) {
g_ilow_272 = l_ilow_8;
li_56 = l_datetime_40;
}
li_36--;
}
double ld_60 = 0.0001;
if (StringFind(Symbol(), "JPY") != -1) ld_60 = 0.01;
g_ihigh_264 = NormalizeDouble(g_ihigh_264, 4);
g_ilow_272 = NormalizeDouble(g_ilow_272, 4);
g_price_280 = NormalizeDouble(g_ihigh_264 + gi_132 * ld_60, 4);
g_price_288 = NormalizeDouble(g_ilow_272 + gi_136 * ld_60, 4);
if (li_52 < li_44 || li_52 >= li_48) gi_304 = TRUE;
else gi_304 = FALSE;
if (li_56 < li_44 || li_56 >= li_48) gi_308 = TRUE;
else gi_308 = FALSE;
gi_296 = li_52;
gi_300 = li_56;
int li_68 = gi_296 + 3600 * gi_124;
int li_72 = gi_300 + 3600 * gi_124;
if (ObjectFind("sellRange") != 0) {
ObjectCreate("sellRange", OBJ_RECTANGLE, 0, MathMax(li_68, l_datetime_40), g_price_280, l_datetime_40 + 86400, g_price_280 + ld_60 * gia_240[gi_228]);
ObjectSet("sellRange", OBJPROP_COLOR, LightBlue);
} else {
ObjectSet("sellRange", OBJPROP_TIME1, MathMax(li_68, l_datetime_40));
ObjectSet("sellRange", OBJPROP_PRICE1, g_price_280);
ObjectSet("sellRange", OBJPROP_TIME2, l_datetime_40 + 86400);
ObjectSet("sellRange", OBJPROP_PRICE2, g_price_280 + ld_60 * gia_240[gi_228]);
ObjectSet("sellRange", OBJPROP_COLOR, LightBlue);
}
if (ObjectFind("buyRange") != 0) {
ObjectCreate("buyRange", OBJ_RECTANGLE, 0, MathMax(li_72, l_datetime_40), g_price_288, l_datetime_40 + 86400, g_price_288 - ld_60 * gia_240[gi_228]);
ObjectSet("buyRange", OBJPROP_COLOR, LightGreen);
return;
}
ObjectSet("buyRange", OBJPROP_TIME1, MathMax(li_72, l_datetime_40));
ObjectSet("buyRange", OBJPROP_PRICE1, g_price_288);
ObjectSet("buyRange", OBJPROP_TIME2, l_datetime_40 + 86400);
ObjectSet("buyRange", OBJPROP_PRICE2, g_price_288 - ld_60 * gia_240[gi_228]);
ObjectSet("buyRange", OBJPROP_COLOR, LightGreen);
}
void validateYesterdayValues() {
if (g_ilow_272 > 0.0 && g_ihigh_264 > g_ilow_272) {
gi_260 = TRUE;
return;
}
gi_260 = FALSE;
}
int isOurMagicNumber(int ai_0) {
if (ai_0 == 12121212 || ai_0 == 12121213 || ai_0 == 12121214 || ai_0 == 12121215 || ai_0 == 12121216) return (1);
return (0);
}
void initState() {
double ld_0;
double ld_8;
int li_unused_16 = 0;
int li_unused_20 = 0;
bool li_24 = FALSE;
bool li_28 = FALSE;
int l_ord_total_32 = OrdersTotal();
for (int l_pos_36 = 0; l_pos_36 < l_ord_total_32; l_pos_36++) {
if (OrderSelect(l_pos_36, SELECT_BY_POS, MODE_TRADES)) {
if (isOurMagicNumber(OrderMagicNumber()) && OrderSymbol() == Symbol()) {
if (OrderType() == OP_SELL) li_24 = TRUE;
else {
if (OrderType() == OP_BUY) li_28 = TRUE;
else {
if (OrderType() == OP_SELLLIMIT) li_unused_16 = 1;
else
if (OrderType() == OP_BUYLIMIT) li_unused_20 = 1;
}
}
}
}
}
validateInputParameters();
if (gi_256 == FALSE) {
gi_244 = 1;
return;
}
analyzeYesterday();
validateYesterdayValues();
if (gi_260) {
analyzeToday();
if (g_ihigh_312 > g_ihigh_264 || gi_304) gi_336 = FALSE;
if (g_ilow_320 < g_ilow_272 || gi_308) gi_340 = FALSE;
ld_0 = 10000.0;
if (StringFind(Symbol(), "JPY") != -1) ld_0 = 100.0;
ld_8 = MathAbs(g_ihigh_264 - g_ilow_272) * ld_0;
if (ld_8 < gi_128) {
gi_340 = FALSE;
gi_336 = FALSE;
}
if (li_24 || li_28) {
gi_244 = 4;
if (li_24) {
g_cmd_248 = TRUE;
return;
}
g_cmd_248 = FALSE;
return;
}
if (gi_336 || gi_340 && !isDayBlacklisted(TimeCurrent())) {
gi_244 = 3;
return;
}
closePositions();
gi_244 = 5;
return;
}
closePositions();
gi_244 = 2;
}
void closePositions() {
int l_ord_total_0;
int l_pos_4;
bool li_8 = FALSE;
int l_count_12 = 0;
for (l_count_12 = 0; l_count_12 < 30; l_count_12++) {
if (IsTradeContextBusy()) Sleep(1000);
else {
li_8 = TRUE;
break;
}
}
if (li_8) {
l_ord_total_0 = OrdersTotal();
l_count_12 = 0;
l_pos_4 = 0;
for (l_count_12 = 0; l_count_12 < l_ord_total_0; l_count_12++) {
if (OrderSelect(l_pos_4, SELECT_BY_POS)) {
if (OrderSymbol() == Symbol() && isOurMagicNumber(OrderMagicNumber())) {
if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 0);
else {
if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 0);
else {
if (OrderType() == OP_BUYLIMIT || OrderType() == OP_SELLLIMIT) OrderDelete(OrderTicket());
else l_pos_4++;
}
}
} else l_pos_4++;
} else l_pos_4++;
}
}
}
void deleteAllPending(int a_cmd_0) {
int l_ord_total_4 = OrdersTotal();
int l_count_8 = 0;
int l_pos_12 = 0;
for (l_count_8 = 0; l_count_8 < l_ord_total_4; l_count_8++) {
if (OrderSelect(l_pos_12, SELECT_BY_POS)) {
if (OrderType() == a_cmd_0 && OrderSymbol() == Symbol() && isOurMagicNumber(OrderMagicNumber()) && OrderMagicNumber() != 12121212) OrderDelete(OrderTicket());
else l_pos_12++;
}
}
}
void computeOrderVolumes() {
int li_0;
double ld_4;
double ld_12;
double ld_20;
double ld_28;
double ld_36;
double ld_44;
if (gi_176 == 1) {
gda_232[0] = NormalizeDouble(gd_180, 1);
gda_232[1] = NormalizeDouble(gd_188, 1);
gda_232[2] = NormalizeDouble(gd_196, 1);
gda_232[3] = NormalizeDouble(gd_204, 1);
gda_232[4] = NormalizeDouble(gd_212, 1);
return;
}
if (gi_176 == 2) {
li_0 = 0;
if (gi_228 >= 1) li_0 += gi_172;
if (gi_228 >= 2) li_0 += gi_172 - 20;
if (gi_228 >= 3) li_0 += gi_172 - 40;
if (gi_228 >= 4) li_0 += gi_172 - 60;
if (gi_228 >= 5) li_0 += gi_172 - 80;
ld_4 = mmRisk * AccountBalance();
ld_12 = 0.0;
if (MarketInfo(Symbol(), MODE_MINLOT) < 0.1) ld_12 = NormalizeDouble(ld_4 / (li_0 * MarketInfo(Symbol(), MODE_LOTSIZE) / 100000.0) / 10.0, 2);
else ld_12 = NormalizeDouble(ld_4 / (li_0 * MarketInfo(Symbol(), MODE_LOTSIZE) / 100000.0) / 10.0, 1);
ld_12 = MathMax(ld_12, MarketInfo(Symbol(), MODE_MINLOT));
gda_232[0] = ld_12;
gda_232[1] = ld_12;
gda_232[2] = ld_12;
gda_232[3] = ld_12;
gda_232[4] = ld_12;
Print("mmMode: 2, orderSize: " + ld_12);
return;
}
if (gi_176 == 3) {
li_0 = 0;
if (gi_228 >= 1) li_0 += gi_172;
if (gi_228 >= 2) li_0 += gi_172 - 20;
if (gi_228 >= 3) li_0 += gi_172 - 40;
if (gi_228 >= 4) li_0 += gi_172 - 60;
if (gi_228 >= 5) li_0 += gi_172 - 80;
ld_4 = mmRisk * AccountBalance();
gd_220 = 10.0 * gd_220;
ld_20 = 0.0;
ld_20 = ld_4;
Print("mmRisk: " + ld_4);
ld_28 = 0.0;
for (int li_52 = 1; li_52 < gi_228; li_52++) ld_28 += li_52 * (gia_240[li_52 + 1]);
ld_28 *= gd_220;
Print("f2: " + ld_28);
ld_20 += ld_28;
ld_36 = 0.0;
for (li_52 = 1; li_52 < gi_228; li_52++) ld_36 += li_52;
ld_36 *= gi_172 * gd_220;
Print("f3: " + ld_36);
ld_20 -= ld_36;
ld_44 = 0.0;
for (li_52 = 1; li_52 <= gi_228; li_52++) ld_44 += gia_240[li_52];
Print("f4: " + ld_44);
ld_20 /= (gi_172 * gi_228 - ld_44);
ld_20 = NormalizeDouble(ld_20 / 10.0, 1);
Print("X: " + ld_20);
gd_220 /= 10.0;
gda_232[0] = ld_20;
for (li_52 = 1; li_52 < gi_228; li_52++) gda_232[li_52] = ld_20 + li_52 * gd_220;
} else {
if (gi_176 == 4) {
li_0 = 0;
if (gi_228 >= 1) li_0 += gi_172;
if (gi_228 >= 2) li_0 += gi_172 - 20;
if (gi_228 >= 3) li_0 += gi_172 - 40;
if (gi_228 >= 4) li_0 += gi_172 - 60;
if (gi_228 >= 5) li_0 += gi_172 - 80;
ld_4 = mmRisk * AccountBalance();
ld_20 = 0.0;
ld_20 = ld_4;
Print("mmRisk: " + ld_4);
ld_28 = 0.0;
for (li_52 = 1; li_52 <= gi_228; li_52++) ld_28 += MathPow(gd_220, li_52 - 1);
ld_28 *= gi_172;
Print("f2: " + ld_28);
ld_36 = 0.0;
for (li_52 = 1; li_52 < gi_228; li_52++) ld_36 += (gia_240[li_52 + 1]) * MathPow(gd_220, li_52);
Print("f3: " + ld_36);
ld_20 /= (ld_28 - ld_36);
ld_20 = NormalizeDouble(ld_20 / 10.0, 1);
Print("X: " + ld_20);
gda_232[0] = ld_20;
for (li_52 = 1; li_52 < gi_228; li_52++) gda_232[li_52] = NormalizeDouble(ld_20 * MathPow(gd_220, li_52), 1);
}
}
}
void updateOrders() {
bool li_0 = FALSE;
bool li_4 = FALSE;
bool li_8 = FALSE;
bool li_12 = FALSE;
double l_price_16 = 0.0;
double l_price_24 = 0.0;
double ld_32 = 1.0;
int l_ord_total_40 = OrdersTotal();
int l_pos_44 = 0;
for (l_pos_44 = 0; l_pos_44 < l_ord_total_40; l_pos_44++) {
if (OrderSelect(l_pos_44, SELECT_BY_POS)) {
if (OrderSymbol() == Symbol() && OrderMagicNumber() == 12121212) {
if (OrderType() == OP_BUYLIMIT) {
if (gi_340 && TimeCurrent() >= gi_300 + 3600 * gi_124) {
ld_32 = 0.0001;
if (StringFind(Symbol(), "JPY") != -1) ld_32 = 0.01;
li_8 = TRUE;
if (MathAbs(OrderOpenPrice() - g_price_288) >= ld_32) {
l_price_16 = g_price_288 - gi_172 * ld_32;
if (gi_140 == 1 || gi_140 == 3) l_price_24 = g_price_288 + gi_144 * ld_32;
else l_price_24 = g_price_288 + gi_148 * ld_32;
if (OrderModify(OrderTicket(), g_price_288, l_price_16, l_price_24, 0)) li_12 = TRUE;
}
} else {
OrderDelete(OrderTicket());
li_8 = FALSE;
}
} else {
if (OrderType() == OP_SELLLIMIT && gi_336) {
if (gi_336 && TimeCurrent() >= gi_296 + 3600 * gi_124) {
ld_32 = 0.0001;
if (StringFind(Symbol(), "JPY") != -1) ld_32 = 0.01;
li_0 = TRUE;
if (MathAbs(OrderOpenPrice() - g_price_280) >= ld_32) {
l_price_16 = g_price_280 + gi_172 * ld_32;
if (gi_140 == 1 || gi_140 == 3) l_price_24 = g_price_280 - gi_144 * ld_32;
else l_price_24 = g_price_280 - gi_148 * ld_32;
if (OrderModify(OrderTicket(), g_price_280, l_price_16, l_price_24, 0)) li_4 = TRUE;
}
} else {
OrderDelete(OrderTicket());
li_0 = FALSE;
}
}
}
}
}
}
if (li_12 || !(gi_340 && TimeCurrent() >= gi_300 + 3600 * gi_124)) deleteAllPending(OP_BUYLIMIT);
if (li_4 || !(gi_336 && TimeCurrent() >= gi_296 + 3600 * gi_124)) deleteAllPending(OP_SELLLIMIT);
ld_32 = 0.0001;
if (StringFind(Symbol(), "JPY") != -1) ld_32 = 0.01;
bool li_48 = FALSE;
bool li_52 = TRUE;
bool li_56 = TRUE;
if (!li_0 && gi_336 && TimeCurrent() >= gi_296 + 3600 * gi_124) {
computeOrderVolumes();
li_48 = TRUE;
l_price_16 = g_price_280 + gi_172 * ld_32;
if (gi_140 == 1 || gi_140 == 3) l_price_24 = g_price_280 - gi_144 * ld_32;
else l_price_24 = g_price_280 - gi_148 * ld_32;
if (g_price_280 - MarketInfo(Symbol(), MODE_BID) < 10.0 * ld_32) li_52 = FALSE;
if (li_52) {
if (OrderSend(Symbol(), OP_SELLLIMIT, gda_232[0], g_price_280, 0, l_price_16, l_price_24, "EnigmaG12Sell", 12121212) < 0) {
Print("OrderSend failed with error: ", GetLastError());
Print("Parameters: " + 3 + "," + gda_232[0] + "," + g_price_280 + ",0," + l_price_16 + "," + l_price_24 + "EnigmaG12Sell," + 12121212);
li_52 = FALSE;
}
}
}
if (li_4 || !li_0 && gi_336 && TimeCurrent() >= gi_296 + 3600 * gi_124) {
if (!li_48) {
computeOrderVolumes();
li_48 = TRUE;
}
l_price_16 = g_price_280 + gi_172 * ld_32;
if (gi_140 == 1 || gi_140 == 3) l_price_24 = g_price_280 - gi_144 * ld_32;
else l_price_24 = g_price_280 - gi_148 * ld_32;
if (li_52 && gi_228 >= 2)
if (OrderSend(Symbol(), OP_SELLLIMIT, gda_232[1], g_price_280 + gia_240[2] * ld_32, 0, l_price_16, l_price_24, "EnigmaG12Sell", 12121213) < 0) li_52 = FALSE;
if (li_52 && gi_228 >= 3)
if (OrderSend(Symbol(), OP_SELLLIMIT, gda_232[2], g_price_280 + gia_240[3] * ld_32, 0, l_price_16, l_price_24, "EnigmaG12Sell", 12121214) < 0) li_52 = FALSE;
if (li_52 && gi_228 >= 4)
if (OrderSend(Symbol(), OP_SELLLIMIT, gda_232[3], g_price_280 + gia_240[4] * ld_32, 0, l_price_16, l_price_24, "EnigmaG12Sell", 12121215) < 0) li_52 = FALSE;
if (li_52 && gi_228 >= 5)
if (OrderSend(Symbol(), OP_SELLLIMIT, gda_232[4], g_price_280 + gia_240[5] * ld_32, 0, l_price_16, l_price_24, "EnigmaG12Sell", 12121216) < 0) li_52 = FALSE;
}
if (!li_8 && gi_340 && TimeCurrent() >= gi_300 + 3600 * gi_124) {
if (!li_48) {
computeOrderVolumes();
li_48 = TRUE;
}
l_price_16 = g_price_288 - gi_172 * ld_32;
if (gi_140 == 1 || gi_140 == 3) l_price_24 = g_price_288 + gi_144 * ld_32;
else l_price_24 = g_price_288 + gi_148 * ld_32;
if (MarketInfo(Symbol(), MODE_ASK) - g_price_288 < 10.0 * ld_32) li_56 = FALSE;
if (li_56) {
if (OrderSend(Symbol(), OP_BUYLIMIT, gda_232[0], g_price_288, 0, l_price_16, l_price_24, "EnigmaG12Buy", 12121212) < 0) {
Print("OrderSend failed with error: ", GetLastError());
Print("Parameters: " + 2 + "," + gda_232[0] + "," + g_price_288 + ",0," + l_price_16 + "," + l_price_24 + "EnigmaG12Buy," + 12121212);
li_56 = FALSE;
}
}
}
if (li_12 || !li_8 && gi_340 && TimeCurrent() >= gi_300 + 3600 * gi_124) {
if (!li_48) {
computeOrderVolumes();
li_48 = TRUE;
}
l_price_16 = g_price_288 - gi_172 * ld_32;
if (gi_140 == 1 || gi_140 == 3) l_price_24 = g_price_288 + gi_144 * ld_32;
else l_price_24 = g_price_288 + gi_148 * ld_32;
if (li_56 && gi_228 >= 2)
if (OrderSend(Symbol(), OP_BUYLIMIT, gda_232[1], g_price_288 - gia_240[2] * ld_32, 0, l_price_16, l_price_24, "EnigmaG12Buy", 12121213) < 0) li_56 = FALSE;
if (li_56 && gi_228 >= 3)
if (OrderSend(Symbol(), OP_BUYLIMIT, gda_232[2], g_price_288 - gia_240[3] * ld_32, 0, l_price_16, l_price_24, "EnigmaG12Buy", 12121214) < 0) li_56 = FALSE;
if (li_56 && gi_228 >= 4)
if (OrderSend(Symbol(), OP_BUYLIMIT, gda_232[3], g_price_288 - gia_240[4] * ld_32, 0, l_price_16, l_price_24, "EnigmaG12Buy", 12121215) < 0) li_56 = FALSE;
if (li_56 && gi_228 >= 5)
if (OrderSend(Symbol(), OP_BUYLIMIT, gda_232[4], g_price_288 - gia_240[5] * ld_32, 0, l_price_16, l_price_24, "EnigmaG12Buy", 12121216) < 0) li_56 = FALSE;
}
}
void updateOrderTPs(int ai_0) {
double ld_4;
double ld_12;
double l_ord_open_price_20;
double ld_28;
int li_36;
int l_ord_total_40 = OrdersTotal();
int l_pos_44 = 0;
double l_price_48 = 0.0;
double ld_56 = 0.0001;
if (StringFind(Symbol(), "JPY") != -1) ld_56 = 0.01;
if (ai_0 == 1) {
for (l_pos_44 = 0; l_pos_44 < l_ord_total_40; l_pos_44++) {
if (OrderSelect(l_pos_44, SELECT_BY_POS)) {
if (OrderSymbol() == Symbol() && OrderMagicNumber() == 12121212) {
if (g_cmd_248 == OP_BUY && OrderType() == OP_BUY) {
if (gi_140 == 1) l_price_48 = OrderOpenPrice() + gi_144 * ld_56;
else {
if (gi_140 == 2) l_price_48 = OrderOpenPrice() + gi_148 * ld_56;
else
if (gi_140 == 3) l_price_48 = OrderOpenPrice() + gi_144 * ld_56;
}
Print("updateOrderTPs OrderModify");
OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), l_price_48, OrderExpiration());
gd_356 = OrderOpenPrice();
return;
}
if (g_cmd_248 == OP_SELL && OrderType() == OP_SELL) {
if (gi_140 == 1) l_price_48 = OrderOpenPrice() - gi_144 * ld_56;
else {
if (gi_140 == 2) l_price_48 = OrderOpenPrice() - gi_148 * ld_56;
else
if (gi_140 == 3) l_price_48 = OrderOpenPrice() - gi_144 * ld_56;
}
Print("updateOrderTPs OrderModify");
OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), l_price_48, OrderExpiration());
gd_356 = OrderOpenPrice();
return;
}
}
}
}
} else {
ld_4 = 0;
ld_12 = 0.0;
gd_356 = 0.0;
for (l_pos_44 = 0; l_pos_44 < l_ord_total_40; l_pos_44++) {
if (OrderSelect(l_pos_44, SELECT_BY_POS)) {
if (OrderSymbol() == Symbol() && isOurMagicNumber(OrderMagicNumber())) {
if (g_cmd_248 == OP_BUY && OrderType() == OP_BUY) {
gd_356 += OrderOpenPrice() * OrderLots();
ld_12 += OrderLots();
ld_4++;
} else {
if (g_cmd_248 == OP_SELL && OrderType() == OP_SELL) {
gd_356 += OrderOpenPrice() * OrderLots();
ld_12 += OrderLots();
ld_4++;
}
}
}
}
}
gd_356 = NormalizeDouble(gd_356 / ld_12, 4);
Print("avg price: " + gd_356);
l_ord_open_price_20 = 0.0;
if (gi_140 == 3) {
for (l_pos_44 = 0; l_pos_44 < l_ord_total_40; l_pos_44++) {
if (OrderSelect(l_pos_44, SELECT_BY_POS)) {
if (OrderSymbol() == Symbol() && OrderMagicNumber() == 12121212 && OrderType() == g_cmd_248) {
if (g_cmd_248 == OP_BUY && OrderType() == OP_BUY) {
l_ord_open_price_20 = OrderOpenPrice();
break;
}
if (g_cmd_248 == OP_SELL && OrderType() == OP_SELL) {
l_ord_open_price_20 = OrderOpenPrice();
break;
}
}
}
}
}
for (l_pos_44 = 0; l_pos_44 < l_ord_total_40; l_pos_44++) {
if (OrderSelect(l_pos_44, SELECT_BY_POS)) {
if (OrderSymbol() == Symbol() && isOurMagicNumber(OrderMagicNumber())) {
ld_28 = gi_148;
if (OrderMagicNumber() == 12121212) ld_28 = gi_148;
else {
if (OrderMagicNumber() == 12121213) ld_28 = gi_152;
else {
if (OrderMagicNumber() == 12121214) ld_28 = gi_156;
else {
if (OrderMagicNumber() == 12121215) ld_28 = gi_160;
else
if (OrderMagicNumber() == 12121216) ld_28 = gi_164;
}
}
}
li_36 = -1;
if (g_cmd_248 == OP_BUY && OrderType() == OP_BUY) {
li_36 = 0;
if (gi_140 == 1) l_price_48 = gd_356 + gi_144 * ld_56;
else {
if (gi_140 == 2) l_price_48 = OrderOpenPrice() + ld_28 * ld_56;
else
if (gi_140 == 3) l_price_48 = l_ord_open_price_20 + gi_144 * ld_56;
}
} else {
if (g_cmd_248 == OP_SELL && OrderType() == OP_SELL) {
li_36 = 1;
if (gi_140 == 1) l_price_48 = gd_356 - gi_144 * ld_56;
else {
if (gi_140 == 2) l_price_48 = OrderOpenPrice() - ld_28 * ld_56;
else
if (gi_140 == 3) l_price_48 = l_ord_open_price_20 - gi_144 * ld_56;
}
} else {
li_36 = -1;
l_price_48 = OrderTakeProfit();
continue;
}
}
if (li_36 != -1) {
Print("updateOrderTPs OrderModify");
OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), l_price_48, OrderExpiration());
}
}
}
}
}
}
int getOpenPosition() {
int l_ord_total_0 = OrdersTotal();
int l_pos_4 = 0;
for (l_pos_4 = 0; l_pos_4 < l_ord_total_0; l_pos_4++) {
if (OrderSelect(l_pos_4, SELECT_BY_POS)) {
if (OrderSymbol() == Symbol() && OrderMagicNumber() == 12121212) {
if (OrderType() == OP_BUY) return (0);
if (OrderType() == OP_SELL) return (1);
}
}
}
return (-1);
}
int getPositionCount() {
int l_count_0 = 0;
int l_ord_total_4 = OrdersTotal();
int l_pos_8 = 0;
for (l_pos_8 = 0; l_pos_8 < l_ord_total_4; l_pos_8++) {
if (OrderSelect(l_pos_8, SELECT_BY_POS)) {
if (OrderSymbol() == Symbol() && isOurMagicNumber(OrderMagicNumber())) {
if (g_cmd_248 == OP_BUY && OrderType() == OP_BUY) l_count_0++;
else
if (g_cmd_248 == OP_SELL && OrderType() == OP_SELL) l_count_0++;
}
}
}
return (l_count_0);
}
int isWeekStart() {
if (TimeDayOfWeek(TimeCurrent()) == 0 || (TimeDayOfWeek(TimeCurrent()) == 1 && TimeHour(TimeCurrent()) <= 10)) return (1);
return (0);
}
int isOtherEAInTrade() {
int l_ord_total_0 = OrdersTotal();
int l_pos_4 = 0;
for (l_pos_4 = 0; l_pos_4 < l_ord_total_0; l_pos_4++) {
if (OrderSelect(l_pos_4, SELECT_BY_POS)) {
if (OrderSymbol() != Symbol() && isOurMagicNumber(OrderMagicNumber()))
if (OrderType() == OP_BUY || OrderType() == OP_SELL) return (1);
}
}
return (0);
}
void updateState() {
double ld_0;
int li_8;
bool li_12;
double ld_16;
int li_24;
int li_28;
int li_32;
bool li_36 = FALSE;
if (g_datetime_328 != 0 && TimeDayOfYear(g_datetime_332 + 3600 * gi_84) > TimeDayOfYear(g_datetime_328 + 3600 * gi_84) || (TimeDayOfYear(g_datetime_332 + 3600 * gi_84) == 1 &&
TimeDayOfYear(g_datetime_328 + 3600 * gi_84) >= 365)) {
li_36 = TRUE;
gi_340 = TRUE;
gi_336 = TRUE;
findFridayData();
}
if (g_hour_368 != -1 && TimeDayOfWeek(TimeCurrent()) == 5 && TimeHour(TimeCurrent()) >= g_hour_368 - 1) {
Print("Closing positions due to Friday market close.");
closePositions();
gi_244 = 5;
}
double ld_40 = -1.0;
if (li_36) {
analyzeYesterday();
validateYesterdayValues();
ld_0 = 10000.0;
if (StringFind(Symbol(), "JPY") != -1) ld_0 = 100.0;
ld_40 = MathAbs(g_ihigh_264 - g_ilow_272) * ld_0;
}
if (gi_244 == 3) {
if (!gi_340 && !gi_336 && !gi_348 && !gi_344) {
closePositions();
gi_244 = 5;
return;
}
li_8 = getOpenPosition();
if (li_8 != -1) {
g_cmd_248 = li_8;
gi_244 = 4;
return;
}
li_12 = isOtherEAInTrade();
if (li_12) {
Print("Blocked due to another instance trading.");
closePositions();
gi_244 = 6;
return;
}
if (li_36 || gi_364) {
if (gi_364) gi_364 = FALSE;
if (gi_260 == FALSE) {
gi_244 = 2;
return;
}
if (ld_40 < gi_128) {
gi_336 = FALSE;
gi_340 = FALSE;
closePositions();
gi_244 = 5;
return;
}
if (gi_304) gi_336 = FALSE;
else
if (!isDayBlacklisted(g_datetime_332)) gi_336 = TRUE;
if (gi_308) gi_340 = FALSE;
else
if (!isDayBlacklisted(g_datetime_332)) gi_340 = TRUE;
}
if (gi_336 && isWeekStart()) {
gi_336 = FALSE;
gi_344 = TRUE;
} else {
if (!isWeekStart() && gi_344) {
gi_336 = TRUE;
gi_344 = FALSE;
}
}
if (gi_340 && isWeekStart()) {
gi_340 = FALSE;
gi_348 = TRUE;
} else {
if (!isWeekStart() && gi_348) {
gi_340 = TRUE;
gi_348 = FALSE;
}
}
if (MarketInfo(Symbol(), MODE_BID) > g_ihigh_264 && gi_336 || gi_344 && TimeCurrent() < gi_296 + 3600 * gi_124) {
gi_336 = FALSE;
gi_344 = FALSE;
} else {
if (MarketInfo(Symbol(), MODE_BID) > g_ihigh_264 && gi_336 || gi_344 && getOpenPosition() == -1) {
gi_336 = FALSE;
gi_344 = FALSE;
}
}
if (MarketInfo(Symbol(), MODE_ASK) < g_ilow_272 && gi_340 || gi_348 && TimeCurrent() < gi_300 + 3600 * gi_124) {
gi_340 = FALSE;
gi_348 = FALSE;
} else {
if (MarketInfo(Symbol(), MODE_ASK) < g_ilow_272 && gi_340 || gi_348 && getOpenPosition() == -1) {
gi_340 = FALSE;
gi_348 = FALSE;
}
}
ld_0 = 10000.0;
if (StringFind(Symbol(), "JPY") != -1) ld_0 = 100.0;
if (hedgingWorkaround) {
ld_16 = (MarketInfo(Symbol(), MODE_ASK) - (g_ihigh_264 + g_ilow_272) / 2.0) * ld_0;
if (MathAbs(ld_16) < 10.0) closePositions();
else {
if (ld_16 >= 10.0) {
li_24 = gi_340;
gi_340 = FALSE;
updateOrders();
gi_340 = li_24;
} else {
li_28 = gi_336;
gi_336 = FALSE;
updateOrders();
gi_336 = li_28;
}
}
} else updateOrders();
}
if (gi_244 == 5) {
if (li_36 || gi_364) {
closePositions();
if (gi_364) gi_364 = FALSE;
if (gi_304) gi_336 = FALSE;
else
if (!isDayBlacklisted(g_datetime_332)) gi_336 = TRUE;
if (gi_308) gi_340 = FALSE;
else
if (!isDayBlacklisted(g_datetime_332)) gi_340 = TRUE;
if (ld_40 < gi_128) {
gi_336 = FALSE;
gi_340 = FALSE;
gi_244 = 5;
} else gi_244 = 3;
} else
if (g_cmd_248 != -1) closePositions();
} else {
if (gi_244 == 4) {
if (getOpenPosition() == -1) {
if (g_cmd_248 == OP_BUY) gi_340 = FALSE;
else
if (g_cmd_248 == OP_SELL) gi_336 = FALSE;
if (gi_340 || gi_336) gi_244 = 3;
else gi_244 = 5;
} else {
li_32 = getPositionCount();
if (li_32 != gi_352) {
updateOrderTPs(li_32);
gi_352 = li_32;
if (gi_352 > gi_236) gi_236 = gi_352;
}
}
if (li_36) {
if (isDayBlacklisted(g_datetime_332)) gi_244 = 5;
else gi_364 = TRUE;
}
}
if (gi_244 == 6) {
if (li_36) gi_364 = TRUE;
if (!isOtherEAInTrade()) {
Print("Resuming from blocked state.");
gi_244 = 3;
}
}
}
}
void findFridayData() {
int li_0 = 0;
if (TimeDayOfWeek(TimeCurrent()) == 5) li_0 += 25;
for (int l_datetime_4 = iTime(Symbol(), PERIOD_H1, li_0); TimeDayOfWeek(l_datetime_4) != 5; l_datetime_4 = iTime(Symbol(), PERIOD_H1, li_0)) li_0++;
g_hour_368 = TimeHour(l_datetime_4);
}
void init() {
int lia_0[1];
int lia_4[1];
int lia_8[1];
int lia_12[1];
int lia_16[1];
int lia_20[1];
int lia_24[1];
int lia_28[1];
int lia_32[1];
int lia_36[1];
int lia_40[1];
int lia_44[1];
int lia_48[1];
int lia_52[1];
int lia_56[1];
int lia_60[1];
double lda_64[1];
double lda_68[1];
double lda_72[1];
double lda_76[1];
double lda_80[1];
double lda_84[1];
int lia_88[1];
int lia_92[1];
int lia_96[1];
int lia_100[1];
int lia_104[1];
int lia_108[1];
int li_112 = Initialize(AccountName(), StringLen(AccountName()), AccountNumber(), AccountCompany(), StringLen(AccountCompany()));
li_112 = 1;
if (li_112 == 1) gi_76 = TRUE;
else gi_76 = FALSE;
if (gi_76) Print("Account authorized.");
else Print("Unauthorized account!");
li_112 = GetSettings(Symbol(), lia_0, lia_4, lia_8, lia_12, lia_16, lia_20, lia_24, lia_28, lia_32, lia_36, lia_40, lia_44, lia_48, lia_52, lia_56, lia_60, lda_64, lda_68, lda_72, lda_76, lda_80, lda_84, lia_88, lia_92);
if (li_112 == 1) {
gi_116 = lia_0[0];
gi_120 = lia_4[0];
gi_124 = lia_8[0];
gi_128 = lia_12[0];
gi_132 = lia_16[0];
gi_136 = lia_20[0];
gi_140 = lia_24[0];
gi_144 = lia_28[0];
gi_148 = lia_32[0];
gi_152 = lia_36[0];
gi_156 = lia_40[0];
gi_160 = lia_44[0];
gi_164 = lia_48[0];
gi_168 = lia_52[0];
gi_172 = lia_56[0];
gi_176 = lia_60[0];
gd_180 = lda_64[0];
gd_188 = lda_68[0];
gd_196 = lda_72[0];
gd_204 = lda_76[0];
gd_212 = lda_80[0];
gd_220 = lda_84[0];
gi_228 = lia_88[0];
gi_84 = lia_92[0];
gi_80 = TRUE;
} else gi_80 = FALSE;
GetVersionInfo(lia_96, lia_100, lia_104, lia_108);
gi_88 = lia_96[0];
gi_92 = lia_100[0];
gi_96 = lia_104[0];
gi_100 = lia_108[0];
validateInputParameters();
initState();
findFridayData();
}
void deinit() {
if (ObjectFind("sellRange") == 0) ObjectDelete("sellRange");
if (ObjectFind("buyRange") == 0) ObjectDelete("buyRange");
}
string stateToString() {
string ls_unused_0;
switch (gi_244) {
case 0:
return ("Unknown");
case 2:
return ("Could not find tradeable range");
case 3:
return ("Waiting to enter trade");
case 4:
switch (gi_352) {
case 1:
return ("1 position open, price " + DoubleToStr(gd_356, 5));
case 2:
return ("2 positions open at average price " + DoubleToStr(gd_356, 5));
case 3:
return ("3 positions open at average price " + DoubleToStr(gd_356, 5));
case 4:
return ("4 positions open at average price " + DoubleToStr(gd_356, 5));
case 5: