-
Notifications
You must be signed in to change notification settings - Fork 1
/
GT-Shadow-3.09-GW-open.mq4
2329 lines (2284 loc) · 101 KB
/
GT-Shadow-3.09-GW-open.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
/*
Opened and nulled by Gayle Woot
Why not support the developer once you make 1000$ with this EA.
*/
#property copyright "GT-Shadow"
#property link "http://www.forex-goldmine.com"
string gs_76 = "GT-Shadow 3.09 - Fixed by Gayle Woot";
extern string tt0 = "-----------------------------------";
extern string Version = "GT-Shadow 3.09 - Fixed by Gayle Woot";
extern string tt1 = "Please support the developer once";
extern string tt2 = "you make 1000$ with this EA.";
extern string tt3 = "-----------------------------------";
extern string webpage = "http://www.forex-goldmine.com";
string gs_100 = "http://www.forex-goldmine.com";
extern int DisplayLevel = 0;
extern string UnlockCode = "1143420711";
extern bool DoTrades = TRUE;
extern bool BlockNegativeClose = TRUE;
extern bool AllowForSpread = TRUE;
extern bool CloseAllOpenOrders = FALSE;
extern int Instances = 39;
extern int FirstInstance = 1;
extern int TradeRange = 30;
extern int GapBetween = 0;
extern string tt4 = "RangeStart based on Dec 1 2008";
extern double RangeStart = 1.1911;
extern int ForwardEnd = 20;
extern int ReverseStart = 20;
extern int Shift = 0;
extern int TradeWindow = 5;
extern string g1 = "-----------------------------------";
extern string g2 = "The Following Settings Set a Dynamic Grid";
extern bool UseDynamicGrid = FALSE;
bool gi_196 = TRUE;
extern int LookBackDays = 2;
extern int CenterRevisitLevel = 101;
bool gi_208 = FALSE;
extern int AutoCalcOffset = 8;
extern int PowerLevel = 1;
extern double Level1 = 94.0;
extern double Level2 = 84.0;
extern double Level3 = 75.0;
extern int Range1 = 10;
extern int GapBetween1 = 0;
extern int Range2 = 25;
extern int GapBetween2 = 0;
extern int Range3 = 40;
extern int GapBetween3 = 0;
extern int Range4 = 55;
extern int GapBetween4 = 0;
extern int Range5 = 70;
extern int GapBetween5 = 0;
extern double CloseThreshold = 50.0;
extern double CloseUntil = 55.0;
extern bool CloseOldOpenOrders = TRUE;
extern double OldOrderOpenDays = 30.0;
extern int MA_Period = 0;
extern int BarToUse = 0;
extern string g3 = "--------------------";
extern string e = "Enter StopLoss as Number of Ranges or 0 for None";
extern int StopLoss = 0;
extern bool ShowTakeProfit = FALSE;
extern string f01 = "-----------------------------------------------";
extern bool UseEquity = FALSE;
extern string _acb = "Leave as 0 to use actual account balance.";
extern double accountbalance = 0.0;
extern double margin = 0.25;
extern bool UseMarginPercent = TRUE;
extern double BalanceFactor = 3500.0;
extern int decimals = 2;
extern int Slippage = 16;
extern bool EnableErrorMessages = FALSE;
extern bool EnableFastBackTests = FALSE;
double g_price_408 = 0.0;
bool gi_416 = FALSE;
bool gi_420 = FALSE;
bool gi_424 = TRUE;
string gs_428 = "-----------------------------------------------";
double gd_436 = 0.0;
double gd_444 = 0.0;
bool gi_452 = FALSE;
bool gi_456 = FALSE;
bool gi_460 = FALSE;
bool gi_464 = FALSE;
bool gi_468 = FALSE;
bool gi_472 = FALSE;
int gi_476 = 1;
string gs_480 = "-----------------------------------------------";
bool gi_488 = FALSE;
bool gi_492 = FALSE;
extern string f02 = "-----------------------------------------------";
extern string Following = "Settings Apply to Shadow Profit";
bool gi_512 = TRUE;
extern double StandardBalance = 1000.0;
extern double StandardMargin = 5.0;
extern string ShadowCurrency1 = "AUDNZD";
extern bool ShadowCurrency1Buy = TRUE;
extern bool ShadowCurrency1Sell = FALSE;
extern string tt5 = "shadowopen based on Dec 1 2008, same as rangestart";
extern double shadowopen1 = 1.1911;
extern string ShadowCurrency2 = "";
extern bool ShadowCurrency2Buy = FALSE;
extern bool ShadowCurrency2Sell = FALSE;
extern double shadowopen2 = 0.0;
string gs_580 = " ";
bool gi_588 = FALSE;
bool gi_592 = FALSE;
double gd_596 = 0.0;
string gs_604 = " ";
bool gi_612 = FALSE;
bool gi_616 = FALSE;
double gd_620 = 0.0;
extern string f03 = "-----------------------------------------------";
double gd_636 = 0.0;
double gd_644 = 0.0;
double gd_652 = 0.0;
double gd_660 = 0.0;
double gd_668 = 0.0;
double gd_676 = 0.0;
string gs_684 = "-----------------------------------------------";
double gd_692 = 0.0;
bool gi_700 = FALSE;
string gs_704 = "-----------------------------------------------";
extern string Currency1 = "AUDNZD";
extern bool Currency1Buy = TRUE;
extern bool Currency1Sell = FALSE;
extern string Currency2 = "";
extern bool Currency2Buy = FALSE;
extern bool Currency2Sell = FALSE;
string gs_744 = " ";
bool gi_752 = FALSE;
bool gi_756 = FALSE;
string gs_760 = " ";
bool gi_768 = FALSE;
bool gi_772 = FALSE;
extern string f04 = "------------------------------------------------";
extern string instr = "Leave Lots 0.00 for Auto-Calculation";
extern double lots1 = 0.0;
extern double lots2 = 0.0;
double gd_808 = 0.0;
double gd_816 = 0.0;
extern string f05 = "------------------------------------------------";
extern int MagicNumber1 = 130001;
extern int MagicNumber2 = 230001;
int gi_840 = 300001;
int gi_844 = 400001;
double gd_848 = 15.0;
extern bool CheckForHalfHedge = FALSE;
bool gi_860 = FALSE;
double gda_864[1001];
double gda_868[1001];
double gda_872[1001];
double gda_876[1001];
int gia_880[1001];
int gia_884[1001];
int gia_888[1001];
int gia_892[1001];
double gd_896 = 0.0;
int gi_904 = 1440;
int g_timeframe_908 = PERIOD_H1;
string g_symbol_912 = " ";
string g_symbol_920 = " ";
string g_symbol_928 = " ";
string g_symbol_936 = " ";
double gd_944 = -1000000.0;
double gd_952 = 1000000.0;
double gd_960 = -1000000.0;
double gd_968 = 1000000.0;
double gd_976 = 0.0;
double gd_984 = 0.0;
double g_free_magrin_992 = 0.0;
double g_free_magrin_1000 = 0.0;
double gd_1008 = 0.0;
double gd_1016 = 0.0;
double gd_1024 = 0.0;
double gd_1032 = 0.0;
double gd_1040 = 0.0;
double gd_1048 = 0.0;
double gd_1056 = 0.0;
double gd_1064 = 0.0;
double gd_1072 = 0.0;
double gd_1080 = 0.0;
double g_ilow_1088 = 0.0;
double g_ilow_1096 = 0.0;
double g_ilow_1104 = 0.0;
double g_ilow_1112 = 0.0;
double gd_1120 = 0.0;
double gd_1128 = 0.0;
double gd_1136 = 0.0;
double gd_1144 = 0.0;
double g_price_1152 = 0.0;
double g_price_1160 = 0.0;
double g_price_1168 = 0.0;
double g_price_1176 = 0.0;
double gd_1184 = 0.0;
double gd_1192 = 0.0;
double gd_1200 = 0.0;
double gd_1208 = 0.0;
double gd_1216 = 0.0;
double gd_1224 = 0.0;
double gd_1232 = 0.0;
double gd_1240 = 0.0;
double gd_1248 = 0.0;
double gd_1256 = 0.0;
double gd_1264 = 0.0;
double gd_1272 = 0.0;
double gd_1280 = 0.0;
double gd_1288 = 0.0;
double gd_1296 = 0.0;
double gd_1304 = 0.0;
double gd_1312 = 0.0;
double gd_1320 = 0.0;
double gd_1328 = 0.0;
double gd_1336 = 0.0;
int g_ord_total_1344 = 0;
int g_error_1348 = 0/* NO_ERROR */;
int gi_1352 = 10;
int g_count_1356 = 4;
int gi_1360 = 0;
double gd_1364 = 0.0;
double gd_1372 = 0.0;
double g_lotsize_1380 = 0.0;
double gd_1388 = 0.0;
double gd_1396 = 0.0;
double gd_1404 = 0.0;
double gd_1412 = 0.0;
double gd_1420 = 0.0;
double gd_1428 = 0.0;
double gd_1436 = 0.0;
double gd_1444 = 0.0;
double gd_1452 = 0.0;
double gd_1460 = 0.0;
string gs_1468 = " ";
string gs_1476 = " ";
string gs_1484 = " ";
string gs_1492 = " ";
int gi_1500 = 0;
int gi_1504 = TRUE;
bool gi_1508 = FALSE;
int gi_1512 = 0;
int gi_1516 = 0;
double gd_1520 = 0.0;
double gd_1528 = 0.0;
double gd_1536 = 0.0;
int gi_1544 = 0;
int gi_1548 = 0;
bool gi_1552 = FALSE;
int g_index_1556 = 0;
int gi_1560 = 0;
bool gi_1564 = FALSE;
bool gi_1568 = FALSE;
double gda_1572[1001];
double gd_1576 = 0.0;
string gs_1584 = " ";
string g_comment_1592 = " ";
string gs_1600 = " ";
string gs_1608 = " ";
string gs_1616 = " ";
string gs_1624 = " ";
int g_digits_1632 = 4;
bool gi_1636 = TRUE;
double g_ilow_1640 = 0.0;
double g_ihigh_1648 = 0.0;
double gd_1656 = 0.0;
int gi_1664 = 0;
int gi_1668 = 0;
int gi_1672 = 0;
int gi_1676 = 0;
int gi_1680 = 0;
int gi_1684 = 0;
int g_count_1688 = 0;
int gi_1692 = 0;
int gi_1696 = 0;
double gd_1700 = 0.0;
int gi_1708 = 0;
int gi_1712 = 0;
int gi_1716 = 0;
int gi_1720 = 0;
int gi_1724 = 0;
int gi_1728 = 0;
int gi_1732 = 0;
int gi_1736 = 0;
int gi_1740 = 0;
int gi_1744 = 0;
int gi_1748 = 0;
int gi_1752 = 0;
int gi_1756 = 0;
int gi_1760 = 0;
int gi_1764 = 0;
int g_datetime_1768;
int gi_1772 = 0;
int init() {
int li_0;
///if (Decoder() == 0) {
/// Comment("Please Enter a Valid Unlock Code");
/// return (0);
///}
if (UseDynamicGrid == TRUE && CloseThreshold > 89.0) {
Comment("CloseThreshold must be less than 90.");
return (0);
}
if (PowerLevel > 3) PowerLevel = 1;
if (UseDynamicGrid == TRUE) ShowTakeProfit = TRUE;
gi_1716 = ForwardEnd;
gi_1720 = ReverseStart;
if (gi_1724 == 0) gi_1724 = Instances;
if (gi_1728 == 0) gi_1728 = TradeRange;
if (gi_1732 == 0) gi_1732 = GapBetween;
if (gi_1736 == 0) gi_1736 = GapBetween1;
if (gi_1740 == 0) gi_1740 = GapBetween2;
if (gi_1744 == 0) gi_1744 = GapBetween3;
if (gi_1748 == 0) gi_1748 = GapBetween4;
if (gi_1752 == 0) gi_1752 = GapBetween5;
gi_1724 = Instances;
gi_1728 = TradeRange;
gi_1732 = GapBetween;
gi_1736 = GapBetween1;
gi_1740 = GapBetween2;
gi_1744 = GapBetween3;
gi_1748 = GapBetween4;
gi_1752 = GapBetween5;
Level1 /= 100.0;
Level2 /= 100.0;
Level3 /= 100.0;
gi_1756 = 0;
if (StopLoss != 0) BlockNegativeClose = FALSE;
g_datetime_1768 = TimeCurrent();
Instances--;
if (CloseAllOpenOrders == TRUE) gi_1636 = FALSE;
if (CloseAllOpenOrders == FALSE) gi_1636 = TRUE;
gd_1024 = shadowopen1;
gd_1032 = shadowopen2;
gd_1040 = gd_596;
gd_1048 = gd_620;
gi_1552 = FALSE;
if (StringLen(StringTrimLeft(Currency2)) < 2 && StringLen(StringTrimLeft(Currency1)) > 2) {
if (StringLen(StringTrimLeft(gs_744)) < 2)
if (StringLen(StringTrimLeft(gs_760)) < 2) gi_1552 = TRUE;
}
if (gi_1552 == TRUE) gs_1584 = "GT-Shadow ";
if (gi_1552 == FALSE) gs_1584 = "GT-Shadow ";
if (gi_1552 == TRUE) g_digits_1632 = MarketInfo(Currency1, MODE_DIGITS);
if (gi_1552 == FALSE) g_digits_1632 = 2;
gi_1692 = FirstInstance + Instances;
SetCurrenciesAndLotSize();
gi_1548 = FALSE;
if (UseDynamicGrid == TRUE) LevelSetup();
ArraySetUp();
if (gi_512 == TRUE && gi_1552 == FALSE) {
SetCurrenciesAndLotSize2();
SetForwardActions2();
gd_1312 = lots1;
gd_1320 = lots2;
gd_1328 = gd_808;
gd_1336 = gd_816;
gd_1536 = margin;
gd_1700 = accountbalance;
accountbalance = StandardBalance;
margin = StandardMargin;
margin *= 400 / AccountLeverage();
CalculateLots();
gd_1280 = gd_1248;
gd_1288 = gd_1256;
gd_1296 = gd_1264;
gd_1304 = gd_1272;
accountbalance = gd_1700;
margin = gd_1536;
lots1 = gd_1312;
lots2 = gd_1320;
gd_808 = gd_1328;
gd_816 = gd_1336;
}
if (gi_512 == TRUE && gi_1552 == TRUE) {
Currency2 = Currency1;
g_symbol_920 = Currency2;
Currency2Buy = Currency1Buy;
Currency2Sell = Currency1Sell;
ShadowCurrency2 = ShadowCurrency1;
ShadowCurrency2Buy = ShadowCurrency1Buy;
ShadowCurrency2Sell = ShadowCurrency1Sell;
shadowopen2 = shadowopen1;
SetCurrenciesAndLotSize2();
SetForwardActions2();
gd_1312 = lots1;
gd_1320 = lots2;
gd_1328 = gd_808;
gd_1336 = gd_816;
gd_1536 = margin;
gd_1700 = accountbalance;
accountbalance = StandardBalance;
margin = StandardMargin;
margin *= 400 / AccountLeverage();
CalculateLots();
gd_1280 = gd_1248;
gd_1288 = gd_1256;
gd_1296 = gd_1264;
gd_1304 = gd_1272;
accountbalance = gd_1700;
margin = gd_1536;
lots1 = gd_1312;
lots2 = gd_1320;
gd_808 = gd_1328;
gd_816 = gd_1336;
Currency2 = " ";
g_symbol_920 = " ";
Currency2Buy = FALSE;
Currency2Sell = FALSE;
ShadowCurrency2 = " ";
ShadowCurrency2Buy = FALSE;
ShadowCurrency2Sell = FALSE;
shadowopen2 = 0.0;
}
SetCurrenciesAndLotSize();
SetForwardActions();
g_index_1556 = 1;
GetOrderOpenPrices();
if (lots1 == 0.0 && lots2 == 0.0 && gd_808 == 0.0 && gd_816 == 0.0) {
gd_1312 = lots1;
gd_1320 = lots2;
gd_1328 = gd_808;
gd_1336 = gd_816;
CalculateLots();
lots1 = gd_1312;
lots2 = gd_1320;
gd_808 = gd_1328;
gd_816 = gd_1336;
}
if (lots1 != 0.0 || lots2 != 0.0 || gd_808 != 0.0 || gd_816 != 0.0) {
gd_1248 = lots1;
gd_1256 = lots2;
gd_1264 = gd_808;
gd_1272 = gd_816;
}
gd_1200 = CalculateShadowProfit("current");
g_count_1688 = 0;
g_index_1556 = FirstInstance - 1;
while (g_index_1556 < gi_1692) {
g_index_1556++;
if (gd_1200 >= gda_864[g_index_1556] && gd_1200 <= gda_868[g_index_1556]) {
gi_1560 = g_index_1556;
gi_1564 = gi_488;
gi_1568 = gi_492;
}
}
g_index_1556 = FirstInstance - 1;
while (g_index_1556 < gi_1692) {
g_index_1556++;
li_0 = search_for_conflict(gia_880[g_index_1556]);
if (li_0 == 1) break;
}
if (li_0 == 1) {
Comment("\nMagic Number Conflict With Another Pair...");
return (-1);
}
ShowComments();
return (0);
}
int deinit() {
return (0);
}
int start() {
int li_0;
int li_8;
///if (Decoder() == 0) {
/// Comment("Please Enter a Valid Unlock Code");
/// return (0);
/// }
g_index_1556 = FirstInstance - 1;
while (g_index_1556 < gi_1692) {
g_index_1556++;
li_0 = search_for_conflict(gia_880[g_index_1556]);
if (li_0 == 1) break;
}
if (li_0 == 1) {
Comment("\nMagic Number Conflict With Another Pair...");
return (-1);
}
if (UseDynamicGrid == TRUE && gi_1760 == TRUE && AccountEquity() / AccountBalance() > (CloseThreshold + 10.0) / 100.0) gi_1760 = FALSE;
if (UseDynamicGrid == TRUE && AccountEquity() / AccountBalance() < CloseThreshold / 100.0) gi_1760 = TRUE;
if (UseDynamicGrid == TRUE && gi_1760 == TRUE) {
FindAndCloseAll();
gi_1756 = 0;
}
if (UseDynamicGrid == TRUE) {
LevelSetup();
if (gi_1552 == TRUE && g_symbol_912 == Symbol() && MathAbs(Bid - gda_864[gi_1560]) / Point > TradeRange + 2) ArraySetUp();
if (gi_196 == TRUE && AccountEquity() / AccountBalance() < CenterRevisitLevel / 100 && ForwardEnd != gi_1672 + AutoCalcOffset) {
ForwardEnd = gi_1716;
ReverseStart = gi_1720;
TradeRange = gi_1728;
GapBetween = gi_1732;
Instances = gi_1724;
ForwardEnd = gi_1716;
ReverseStart = gi_1720;
ArraySetUp();
gi_1756 = 0;
LevelSetup();
ForwardEnd = gi_1672 + AutoCalcOffset;
ReverseStart = gi_1672 - AutoCalcOffset;
gi_1676 = ForwardEnd;
gi_1680 = ReverseStart;
}
if (CloseOldOpenOrders == TRUE && Minute() > 30 && gi_1764 == TRUE) gi_1764 = FALSE;
if (CloseOldOpenOrders == TRUE && Minute() < 10 && gi_1764 == FALSE) {
CloseOldOrders();
gi_1764 = TRUE;
}
if (TimeCurrent() - g_datetime_1768 > 432000) gi_1772 = TRUE;
}
if (StringLen(StringTrimLeft(Currency2)) < 2 && StringLen(StringTrimLeft(Currency1)) > 2) {
if (StringLen(StringTrimLeft(gs_744)) < 2)
if (StringLen(StringTrimLeft(gs_760)) < 2) gi_1552 = TRUE;
}
if (CloseAllOpenOrders == TRUE) gi_1636 = FALSE;
if (CloseAllOpenOrders == FALSE) gi_1636 = TRUE;
if (gi_1552 == TRUE) {
g_ilow_1640 = iLow(g_symbol_912, PERIOD_D1, 0);
for (int li_4 = 0; li_4 <= LookBackDays; li_4++)
if (iLow(g_symbol_912, PERIOD_D1, li_4) < g_ilow_1640) g_ilow_1640 = iLow(g_symbol_912, PERIOD_D1, li_4);
g_ihigh_1648 = iHigh(g_symbol_912, PERIOD_D1, 0);
for (li_4 = 0; li_4 <= LookBackDays; li_4++)
if (iHigh(g_symbol_912, PERIOD_D1, li_4) > g_ihigh_1648) g_ihigh_1648 = iHigh(g_symbol_912, PERIOD_D1, li_4);
g_ihigh_1648 = NormalizeDouble(g_ihigh_1648, MarketInfo(g_symbol_912, MODE_DIGITS));
g_ilow_1640 = NormalizeDouble(g_ilow_1640, MarketInfo(g_symbol_912, MODE_DIGITS));
gd_1656 = (g_ihigh_1648 + g_ilow_1640) / 2.0;
gd_1656 = NormalizeDouble(gd_1656, MarketInfo(g_symbol_912, MODE_DIGITS));
gi_1676 = ForwardEnd;
gi_1680 = ReverseStart;
if (gi_1684 == 1 && gd_1200 > gd_1656 && UseDynamicGrid == FALSE) {
if (ForwardEnd == 0 && gi_1664 != 0) gi_1676 = gi_1664 - 1;
if (ReverseStart == 0 && gi_1672 != 0) gi_1680 = gi_1672;
}
if (gi_1684 == 1 && gd_1200 < gd_1656 && UseDynamicGrid == FALSE) {
if (ReverseStart == 0 && gi_1668 != 0) gi_1680 = gi_1668 + 1;
if (ForwardEnd == 0 && gi_1672 != 0) gi_1676 = gi_1672;
}
if (gi_1684 == 0 && UseDynamicGrid == FALSE) {
if (gi_1676 == 0) gi_1676 = gi_1672;
if (gi_1680 == 0) gi_1680 = gi_1672;
}
if (gi_1676 == 0 && UseDynamicGrid == FALSE) gi_1676 = Instances;
if (gi_1680 == 0 && UseDynamicGrid == FALSE) gi_1680 = 1;
}
SetCurrenciesAndLotSize();
SetForwardActions();
g_index_1556 = 1;
GetOrderOpenPrices();
if (lots1 == 0.0 && lots2 == 0.0 && gd_808 == 0.0 && gd_816 == 0.0) {
gd_1312 = lots1;
gd_1320 = lots2;
gd_1328 = gd_808;
gd_1336 = gd_816;
CalculateLots();
lots1 = gd_1312;
lots2 = gd_1320;
gd_808 = gd_1328;
gd_816 = gd_1336;
}
if (lots1 != 0.0 || lots2 != 0.0 || gd_808 != 0.0 || gd_816 != 0.0) {
gd_1248 = lots1;
gd_1256 = lots2;
gd_1264 = gd_808;
gd_1272 = gd_816;
}
SetForwardActions();
gd_1428 = CalculateSwap();
gd_1200 = CalculateShadowProfit("current");
gd_1208 = CalculateShadowProfit("average");
if (gd_1200 != 0.0) {
if (gi_1552 == TRUE && EnableFastBackTests == TRUE) {
li_8 = TradeRange + GapBetween;
if (li_8 == 0) li_8 = 1;
g_count_1688 = 0;
gi_1708 = (Bid - RangeStart - TradeRange * Point) / Point / li_8 - 5.0;
gi_1712 = (Bid - RangeStart) / Point / li_8 + 5.0;
}
if (gi_1552 == FALSE || EnableFastBackTests == FALSE) {
gi_1708 = 1;
gi_1712 = 1000;
}
if (gi_1708 < 0) gi_1708 = 0;
if (gi_1712 > gi_1692 - 1) gi_1712 = gi_1692 - 1;
g_index_1556 = gi_1708;
while (g_index_1556 <= gi_1712) {
g_index_1556++;
if (gi_1676 >= g_index_1556) gi_488 = TRUE;
if (gi_1676 < g_index_1556) gi_488 = FALSE;
if (gi_1680 > g_index_1556) gi_492 = FALSE;
if (gi_1680 <= g_index_1556) gi_492 = TRUE;
if (gd_1200 >= gda_864[g_index_1556] && gd_1200 <= gda_868[g_index_1556]) {
gi_1560 = g_index_1556;
gi_1564 = gi_488;
gi_1568 = gi_492;
}
gda_1572[g_index_1556] = EAProfit();
if (DoTrades == TRUE) {
scanfororders2();
if (gi_1636 == FALSE) CloseAll();
gd_1200 = CalculateShadowProfit("ask");
if (gi_1772 == TRUE || (gi_1760 == FALSE && scanfororders() == 0 && (gi_424 == FALSE && gd_1200 <= gda_864[g_index_1556]) || (gi_424 == TRUE && (MA_Period != 0 && gd_1200 > gd_1208) ||
MA_Period == 0 && gd_1200 <= gda_864[g_index_1556] && gd_1200 >= gda_864[g_index_1556] - gd_1576) && gi_1636 == TRUE && gi_488 == TRUE && gi_1548 == FALSE)) {
if (gi_1772 == TRUE) gd_1248 = 0.01;
if (gi_1772 == TRUE) gd_1248 = NormalizeDouble(gd_1248, decimals);
g_price_408 = gd_1200;
SetForwardActions();
OpenAll();
g_datetime_1768 = TimeCurrent();
gi_1772 = FALSE;
gi_1360 = 1;
GetOrderOpenPrices();
if (gi_468 == TRUE && shadowopen1 != 0.0 || shadowopen2 != 0.0 || gd_596 != 0.0 || gd_620 != 0.0) ReadOrderOpenPrices();
if (gi_468 == FALSE) ReadOrderOpenPrices();
if (gi_468 == TRUE) WriteOrderOpenPrices();
gd_1200 = CalculateShadowProfit("current");
gi_1508 = FALSE;
}
gd_1200 = CalculateShadowProfit("current");
if (UseDynamicGrid == FALSE && gi_1508 == FALSE && gd_1200 >= gda_868[g_index_1556] && scanfororders() > 0) {
g_price_408 = gd_1200;
CloseAll();
}
gd_1200 = CalculateShadowProfit("current");
if (gi_1772 == TRUE || (gi_1760 == FALSE && gi_492 == TRUE && scanfororders() == 0 && (gi_424 == FALSE && gd_1200 >= gda_872[g_index_1556]) || (gi_424 == TRUE && (MA_Period != 0 &&
gd_1200 < gd_1208) || MA_Period == 0 && gd_1200 <= gda_872[g_index_1556] + gd_1576 && gd_1200 >= gda_872[g_index_1556]) && gi_1636 == TRUE && gi_1548 == FALSE)) {
if (gi_1772 == TRUE) gd_1248 = 0.01;
if (gi_1772 == TRUE) gd_1248 = NormalizeDouble(gd_1248, decimals);
g_price_408 = gd_1200;
SetReverseActions();
gi_1508 = TRUE;
OpenAll();
g_datetime_1768 = TimeCurrent();
gi_1772 = FALSE;
gi_1360 = 1;
GetOrderOpenPrices();
if (gi_468 == TRUE && shadowopen1 != 0.0 || shadowopen2 != 0.0 || gd_596 != 0.0 || gd_620 != 0.0) ReadOrderOpenPrices();
if (gi_468 == FALSE) ReadOrderOpenPrices();
if (gi_468 == TRUE) WriteOrderOpenPrices();
SetForwardActions();
gd_1200 = CalculateShadowProfit("current");
}
gd_1200 = CalculateShadowProfit("ask");
if (UseDynamicGrid == FALSE && gi_1508 == TRUE && gd_1200 <= gda_876[g_index_1556] && scanfororders() > 0) {
g_price_408 = gd_1200;
CloseAll();
}
gd_1200 = CalculateShadowProfit("current");
if (CheckForHalfHedge == TRUE) {
SetForwardActions();
scanfororders2();
if (gi_1508 == TRUE) SetReverseActions();
checkhalfhedge();
SetForwardActions();
}
}
}
}
scanfororders2();
ShowComments();
return (0);
}
int ShowComments() {
SetCurrenciesAndLotSize();
SetForwardActions();
if (lots1 == 0.0 && lots2 == 0.0 && gd_808 == 0.0 && gd_816 == 0.0) {
gd_1312 = lots1;
gd_1320 = lots2;
gd_1328 = gd_808;
gd_1336 = gd_816;
CalculateLots();
lots1 = gd_1312;
lots2 = gd_1320;
gd_808 = gd_1328;
gd_816 = gd_1336;
}
if (lots1 != 0.0 || lots2 != 0.0 || gd_808 != 0.0 || gd_816 != 0.0) {
gd_1248 = lots1;
gd_1256 = lots2;
gd_1264 = gd_808;
gd_1272 = gd_816;
}
string ls_0 = "";
if (g_timeframe_908 == PERIOD_H1) ls_0 = "Hourly";
if (g_timeframe_908 == PERIOD_H4) ls_0 = "4 Hour";
if (g_timeframe_908 == PERIOD_D1) ls_0 = "Daily";
if (g_timeframe_908 == PERIOD_M30) ls_0 = "30 Minute";
if (g_timeframe_908 == PERIOD_M15) ls_0 = "15 Minute";
if (g_timeframe_908 == PERIOD_M1) ls_0 = "1 Minute";
if (g_timeframe_908 == PERIOD_M5) ls_0 = "5 Minute";
double ld_8 = gd_848 / 100.0;
double ld_16 = gd_944 - gd_952;
double ld_24 = ld_16 * ld_8;
double ld_32 = gd_960 - gd_968;
double ld_40 = ld_32 * ld_8;
int li_48 = gi_1560;
if (DisplayLevel != 0) gi_1560 = DisplayLevel;
if (gi_1676 >= gi_1560) gi_488 = TRUE;
if (gi_1676 < gi_1560) gi_488 = FALSE;
if (gi_1680 > gi_1560) gi_492 = FALSE;
if (gi_1680 <= gi_1560) gi_492 = TRUE;
gi_1564 = gi_488;
gi_1568 = gi_492;
string ls_52 = "True";
if (DoTrades == FALSE) ls_52 = "False";
string ls_60 = "True";
if (gi_1564 == FALSE) ls_60 = "False";
string ls_68 = "True";
if (gi_1568 == FALSE) ls_68 = "False";
string ls_76 = "False";
if (CloseAllOpenOrders == TRUE) ls_76 = "True";
string ls_84 = "False";
if (CheckForHalfHedge == TRUE) ls_84 = "True";
if (gi_1552 == FALSE) {
Comment("\n"
+ gs_76
+ "\n"
+ gs_100
+ "\n\nShadow Profit = " + DoubleToStr(gd_1200, 2)
+ "\nAverage Shadow Profit = " + DoubleToStr(CalculateShadowProfit("average"), 2)
+ "\n\nComment = " + gs_1584 + DoubleToStr(MagicNumber1, 0) + " " + DoubleToStr(gd_1200, g_digits_1632)
+ "\n\nForward Open " + gi_1560 + " = " + DoubleToStr(gda_864[gi_1560], 2)
+ "\nForward Close " + gi_1560 + " = " + DoubleToStr(gda_868[gi_1560], 2)
+ "\nReverse Open " + gi_1560 + " = " + DoubleToStr(gda_872[gi_1560], 2)
+ "\nReverse Close " + gi_1560 + " = " + DoubleToStr(gda_876[gi_1560], 2)
+ "\n\nShift = " + DoubleToStr(Shift, 2)
+ "\nMargin = " + DoubleToStr(margin, 2)
+ "\nMA_Period = " + MA_Period
+ "\nTradeWindow = " + DoubleToStr(gd_1576, 2)
+ "\n\nTradeRange = " + TradeRange
+ "\nRangeStart = " + DoubleToStr(RangeStart, 2)
+ "\nTotal Ranges = " + ((Instances + 1))
+ "\nFirst Range = " + FirstInstance
+ "\nLast Range = " + gi_1692
+ "\n\nEquity Percent = " + DoubleToStr(100.0 * (AccountEquity() / AccountBalance()), 2)
+ "\nProfit for this Instance of EA = " + DoubleToStr(gda_1572[gi_1560], 2)
+ "\n\nLots1 = " + gs_1468 + " " + DoubleToStr(gd_1248, 2) + " " + g_symbol_912 + " " + gia_880[gi_1560] + " Net Total Lots = " + DoubleToStr(AddLots(g_symbol_912), 2)
+ "\nLots2 = " + gs_1476 + " " + DoubleToStr(gd_1256, 2) + " " + g_symbol_920 + " " + gia_884[gi_1560] + " Net Total Lots = " + DoubleToStr(AddLots(g_symbol_920), 2)
+ "\nLotSize = " + DoubleToStr(g_lotsize_1380, 0)
+ "\nAccount Leverage = " + AccountLeverage() + " : 1"
+ "\n\nDoTrades = " + ls_52
+ "\nClose All Open Orders = " + ls_76
+ "\nOpen Forward Orders = " + ls_60 + " (" + gi_1676 + ") "
+ "\nOpen Reverse Orders = " + ls_68 + " (" + gi_1680 + ") "
+ "\nCheck and Correct For Half Hedge = " + ls_84);
}
if (gi_1552 == TRUE && gi_1560 > gi_1676 && gi_1560 >= gi_1680) {
Comment("\n"
+ gs_76
+ "\n"
+ gs_100
+ "\n\nCurrent Bid Price= " + DoubleToStr(gd_1200, MarketInfo(g_symbol_912, MODE_DIGITS))
+ "\n\nReverse Open " + gi_1560 + " = " + DoubleToStr(gda_872[gi_1560], MarketInfo(g_symbol_912, MODE_DIGITS))
+ "\nReverse Close " + gi_1560 + " = " + DoubleToStr(gda_876[gi_1560], MarketInfo(g_symbol_912, MODE_DIGITS))
+ "\n\nShift = " + DoubleToStr(Shift, 2)
+ "\nMargin = " + DoubleToStr(margin, 2)
+ "\nMA_Period = " + MA_Period
+ "\nTradeWindow = " + DoubleToStr(gd_1576, MarketInfo(g_symbol_912, MODE_DIGITS))
+ "\n\nTradeRange = " + TradeRange
+ "\nRangeStart = " + DoubleToStr(RangeStart, Digits)
+ "\nTotal Ranges = " + ((Instances + 1))
+ "\nFirst Range = " + FirstInstance
+ "\nLast Range = " + gi_1692
+ "\nBalanceFactor = " + DoubleToStr(BalanceFactor, 2)
+ "\nEquity Percent = " + DoubleToStr(100.0 * (AccountEquity() / AccountBalance()), 2)
+ "\n\nPrice " + LookBackDays + " Day High = " + DoubleToStr(g_ihigh_1648, MarketInfo(g_symbol_912, MODE_DIGITS)) + " (" + gi_1664 + ") "
+ "\nPrice " + LookBackDays + " Day Low = " + DoubleToStr(g_ilow_1640, MarketInfo(g_symbol_912, MODE_DIGITS)) + " (" + gi_1668 + ") "
+ "\nPrice " + LookBackDays + " Mid-Range = " + DoubleToStr(gd_1656, MarketInfo(g_symbol_912, MODE_DIGITS)) + " (" + gi_1672 + ") "
+ "\n\nProfit for this Instance of EA = " + DoubleToStr(gda_1572[gi_1560], 2)
+ "\n\nLots1 = " + gs_1468 + " " + DoubleToStr(gd_1248, 2) + " " + g_symbol_912 + " " + gia_880[gi_1560] + " Net Total Lots = " + DoubleToStr(AddLots(g_symbol_912), 2)
+ "\nLots2 = " + gs_1476 + " " + DoubleToStr(gd_1256, 2) + " " + g_symbol_920 + " " + gia_884[gi_1560] + " Net Total Lots = " + DoubleToStr(AddLots(g_symbol_920), 2)
+ "\nLotSize = " + DoubleToStr(g_lotsize_1380, 0)
+ "\nAccount Leverage = " + AccountLeverage() + " : 1"
+ "\nMax Slippage = " + DoubleToStr(Slippage * MarketInfo(g_symbol_912, MODE_POINT), MarketInfo(g_symbol_912, MODE_DIGITS))
+ "\n\nDoTrades = " + ls_52
+ "\nClose All Open Orders = " + ls_76
+ "\nOpen Forward Orders = " + ls_60 + " (" + gi_1676 + ") "
+ "\nOpen Reverse Orders = " + ls_68 + " (" + gi_1680 + ") ");
}
if (gi_1552 == TRUE && gi_1560 <= gi_1676 && gi_1560 < gi_1680) {
Comment("\n"
+ gs_76
+ "\n"
+ gs_100
+ "\n\nCurrent Bid Price= " + DoubleToStr(gd_1200, MarketInfo(g_symbol_912, MODE_DIGITS))
+ "\n\nForward Open " + gi_1560 + " = " + DoubleToStr(gda_864[gi_1560], MarketInfo(g_symbol_912, MODE_DIGITS))
+ "\nForward Close " + gi_1560 + " = " + DoubleToStr(gda_868[gi_1560], MarketInfo(g_symbol_912, MODE_DIGITS))
+ "\n\nShift = " + DoubleToStr(Shift, 2)
+ "\nMargin = " + DoubleToStr(margin, 2)
+ "\nMA_Period = " + MA_Period
+ "\nTradeWindow = " + DoubleToStr(gd_1576, MarketInfo(g_symbol_912, MODE_DIGITS))
+ "\n\nTradeRange = " + TradeRange
+ "\nRangeStart = " + DoubleToStr(RangeStart, Digits)
+ "\nTotal Ranges = " + ((Instances + 1))
+ "\nFirst Range = " + FirstInstance
+ "\nLast Range = " + gi_1692
+ "\nBalanceFactor = " + DoubleToStr(BalanceFactor, 2)
+ "\nEquity Percent = " + DoubleToStr(100.0 * (AccountEquity() / AccountBalance()), 2)
+ "\n\nPrice " + LookBackDays + " Day High = " + DoubleToStr(g_ihigh_1648, MarketInfo(g_symbol_912, MODE_DIGITS)) + " (" + gi_1664 + ") "
+ "\nPrice " + LookBackDays + " Day Low = " + DoubleToStr(g_ilow_1640, MarketInfo(g_symbol_912, MODE_DIGITS)) + " (" + gi_1668 + ") "
+ "\nPrice " + LookBackDays + " Mid-Range = " + DoubleToStr(gd_1656, MarketInfo(g_symbol_912, MODE_DIGITS)) + " (" + gi_1672 + ") "
+ "\n\nProfit for this Instance of EA = " + DoubleToStr(gda_1572[gi_1560], 2)
+ "\n\nLots1 = " + gs_1468 + " " + DoubleToStr(gd_1248, 2) + " " + g_symbol_912 + " " + gia_880[gi_1560] + " Net Total Lots = " + DoubleToStr(AddLots(g_symbol_912), 2)
+ "\nLots2 = " + gs_1476 + " " + DoubleToStr(gd_1256, 2) + " " + g_symbol_920 + " " + gia_884[gi_1560] + " Net Total Lots = " + DoubleToStr(AddLots(g_symbol_920), 2)
+ "\nLotSize = " + DoubleToStr(g_lotsize_1380, 0)
+ "\nAccount Leverage = " + AccountLeverage() + " : 1"
+ "\nMax Slippage = " + DoubleToStr(Slippage * MarketInfo(g_symbol_912, MODE_POINT), MarketInfo(g_symbol_912, MODE_DIGITS))
+ "\n\nDoTrades = " + ls_52
+ "\nClose All Open Orders = " + ls_76
+ "\nOpen Forward Orders = " + ls_60 + " (" + gi_1676 + ") "
+ "\nOpen Reverse Orders = " + ls_68 + " (" + gi_1680 + ") ");
}
if (gi_1552 == TRUE && (gi_1560 <= gi_1676 && gi_1560 >= gi_1680)) {
Comment("\n"
+ gs_76
+ "\n"
+ gs_100
+ "\n\nCurrent Bid Price= " + DoubleToStr(gd_1200, MarketInfo(g_symbol_912, MODE_DIGITS))
+ "\n\nForward Open " + gi_1560 + " = " + DoubleToStr(gda_864[gi_1560], MarketInfo(g_symbol_912, MODE_DIGITS))
+ "\nForward Close " + gi_1560 + " = " + DoubleToStr(gda_868[gi_1560], MarketInfo(g_symbol_912, MODE_DIGITS))
+ "\nReverse Open " + gi_1560 + " = " + DoubleToStr(gda_872[gi_1560], MarketInfo(g_symbol_912, MODE_DIGITS))
+ "\nReverse Close " + gi_1560 + " = " + DoubleToStr(gda_876[gi_1560], MarketInfo(g_symbol_912, MODE_DIGITS))
+ "\n\nShift = " + DoubleToStr(Shift, 2)
+ "\nMargin = " + DoubleToStr(margin, 2)
+ "\nMA_Period = " + MA_Period
+ "\nTradeWindow = " + DoubleToStr(gd_1576, MarketInfo(g_symbol_912, MODE_DIGITS))
+ "\n\nTradeRange = " + TradeRange
+ "\nRangeStart = " + DoubleToStr(RangeStart, Digits)
+ "\nTotal Ranges = " + ((Instances + 1))
+ "\nFirst Range = " + FirstInstance
+ "\nLast Range = " + gi_1692
+ "\nBalanceFactor = " + DoubleToStr(BalanceFactor, 2)
+ "\nEquity Percent = " + DoubleToStr(100.0 * (AccountEquity() / AccountBalance()), 2)
+ "\n\nPrice " + LookBackDays + " Day High = " + DoubleToStr(g_ihigh_1648, MarketInfo(g_symbol_912, MODE_DIGITS)) + " (" + gi_1664 + ") "
+ "\nPrice " + LookBackDays + " Day Low = " + DoubleToStr(g_ilow_1640, MarketInfo(g_symbol_912, MODE_DIGITS)) + " (" + gi_1668 + ") "
+ "\nPrice " + LookBackDays + " Mid-Range = " + DoubleToStr(gd_1656, MarketInfo(g_symbol_912, MODE_DIGITS)) + " (" + gi_1672 + ") "
+ "\n\nProfit for this Instance of EA = " + DoubleToStr(gda_1572[gi_1560], 2)
+ "\n\nLots1 = " + gs_1468 + " " + DoubleToStr(gd_1248, 2) + " " + g_symbol_912 + " " + gia_880[gi_1560] + " Net Total Lots = " + DoubleToStr(AddLots(g_symbol_912), 2)
+ "\nLots2 = " + gs_1476 + " " + DoubleToStr(gd_1256, 2) + " " + g_symbol_920 + " " + gia_884[gi_1560] + " Net Total Lots = " + DoubleToStr(AddLots(g_symbol_920), 2)
+ "\nLotSize = " + DoubleToStr(g_lotsize_1380, 0)
+ "\nAccount Leverage = " + AccountLeverage() + " : 1"
+ "\nMax Slippage = " + DoubleToStr(Slippage * MarketInfo(g_symbol_912, MODE_POINT), MarketInfo(g_symbol_912, MODE_DIGITS))
+ "\n\nDoTrades = " + ls_52
+ "\nClose All Open Orders = " + ls_76
+ "\nOpen Forward Orders = " + ls_60 + " (" + gi_1676 + ") "
+ "\nOpen Reverse Orders = " + ls_68 + " (" + gi_1680 + ") ");
}
gi_1560 = li_48;
return (0);
}
double EAProfit() {
double ld_ret_0 = 0.0;
if (search_for(gia_880[g_index_1556]) != 0) ld_ret_0 += OrderProfit();
if (search_for(gia_884[g_index_1556]) != 0) ld_ret_0 += OrderProfit();
if (search_for(gia_888[g_index_1556]) != 0) ld_ret_0 += OrderProfit();
if (search_for(gia_892[g_index_1556]) != 0) ld_ret_0 += OrderProfit();
return (ld_ret_0);
}
int search_for(int a_magic_0) {
g_ord_total_1344 = OrdersTotal();
for (int l_pos_4 = g_ord_total_1344 - 1; l_pos_4 >= 0; l_pos_4--) {
if (!OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES)) {
g_error_1348 = GetLastError();
Print("OrderSelect( ", l_pos_4, ", SELECT_BY_POS ) - Error #", g_error_1348);
} else {
if (OrderMagicNumber() == a_magic_0)
if (OrderCloseTime() == 0) return (a_magic_0);
}
}
return (0);
}
int search_for_conflict(int a_magic_0) {
bool li_4 = FALSE;
g_ord_total_1344 = OrdersTotal();
for (int l_pos_8 = g_ord_total_1344 - 1; l_pos_8 >= 0; l_pos_8--) {
if (!OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES)) {
g_error_1348 = GetLastError();
Print("OrderSelect( ", l_pos_8, ", SELECT_BY_POS ) - Error #", g_error_1348);
} else {
if (OrderMagicNumber() == a_magic_0) {
if (OrderCloseTime() == 0) {
if (OrderSymbol() != g_symbol_912) {
if (OrderSymbol() != g_symbol_912) li_4 = TRUE;
if (li_4 == TRUE) return (1);
}
}
}
}
}
return (0);
}
int FindAndCloseAll() {
g_ord_total_1344 = OrdersTotal();
for (int l_pos_0 = g_ord_total_1344 - 1; l_pos_0 >= 0; l_pos_0--) {
if (!OrderSelect(l_pos_0, SELECT_BY_POS, MODE_TRADES)) {
g_error_1348 = GetLastError();
Print("OrderSelect( ", l_pos_0, ", SELECT_BY_POS ) - Error #", g_error_1348);
} else {
if (OrderMagicNumber() - MagicNumber1 <= 2000) {
if (OrderMagicNumber() >= MagicNumber1) {
if (OrderCloseTime() == 0)
if (AccountEquity() / AccountBalance() < CloseUntil / 100.0) Close_it();
}
}
}
}
return (0);
}
int CloseOldOrders() {
int l_index_0 = 0;
while (l_index_0 < 2000) {
l_index_0++;
if (search_for(gia_880[l_index_0]) != 0)
if (TimeCurrent() - OrderOpenTime() > 86400.0 * OldOrderOpenDays) Close_it();
}
return (0);
}
double AddLots(string a_symbol_0) {
double ld_ret_8 = 0.0;
g_ord_total_1344 = OrdersTotal();
for (int l_pos_16 = g_ord_total_1344 - 1; l_pos_16 >= 0; l_pos_16--) {
if (!OrderSelect(l_pos_16, SELECT_BY_POS, MODE_TRADES)) {
g_error_1348 = GetLastError();
Print("OrderSelect( ", l_pos_16, ", SELECT_BY_POS ) - Error #", g_error_1348);
} else {
if (OrderSymbol() == a_symbol_0) {
if (OrderCloseTime() == 0) {
if (OrderType() == OP_BUY) ld_ret_8 += OrderLots();
if (OrderType() == OP_SELL) ld_ret_8 -= OrderLots();
}
}
}
}
return (ld_ret_8);
}
int open_buy_market(int a_magic_0, double a_lots_4, string a_symbol_12) {
int l_slippage_52;
int l_count_56;
int l_ticket_60;
double l_price_64;
double l_maxlot_20 = MarketInfo(a_symbol_12, MODE_MAXLOT);
double l_minlot_28 = MarketInfo(a_symbol_12, MODE_MINLOT);
double ld_36 = a_lots_4;
double l_price_44 = 0.0;
if (gi_1552 == TRUE) {
if (StopLoss != 0.0) {
if (gi_1772 == FALSE) l_price_44 = gda_864[g_index_1556] - StopLoss * TradeRange * MarketInfo(a_symbol_12, MODE_POINT);
if (gi_1772 == TRUE) l_price_44 = MarketInfo(a_symbol_12, MODE_BID) - StopLoss * TradeRange * MarketInfo(a_symbol_12, MODE_POINT);
l_price_44 = NormalizeDouble(l_price_44, MarketInfo(a_symbol_12, MODE_DIGITS));
}
}
if (gi_1552 == FALSE) l_price_44 = 0.0;
while (ld_36 > 0.0) {
a_lots_4 = ld_36;
if (a_lots_4 > l_maxlot_20) a_lots_4 = l_maxlot_20;
if (a_lots_4 < l_minlot_28) a_lots_4 = l_minlot_28;
a_lots_4 = NormalizeDouble(a_lots_4, decimals);
ld_36 -= a_lots_4;
l_slippage_52 = Slippage;
l_count_56 = 0;
l_ticket_60 = -1;
l_price_64 = 0.0;
if (ShowTakeProfit == TRUE && gi_1552 == TRUE) {
if (gi_1772 == FALSE) l_price_64 = gda_864[g_index_1556] + TradeRange * MarketInfo(a_symbol_12, MODE_POINT);
if (gi_1772 == TRUE) l_price_64 = MarketInfo(a_symbol_12, MODE_ASK) + TradeRange * MarketInfo(a_symbol_12, MODE_POINT);
l_price_64 = NormalizeDouble(l_price_64, MarketInfo(a_symbol_12, MODE_DIGITS));
}
g_comment_1592 = gs_1584 + DoubleToStr(a_magic_0, 0) + " " + DoubleToStr(gd_1200, g_digits_1632);
while (l_ticket_60 == -1 && l_count_56 <= gi_1352) {
if (Slippage != 0 && gi_1552 == TRUE && MarketInfo(a_symbol_12, MODE_ASK) - g_price_408 < Slippage * MarketInfo(a_symbol_12, MODE_POINT)) l_ticket_60 = OrderSend(a_symbol_12, OP_BUY, a_lots_4, MarketInfo(a_symbol_12, MODE_ASK), l_slippage_52, l_price_44, l_price_64, g_comment_1592, a_magic_0, 0, CLR_NONE);
if (Slippage == 0 || gi_1552 == FALSE) l_ticket_60 = OrderSend(a_symbol_12, OP_BUY, a_lots_4, MarketInfo(a_symbol_12, MODE_ASK), l_slippage_52, l_price_44, l_price_64, g_comment_1592, a_magic_0, 0, CLR_NONE);
l_count_56++;
if (l_ticket_60 >= 0) break;
if (l_count_56 > gi_1352) break;
Sleep(1000);
}
if (l_ticket_60 != 0) {
g_error_1348 = GetLastError();
if (EnableErrorMessages == TRUE) Alert("Error OrderSend # ", g_error_1348);
}
if (ld_36 > 0.0) continue;
}
return (0);
}
int open_sell_market(int a_magic_0, double a_lots_4, string a_symbol_12) {
int l_slippage_52;
int l_count_56;
int l_ticket_60;