forked from peterthomet/MetaTrader-5-and-4-Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Trade Manager.mq5
5440 lines (4685 loc) · 140 KB
/
Trade Manager.mq5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
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
//
// Trade Manager.mq5
// getYourNet.ch
//
#property copyright "Copyright 2023, getYourNet.ch"
#property link "http://shop.getyournet.ch/trademanager"
#ifdef __MQL4__
#include <..\Libraries\stdlib.mq4>
#endif
#ifdef __MQL5__
#include <Trade\Trade.mqh>
#include <errordescription.mqh>
enum OrderType
{
OP_BUY,
OP_SELL
};
#endif
#include <CurrencyStrength.mqh>
#include <MultiPivots.mqh>
#ifdef __MQL5__
//#include <CurrencyStrengthReadDB.mqh>
#endif
enum TypeAutomation
{
NoAutomation, // None
Dredging // Dredging System
};
enum TypeInstance
{
Instance1=1,
Instance2=2,
Instance3=3,
Instance4=4,
Instance5=5,
Instance6=6,
Instance7=7,
Instance8=8,
Instance9=9
};
enum TypeStopLossPercentTradingCapitalAction
{
CloseWorstTrade,
CloseAllTrades
};
enum TypeLipStickMode
{
LipStickNone,
LipStickMode1,
LipStickMode2
};
input TypeInstance Instance = 1;
input TypeAutomation Automation = NoAutomation;
input double BreakEvenAfterPips = 5;
input double AboveBEPips = 1;
input double StartTrailingPips = 7;
input double TakeProfitPips = 0;
input double StopLossPips = 0;
input bool HedgeAtStopLoss = false;
input double HedgeVolumeFactor = 1;
input double HedgeFlatAtLevel = 5;
input double TakeProfitPercentTradingCapital = 0;
input double StopLossPercentTradingCapital = 0;
input double MaxDailyLoss = 0;
input TypeStopLossPercentTradingCapitalAction StopLossPercentTradingCapitalAction = CloseAllTrades;
input bool CloseTradesBeforeMidnight = false;
input int CloseTradesBeforeMidnightHour = 23;
input int CloseTradesBeforeMidnightMinute = 00;
input bool ActivateTrailing = false;
input double TrailingFactor = 0.6;
input double OpenLots = 0.01;
input bool ShowInfo = true;
input color TextColor = Gray;
input color TextColorBold = Black;
input color TextColorInfo = DodgerBlue;
input color TextColorPlus = MediumSeaGreen;
input color TextColorMinus = DeepPink;
input color Color_USD = MediumSeaGreen; // USD color
input color Color_EUR = DodgerBlue; // EUR color
input color Color_GBP = DeepPink; // GBP color
input color Color_CHF = Black; // CHF color
input color Color_JPY = Chocolate; // JPY color
input color Color_AUD = DarkOrange; // AUD color
input color Color_CAD = MediumVioletRed; // CAD color
input color Color_NZD = Silver; // NZD color
input string FontName = "Arial";
input int FontSize = 9;
input int TextGap = 16;
input bool ManageOwnTradesOnly = true;
input int ManageMagicNumberOnly = 0;
input int ManageOrderNumberOnly = 0;
input bool SwitchSymbolClickAllCharts = true;
input bool DrawLevelsAllCharts = true;
input bool DrawBackgroundPanel = true;
input int BackgroundPanelWidth = 250;
input color BackgroundPanelColor = clrNONE;
input int SymbolListSize = 10;
input bool MT5CommissionPerDeal = true;
input int AvailableTradingCapital = 0;
input int PendingOrdersSplit = 3;
input double PendingOrdersRiskFactor = 3;
input double PendingOrdersFirstTPStep = 5;
input double PendingOrdersNextTPSteps = 1;
input int StartHour = 0;
input int StartMinute = 0;
input int MinPoints1 = 0;
input group "Harvesters";
input bool Harvester_CSGBPReversal = false;
input bool Harvester_CSGBP45MinStrength = false;
input bool Harvester_CSFollow = false;
input bool Harvester_GBPWeek = false;
input bool Harvester_CSEmergingTrends = false;
input bool UseCurrencyStrengthDatabase = false;
input group "Trading Hours";
input bool Hour0 = true;
input bool Hour1 = true;
input bool Hour2 = true;
input bool Hour3 = true;
input bool Hour4 = true;
input bool Hour5 = true;
input bool Hour6 = true;
input bool Hour7 = true;
input bool Hour8 = true;
input bool Hour9 = true;
input bool Hour10 = true;
input bool Hour11 = true;
input bool Hour12 = true;
input bool Hour13 = true;
input bool Hour14 = true;
input bool Hour15 = true;
input bool Hour16 = true;
input bool Hour17 = true;
input bool Hour18 = true;
input bool Hour19 = true;
input bool Hour20 = true;
input bool Hour21 = true;
input bool Hour22 = true;
input bool Hour23 = true;
input group "Trading Weekdays";
input bool Sunday = true;
input bool Monday = true;
input bool Tuesday = true;
input bool Wednesday = true;
input bool Thursday = true;
input bool Friday = true;
input bool Saturday = true;
input group "General Parameters";
input double P1 = 0;
input double P2 = 0;
input double P3 = 0;
input double P4 = 0;
input double P5 = 0;
input double P6 = 0;
input double P7 = 0;
input double P8 = 0;
input double P9 = 0;
input double P10 = 0;
input double P11 = 0;
input double P12 = 0;
input double P13 = 0;
input double P14 = 0;
input double P15 = 0;
input double P16 = 0;
input double P17 = 0;
input double P18 = 0;
input double P19 = 0;
input double P20 = 0;
string appname="Trade Manager";
string appnamespace="";
bool appinit=false;
bool working=false;
double pipsfactor;
datetime lasttick;
datetime lasterrortime;
string lasterrorstring;
bool istesting;
bool initerror;
string SymbolExtraChars="";
double SymbolCommission;
string tickchar="";
int magicnumberfloor=0;
int basemagicnumber=0;
int hedgeoffsetmagicnumber=10000;
double _BreakEvenAfterPips;
double _AboveBEPips;
double _StartTrailingPips;
double _TakeProfitPips;
double _StopLossPips;
double _OpenLots;
bool _TradingHours[24];
bool _TradingWeekdays[7];
bool ctrlon;
bool crosshairon;
bool leftmousebutton;
int lipstickmode;
int currentlipstickmode;
double startdragprice;
double enddragprice;
bool tradelevelsvisible;
int selectedtradeindex;
uint repeatlasttick=0;
int repeatcount=0;
double atr;
int atrday;
int InstrumentSelected;
int TradesViewSelected;
const double DISABLEDPOINTS=1000000;
bool _ShowInfo;
int chartheight;
bool arrowdown=false;
int listshift=0;
string currencies[8]={"USD","EUR","GBP","JPY","CHF","CAD","AUD","NZD"};
string pairs[8][7]={
{"EURUSD","GBPUSD","USDJPY","USDCHF","USDCAD","AUDUSD","NZDUSD"},
{"EURUSD","EURGBP","EURJPY","EURCHF","EURCAD","EURAUD","EURNZD"},
{"GBPUSD","EURGBP","GBPJPY","GBPCHF","GBPCAD","GBPAUD","GBPNZD"},
{"USDJPY","EURJPY","GBPJPY","CHFJPY","CADJPY","AUDJPY","NZDJPY"},
{"USDCHF","EURCHF","GBPCHF","CHFJPY","CADCHF","AUDCHF","NZDCHF"},
{"USDCAD","EURCAD","GBPCAD","CADJPY","CADCHF","AUDCAD","NZDCAD"},
{"AUDUSD","EURAUD","GBPAUD","AUDJPY","AUDCHF","AUDCAD","AUDNZD"},
{"NZDUSD","EURNZD","GBPNZD","NZDJPY","NZDCHF","NZDCAD","AUDNZD"}
};
color currencycolor[8];
string symbollist;
string inifilename;
struct TypeTextObjects
{
string objects[];
void AddObject(string name)
{
bool found=false;
int size=ArraySize(objects);
for(int i=0; i<size; i++)
{
if(objects[i]==name)
{
found=true;
break;
}
}
if(!found)
{
ArrayResize(objects,size+1);
objects[size]=name;
}
}
void HideAll()
{
int size=ArraySize(objects);
for(int i=0; i<size; i++)
ObjectSetInteger(0,objects[i],OBJPROP_XDISTANCE,-1000);
}
};
enum BEStopModes
{
None=1,
HardSingle=2,
SoftBasket=3
};
enum Instruments
{
CurrentPair=-1,
USD=0,
EUR=1,
GBP=2,
JPY=3,
CHF=4,
CAD=5,
AUD=6,
NZD=7,
};
enum TradesView
{
ByPairs,
ByCurrencies,
ByCurrenciesGrouped
};
struct TypeTradeInfo
{
int orderindex;
int type;
double volume;
double openprice;
datetime opentime;
double points;
double commissionpoints;
double gain;
double tickvalue;
long magicnumber;
long orderticket;
TypeTradeInfo()
{
orderindex=-1;
type=NULL;
volume=0;
openprice=0;
opentime=0;
points=0;
commissionpoints=0;
gain=0;
tickvalue=0;
magicnumber=0;
orderticket=0;
}
};
struct TypeTradeReference
{
long magicnumber;
double points;
double gain;
double tickvalue;
double stoplosspips;
double stoplosslevel;
double takeprofitpips;
double takeprofitlevel;
double commissionpoints;
double openprice;
string pair;
int type;
double volume;
datetime lastupdate;
TypeTradeReference()
{
magicnumber=0;
points=0;
gain=0;
tickvalue=0;
stoplosspips=DISABLEDPOINTS;
stoplosslevel=0;
takeprofitpips=DISABLEDPOINTS;
takeprofitlevel=0;
commissionpoints=0;
openprice=0;
pair="";
type=NULL;
volume=0;
lastupdate=0;
}
};
struct TypeCloseCommand
{
string filter;
bool executed;
TypeCloseCommand()
{
filter="";
executed=false;
}
};
struct TypeCloseCommands
{
TypeCloseCommand commands[];
void Init()
{
ArrayResize(commands,0);
}
void Add(string filter="")
{
int size=ArraySize(commands);
ArrayResize(commands,size+1);
commands[size].filter=filter;
}
int GetNextCommandIndex()
{
int index=-1;
for(int i=ArraySize(commands)-1; i>=0; i--)
{
if(!commands[i].executed)
{
index=i;
break;
}
}
return index;
}
};
struct TypePendingOrder
{
int ordertype;
double entryprice;
double stopprice;
double stoppoints;
double volume;
};
struct TypeWorkingState
{
BEStopModes StopMode;
bool closebasketatBE;
bool ManualBEStopLocked;
bool SoftBEStopLocked;
double peakgain;
double peakpips;
bool TrailingActivated;
long currentbasemagicnumber;
TypeTradeReference tradereference[];
double globalgain;
datetime lastorderexecution;
TypeCloseCommands closecommands;
TypePendingOrder pendingorders[];
void Init()
{
closebasketatBE=false;
ManualBEStopLocked=false;
SoftBEStopLocked=false;
StopMode=SoftBasket;
peakgain=0;
peakpips=0;
TrailingActivated=false;
currentbasemagicnumber=basemagicnumber;
ArrayResize(tradereference,0);
globalgain=0;
lastorderexecution=0;
closecommands.Init();
ArrayResize(pendingorders,0);
};
void Reset()
{
closebasketatBE=false;
ManualBEStopLocked=false;
SoftBEStopLocked=false;
peakgain=0;
peakpips=0;
TrailingActivated=false;
currentbasemagicnumber=basemagicnumber;
ArrayResize(tradereference,0);
globalgain=0;
ToggleTradeLevels(true);
closecommands.Init();
};
void ResetLocks()
{
ManualBEStopLocked=false;
SoftBEStopLocked=false;
};
bool IsOrderPending()
{
int lastordertimediff = (int)TimeLocal()-(int)lastorderexecution;
return (lastordertimediff<=5);
};
};
struct TypeCurrenciesTradesGroupsInfo
{
int type;
double volume;
double gain;
long magicfrom;
long magicto;
string containspairs;
TypeCurrenciesTradesGroupsInfo()
{
type=0;
volume=0;
gain=0;
magicfrom=LONG_MAX;
magicto=LONG_MIN;
containspairs="";
}
};
struct TypeCurrenciesTradesInfo
{
double buyvolume;
double sellvolume;
double buygain;
double sellgain;
TypeCurrenciesTradesGroupsInfo tg[];
TypeCurrenciesTradesInfo()
{
buyvolume=0;
sellvolume=0;
buygain=0;
sellgain=0;
ArrayResize(tg,0);
}
};
struct TypePairsTradesInfo
{
string pair;
double buyvolume;
double sellvolume;
double buygain;
double sellgain;
double gain;
double gainpips;
TypeTradeInfo tradeinfo[];
TypePairsTradesInfo()
{
pair="";
buyvolume=0;
sellvolume=0;
buygain=0;
sellgain=0;
gain=0;
gainpips=0;
ArrayResize(tradeinfo,0);
}
};
struct TypeBasketInfo
{
double gain;
double gainpips;
double gainpipsglobal;
double gainpipsplus;
double gainpipsminus;
double volumeplus;
double volumeminus;
int buys;
int sells;
double buyvolume;
double sellvolume;
int managedorders;
TypePairsTradesInfo pairsintrades[];
TypeCurrenciesTradesInfo currenciesintrades[];
int largestlossindex;
double largestloss;
double globalprofitloss;
void Init()
{
gain=0;
gainpips=0;
gainpipsglobal=0;
gainpipsplus=0;
gainpipsminus=0;
volumeplus=0;
volumeminus=0;
buys=0;
sells=0;
buyvolume=0;
sellvolume=0;
managedorders=0;
ArrayResize(pairsintrades,0);
ArrayResize(currenciesintrades,0);
ArrayResize(currenciesintrades,8);
largestlossindex=-1;
largestloss=0;
globalprofitloss=0;
};
};
TypeTextObjects TextObjects;
TypeWorkingState WS;
TypeBasketInfo BI;
void OnInit()
{
ChartSetInteger(0,CHART_EVENT_MOUSE_MOVE,1);
atr=0;
atrday=-1;
InstrumentSelected=CurrentPair;
TradesViewSelected=ByPairs;
ctrlon=false;
crosshairon=false;
leftmousebutton=false;
lipstickmode=LipStickNone;
currentlipstickmode=LipStickNone;
startdragprice=0;
enddragprice=0;
tradelevelsvisible=false;
initerror=false;
appnamespace=appname+" "+IntegerToString(Instance)+" ";
magicnumberfloor=10000000*Instance;
basemagicnumber=magicnumberfloor+1;
istesting=MQLInfoInteger(MQL_TESTER);
_ShowInfo=ShowInfo;
if(istesting&&MQLInfoInteger(MQL_VISUAL_MODE))
_ShowInfo=true;
SymbolExtraChars = StringSubstr(Symbol(), 6);
lasttick=TimeLocal();
pipsfactor=1;
if(Digits()==5||Digits()==3)
pipsfactor=10;
_BreakEvenAfterPips=BreakEvenAfterPips*pipsfactor;
_AboveBEPips=AboveBEPips*pipsfactor;
_TakeProfitPips=TakeProfitPips*pipsfactor;
if(_TakeProfitPips==0)
_TakeProfitPips=DISABLEDPOINTS;
_StopLossPips=StopLossPips*pipsfactor;
if(_StopLossPips==0)
_StopLossPips=DISABLEDPOINTS;
_StartTrailingPips=StartTrailingPips*pipsfactor;
_OpenLots=OpenLots;
_TradingHours[0]=Hour0;
_TradingHours[1]=Hour1;
_TradingHours[2]=Hour2;
_TradingHours[3]=Hour3;
_TradingHours[4]=Hour4;
_TradingHours[5]=Hour5;
_TradingHours[6]=Hour6;
_TradingHours[7]=Hour7;
_TradingHours[8]=Hour8;
_TradingHours[9]=Hour9;
_TradingHours[10]=Hour10;
_TradingHours[11]=Hour11;
_TradingHours[12]=Hour12;
_TradingHours[13]=Hour13;
_TradingHours[14]=Hour14;
_TradingHours[15]=Hour15;
_TradingHours[16]=Hour16;
_TradingHours[17]=Hour17;
_TradingHours[18]=Hour18;
_TradingHours[19]=Hour19;
_TradingHours[20]=Hour20;
_TradingHours[21]=Hour21;
_TradingHours[22]=Hour22;
_TradingHours[23]=Hour23;
_TradingWeekdays[0]=Sunday;
_TradingWeekdays[1]=Monday;
_TradingWeekdays[2]=Tuesday;
_TradingWeekdays[3]=Wednesday;
_TradingWeekdays[4]=Thursday;
_TradingWeekdays[5]=Friday;
_TradingWeekdays[6]=Saturday;
currencycolor[0]=Color_USD;
currencycolor[1]=Color_EUR;
currencycolor[2]=Color_GBP;
currencycolor[3]=Color_JPY;
currencycolor[4]=Color_CHF;
currencycolor[5]=Color_CAD;
currencycolor[6]=Color_AUD;
currencycolor[7]=Color_NZD;
symbollist="";
inifilename=AccountInfoString(ACCOUNT_SERVER)+" "+IntegerToString(AccountInfoInteger(ACCOUNT_LOGIN))+" "+appnamespace+".ini";
WS.Init();
if(!istesting)
GetGlobalVariables();
chartheight=(int)ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS);
if(DrawBackgroundPanel&&_ShowInfo)
{
string objname=appnamespace+"Panel";
ObjectCreate(0,objname,OBJ_RECTANGLE_LABEL,0,0,0,0,0);
ObjectSetInteger(0,objname,OBJPROP_CORNER,CORNER_RIGHT_UPPER);
ObjectSetInteger(0,objname,OBJPROP_BORDER_TYPE,BORDER_FLAT);
ObjectSetInteger(0,objname,OBJPROP_WIDTH,1);
ObjectSetInteger(0,objname,OBJPROP_XDISTANCE,BackgroundPanelWidth);
ObjectSetInteger(0,objname,OBJPROP_YDISTANCE,0);
ObjectSetInteger(0,objname,OBJPROP_XSIZE,BackgroundPanelWidth);
ObjectSetInteger(0,objname,OBJPROP_YSIZE,10000);
color c=(color)ChartGetInteger(0,CHART_COLOR_BACKGROUND);
if(BackgroundPanelColor!=clrNONE)
c=BackgroundPanelColor;
ObjectSetInteger(0,objname,OBJPROP_COLOR,c);
ObjectSetInteger(0,objname,OBJPROP_BGCOLOR,c);
}
DisplaySymbolList();
InitStrategies();
InitTesting();
if(!istesting)
{
if(!EventSetMillisecondTimer(200))
initerror=true;
}
}
void AppInit()
{
if(appinit)
return;
SymbolCommission=0;
HistorySelect(0,TimeCurrent());
int total=HistoryDealsTotal();
ulong ticket=0;
for(int i=total-1;i>=0;i--)
{
if((ticket=HistoryDealGetTicket(i))>0)
{
if(HistoryDealGetString(ticket,DEAL_SYMBOL)==Symbol())
{
SymbolCommission=MathAbs(NormalizeDouble(HistoryDealGetDouble(ticket,DEAL_COMMISSION)/HistoryDealGetDouble(ticket,DEAL_VOLUME),2)*2);
break;
}
}
}
appinit=true;
}
void InitTesting()
{
if(!istesting)
return;
//WS.StopMode=None;
//_OpenLots=0.1;
//ctrlon=true;
//TradesViewSelected=ByCurrencies;
//OpenBuy("GBPUSD");
//OpenSell("EURGBP");
//OpenBuy("GBPJPY");
//OpenBuy("GBPCHF");
//OpenBuy("GBPCAD");
//OpenBuy("GBPAUD");
//OpenBuy("GBPNZD");
//OpenSell("GBPUSD");
//OpenBuy("EURGBP");
//OpenSell("GBPJPY");
//OpenSell("GBPCHF");
//OpenSell("GBPCAD");
//OpenSell("GBPAUD");
//OpenSell("GBPNZD");
//WS.closecommands.Add();
//ArrayResize(strats,1);
//strats[0]=new StrategyCSGBPBaskets;
//strats[0]=new StrategyOutOfTheBox;
//strats[0]=new StrategyLittleDD;
//strats[0]=new StrategyPivotsH4FibonacciR1S1Reversal;
#ifdef __MQL5__
//OpenDBConnection();
//CloseDBConnection();
#endif
}
void InitStrategies()
{
ArrayResize(strats,0);
int i=0;
if(Harvester_CSGBPReversal)
{
ArrayResize(strats,i+1);
strats[i]=new StrategyCSGBPReversal;
i++;
}
if(Harvester_CSGBP45MinStrength)
{
ArrayResize(strats,i+1);
strats[i]=new StrategyCSGBP45MinStrength;
i++;
}
if(Harvester_CSFollow)
{
ArrayResize(strats,i+1);
strats[i]=new StrategyCSFollow;
i++;
}
if(Harvester_GBPWeek)
{
ArrayResize(strats,i+1);
strats[i]=new StrategyGBPWeek;
i++;
}
if(Harvester_CSEmergingTrends)
{
ArrayResize(strats,i+1);
strats[i]=new StrategyCSEmergingTrends;
i++;
}
}
void OnDeinit(const int reason)
{
for(int i=ArraySize(strats)-1; i>=0; i--)
delete strats[i];
EventKillTimer();
#ifdef __MQL5__
if(istesting)
{
//CloseDBConnection();
//if(!MQL5InfoInteger(MQL5_OPTIMIZATION))
}
#endif
if(!istesting)
{
DeleteAllObjects();
SetGlobalVariables();
ToggleCtrl(true);
ToggleTradeLevels(true);
}
}
void OnTick()
{
lasttick=TimeLocal();
if(ctrlon)
DrawLevels();
CheckPendingOrders();
Manage();
}
void OnTimer()
{
Manage();
}
void Manage()
{
if(working||initerror||!TerminalInfoInteger(TERMINAL_CONNECTED))
return;
working=true;
AppInit();
int closecommandindex=WS.closecommands.GetNextCommandIndex();
while(closecommandindex>-1)
{
CloseAllInternal(WS.closecommands.commands[closecommandindex].filter);
WS.closecommands.commands[closecommandindex].executed=true;
closecommandindex=WS.closecommands.GetNextCommandIndex();
}
if(currentlipstickmode!=lipstickmode)
{
if(lipstickmode==LipStickNone)
DeleteLipstick();
else
CreateLipstick();
currentlipstickmode=lipstickmode;
}
if(ManageOrders())
{
ManageBasket();
DisplayText();
}
for(int i=ArraySize(strats)-1; i>=0; i--)
strats[i].Calculate();
working=false;
}
void SetBEClose()
{
if(WS.globalgain<0)
{
WS.closebasketatBE=!WS.closebasketatBE;
}
if(WS.globalgain>=0)
{
WS.ManualBEStopLocked=!WS.ManualBEStopLocked;
}
}
void SetSoftStopMode()
{
if(WS.StopMode==None)
WS.StopMode=SoftBasket;
else if(WS.StopMode==HardSingle)
WS.StopMode=None;
else
WS.StopMode=None;
WS.ResetLocks();
SetGlobalVariables();
}
void SetHardStopMode()
{
if(WS.StopMode==None)
WS.StopMode=HardSingle;
else if(WS.StopMode==SoftBasket)
WS.StopMode=None;
else
WS.StopMode=None;
WS.ResetLocks();
SetGlobalVariables();
}
void ManageSymbolList()
{
string symbols[];
int n=StringSplit(symbollist,';',symbols);
int listsize=MathMax(10,SymbolListSize);
symbollist="";
for(int i=(n>listsize) ? (n-listsize) : 0; i<n; i++)
{
if(symbols[i]!=Symbol())
{
if(symbollist.Length()>0)
symbollist+=";";
symbollist+=symbols[i];
}
}
if(symbollist.Length()>0)
symbollist+=";";
symbollist+=Symbol();
}
void DisplaySymbolList()
{
int rowindex=0;
string symbols[];
int n=StringSplit(symbollist,';',symbols);
if(SymbolListSize>1)
{
for(int i=n-1; i>=MathMax(0,n-SymbolListSize); i--)
{
color paircolor=TextColor;
if(symbols[i]==Symbol())
paircolor=TextColorBold;
CreateSymbolLabel(rowindex,FontSize,paircolor,symbols[i],"-TMSymbolListButton",0,"");
rowindex++;
}
}
}
void SetGlobalVariables()
{
PersistentVariables pv(inifilename);
pv.load();
pv["StopMode"]=WS.StopMode;
pv["peakgain"]=WS.peakgain;
pv["peakpips"]=WS.peakpips;
pv["OpenLots"]=_OpenLots;
pv["OpenLots-"+Symbol()]=_OpenLots;
pv["StopLossPips"]=_StopLossPips;
pv["StopLossPips-"+Symbol()]=_StopLossPips;
pv["TakeProfitPips"]=_TakeProfitPips;
pv["TakeProfitPips-"+Symbol()]=_TakeProfitPips;
pv["currentbasemagicnumber"]=WS.currentbasemagicnumber;
pv["ManualBEStopLocked"]=WS.ManualBEStopLocked;
pv["closebasketatBE"]=WS.closebasketatBE;
pv["lipstickmode"]=lipstickmode;
pv["InstrumentSelected"]=InstrumentSelected;
pv["TradesViewSelected"]=TradesViewSelected;
pv.ClearGroup("TradeReference.");
int asize=ArraySize(WS.tradereference);
for(int i=0; i<asize; i++)
{