forked from hung96ad/MQL4_Experts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MultiTrader.mq4
5572 lines (5325 loc) · 413 KB
/
MultiTrader.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
//+---------------------------------------------------------------------------+
//| ___ ___ _ _ _ _____ _ |
//| | \/ | | | | (_)_ _| | | |
//| | . . |_ _| | |_ _ | |_ __ __ _ __| | ___ _ __ |
//| | |\/| | | | | | __| | | | '__/ _` |/ _` |/ _ \ '__| |
//| | | | | |_| | | |_| | | | | | (_| | (_| | __/ | |
//| \_| |_/\__,_|_|\__|_| \_/_| \__,_|\__,_|\___|_| |
//| |
//| Open-source software (OSS) MultiTrader.mq4 |
//| Provided free of charge Copyright © 2019, MhFx7 <> Mani Heshmat |
//| By MhFx7 <> Mani Heshmat https://www.mql5.com/en/users/mhfx7 |
//+---------------------------------------------------------------------------+
#define Copyright "Copyright © 2019, MhFx7 <> Mani Heshmat"
#property copyright Copyright
#define Link "https://www.mql5.com/en/users/mhfx7"
#property link Link
#define Version "1.00"
#property version Version
#property strict
//---
#define ExpertName "MultiTrader"
#define OBJPREFIX "MT - "
//---
#property description "Warning: The automatically generated lot size is an estimated value and should not be considered accurate, note that this feature always requires a stoploss distance.\n"
#property description "Note: All displayed values symbolized with a \"p\" as well as all input distances are in points.\n"
#property description "This software is provided free of charge and can be downloaded under the following link:"
#property description "https://www.mql5.com/en/code/24786"
//---
#define CLIENT_BG_WIDTH 1190
#define INDENT_TOP 15
//---
#define OPENPRICE 0
#define CLOSEPRICE 1
//---
#define OP_ALL -1
//---
#define KEY_UP 38
#define KEY_DOWN 40
//---
enum ENUM_TF{DAILY/*Daily*/,WEEKLY/*Weekly*/,MONTHLY/*Monthly*/};
enum ENUM_MODE{FULL/*Full*/,COMPACT/*Compact*/,MINI/*Mini*/};
//--- User inputs
input string =" < - - - General - - - >";
input ENUM_MODE SelectedMode = COMPACT;/*Dashboard (Size)*/
input ENUM_TF CalcPeriod = DAILY;/*Time Frame*/
input int BuyLevel = 90;//High Level %
input int SellLevel = 10;//Low Level %
input string Prefix = "";//Symbol Prefix
input string Suffix = "";//Symbol Suffix
extern string TradeSymbols = "AUDCAD;AUDCHF;AUDJPY;AUDNZD;AUDUSD;CADCHF;CADJPY;CHFJPY;EURAUD;EURCAD;EURCHF;EURGBP;EURJPY;EURNZD;EURUSD;GBPAUD;GBPCAD;GBPCHF;GBPNZD;GBPUSD;GBPJPY;NZDCHF;NZDCAD;NZDJPY;NZDUSD;USDCAD;USDCHF;USDJPY;";/*Symbol List (separated by " ; ")*/
input string = " < - - - Trading - - - >";
input bool OneClickTrading = true;/*One-Click Trading*/
input int MagicNumber = 0;//Magic Number
input int Slippage = 3;//Slippage
input bool KeyboardTrading = true;/*Keyboard Trading*/
input string BuyKey = "B";/*Buy Key*/
input string CloseKey = "C";/*Close Key*/
input string SellKey = "S";/*Sell Key*/
input string = " < - - - AutoSL - - - >";
input ENUM_TIMEFRAMES ATRTF = PERIOD_H1;/*ATR Time Frame*/
input int ATRPeriod = 14;/*ATR Period*/
extern double ATRMulti = 1;/*ATR Multiplier*/
input string = " < - - - Alerts - - - >";
input bool PairSuggest = true;/*Suggestions*/
input bool SmartAlert = true;/*Smart Alerts*/
input bool _Alert = true;/*Pop-ups*/
input bool Push = false;/*Push*/
input bool Mail = false;/*Email*/
input string = " < - - - Graphics - - - >";
input color COLOR_BORDER = C'255,151,25';/*Panel Border*/
input color COLOR_CBG_LIGHT = C'252,252,252';/*Chart Background (Light)*/
input color COLOR_CBG_DARK = C'28,27,26';/*Chart Background (Dark)*/
//--- Global variables
string sTradeSymbols = TradeSymbols;
string sFontType = "";
//---
double RiskP = 0;
double RiskC = 0;
double RiskInpC = 0;
double RiskInpP = 0;
//---
int ResetAlertUp = 0;
int ResetAlertDwn = 0;
bool UserIsEditing = false;
bool UserWasNotified = false;
//---
double StopLossDist = 0;
double RiskInp = 0;
double RR = 0;
double _TP = 0;
//---
int SelectedTheme = 0;
int PriceRowLeft = 0;
int PriceRowRight = 0;
bool ShowTradePanel = true;
//---
int ErrorInterval = 300;
int LastReason = 0;
string ErrorSound = "error.wav";
bool SoundIsEnabled = false;
bool AlarmIsEnabled = false;
int ProfitMode = 0;
//---
bool AUDAlarm = true;
bool CADAlarm = true;
bool CHFAlarm = true;
bool EURAlarm = true;
bool GBPAlarm = true;
bool JPYAlarm = true;
bool NZDAlarm = true;
bool USDAlarm = true;
//---
bool AUDTrigger = false;
bool CADTrigger = false;
bool CHFTrigger = false;
bool EURTrigger = false;
bool GBPTrigger = false;
bool JPYTrigger = false;
bool NZDTrigger = false;
bool USDTrigger = false;
//----
string SuggestedPair = "";
int LastTimeFrame = 0;
int LastMode = -1;
//---
bool AutoSL = false;
bool AutoTP = false;
bool AutoLots = false;
bool ClearedTemplate = false;
bool FirstRun = true;
//---
color COLOR_BG = clrNONE;
color COLOR_FONT = clrNONE;
//---
color COLOR_GREEN = clrForestGreen;
color COLOR_RED = clrFireBrick;
color COLOR_SELL = C'225,68,29';
color COLOR_BUY = C'3,95,172';
color COLOR_CLOSE = clrNONE;
color COLOR_AUTO = clrDodgerBlue;
color COLOR_LOW = clrNONE;
color COLOR_MARKER = clrNONE;
int FONTSIZE = 9;
//---
int _x1 = 0;
int _y1 = 0;
int ChartX = 0;
int ChartY = 0;
int Chart_XSize = 0;
int Chart_YSize = 0;
int CalcTF = 0;
datetime drop_time = 0;
datetime stauts_time = 0;
//---
color COLOR_REGBG = C'27,27,27';
color COLOR_REGFONT = clrSilver;
//---
int Bck_Win_X = 255;
int Bck_Win_Y = 150;
//---
string aSymbols[];
string UsedSymbols[];
//---
string MB_CAPTION=ExpertName+" v"+Version+" | "+Copyright;
//---
string PriceRowLeftArr[]={"Bid","Low","Open","Pivot"};
string PriceRowRightArr[]={"Ask","High","Open","Pivot"};
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---- CreateTimer
EventSetMillisecondTimer(100);
//--- StrategyTester
if(MQLInfoInteger(MQL_TESTER))
{
_OnTester();
return(INIT_SUCCEEDED);
}
//--- Disclaimer
if(!GlobalVariableCheck(OBJPREFIX+"Disclaimer") || GlobalVariableGet(OBJPREFIX+"Disclaimer")!=1)
{
//---
string message="DISCLAIMER:\n\nIf you trade with MultiTrader, you are doing so at your own discretion. Forex is a risky business. You may lose a substantial amount of money by taking the risk of live trading. The author of MultiTrader and/or MhFx7 <> Mani Heshmat will not be held responsible for your losses or problems of any kind if the EA is directly or indirectly responsible for any losses.";
//---
if(MessageBox(message,MB_CAPTION,MB_OKCANCEL|MB_ICONWARNING)==IDOK)
GlobalVariableSet(OBJPREFIX+"Disclaimer",1);
else
return(INIT_FAILED);
}
//---
if(!GlobalVariableCheck(OBJPREFIX+"Theme"))
SelectedTheme=1;
else
SelectedTheme=(int)GlobalVariableGet(OBJPREFIX+"Theme");
//---
if(SelectedTheme==0)
{
COLOR_BG=C'240,240,240';
COLOR_FONT=C'40,41,59';
COLOR_GREEN=clrForestGreen;
COLOR_RED=clrIndianRed;
COLOR_LOW=clrGoldenrod;
COLOR_MARKER=clrDarkOrange;
}
else
{
COLOR_BG=C'28,28,28';
COLOR_FONT=clrSilver;
COLOR_GREEN=clrLimeGreen;
COLOR_RED=clrRed;
COLOR_LOW=clrYellow;
COLOR_MARKER=clrGold;
}
//---
if(LastReason==0)
{
//--- OfflineChart
if(ChartGetInteger(0,CHART_IS_OFFLINE))
{
MessageBox("The currenct chart is offline, make sure to uncheck \"Offline chart\" under Properties(F8)->Common.",
MB_CAPTION,MB_OK|MB_ICONERROR);
return(INIT_FAILED);
}
//--- CheckConnection
if(!TerminalInfoInteger(TERMINAL_CONNECTED))
MessageBox("Warning: No Internet connection found!\nPlease check your network connection.",
MB_CAPTION+" | "+"#"+IntegerToString(123),MB_OK|MB_ICONWARNING);
//--- CheckTradingIsAllowed
if(!TerminalInfoInteger(TERMINAL_TRADE_ALLOWED))//Terminal
{
MessageBox("Warning: Check if automated trading is allowed in the terminal settings!",
MB_CAPTION+" | "+"#"+IntegerToString(123),MB_OK|MB_ICONWARNING);
}
else
{
if(!MQLInfoInteger(MQL_TRADE_ALLOWED))//CheckBox
{
MessageBox("Warning: Automated trading is forbidden in the program settings for "+__FILE__,
MB_CAPTION+" | "+"#"+IntegerToString(123),MB_OK|MB_ICONWARNING);
}
}
//---
if(!AccountInfoInteger(ACCOUNT_TRADE_EXPERT))//Server
MessageBox("Warning: Automated trading is forbidden for the account "+IntegerToString(AccountInfoInteger(ACCOUNT_LOGIN))+" at the trade server side.",
MB_CAPTION+" | "+"#"+IntegerToString(123),MB_OK|MB_ICONWARNING);
//---
if(!AccountInfoInteger(ACCOUNT_TRADE_ALLOWED))//Investor
MessageBox("Warning: Trading is forbidden for the account "+IntegerToString(AccountInfoInteger(ACCOUNT_LOGIN))+"."+
"\n\nPerhaps an investor password has been used to connect to the trading account."+
"\n\nCheck the terminal journal for the following entry:"+
"\n\'"+IntegerToString(AccountInfoInteger(ACCOUNT_LOGIN))+"\': trading has been disabled - investor mode.",
MB_CAPTION+" | "+"#"+IntegerToString(ERR_TRADE_DISABLED),MB_OK|MB_ICONWARNING);
//---
if(!SymbolInfoInteger(_Symbol,SYMBOL_TRADE_MODE))//Symbol
MessageBox("Warning: Trading is disabled for the symbol "+_Symbol+" at the trade server side.",
MB_CAPTION+" | "+"#"+IntegerToString(ERR_TRADE_DISABLED),MB_OK|MB_ICONWARNING);
//--- CheckDotsPerInch
if(TerminalInfoInteger(TERMINAL_SCREEN_DPI)!=96)
{
Comment("Warning: 96 DPI highly recommended !");
Sleep(3000);
Comment("");
}
}
//--- Check for Symbols (Analysis)
for(int i=0; i<ArraySize(Symbols); i++)
{
//---
if(!SymbolFind(Prefix+Symbols[i]+Suffix,true))
if(SymbolFind(Prefix+Symbols[i]+Suffix,false))
SymbolSelect(Prefix+Symbols[i]+Suffix,true);
}
//--- Input Symbols Changed
if(sTradeSymbols!=TradeSymbols || LastReason==0)
{
//---
ArrayResize(aSymbols,0,0);
ObjectsDeleteAll(0,OBJPREFIX,-1,-1);
//--- Get Trade Symobols
if(StringFind(TradeSymbols,";",0)==-1)
{
//---
string message="No separator found !\nMake sure to separate symbols with a semicolon \" ; \".";
//---
MessageBox(message,MB_CAPTION,MB_OK|MB_ICONERROR);
Comment(message);
//---
ObjectsDeleteAll(0,OBJPREFIX,-1,-1);
return(INIT_FAILED);
}
//--- Semicolon at the first place
if(StringFind(TradeSymbols,";",0)==0)
TradeSymbols=StringSubstr(TradeSymbols,1,StringLen(TradeSymbols));
//---
TradeSymbols=StringTrimLeft(StringTrimRight(TradeSymbols));
//---
if(StringSubstr(TradeSymbols,StringLen(TradeSymbols)-1,1)!=";")
TradeSymbols=StringConcatenate(TradeSymbols,";");
//---
int s=0,k=StringFind(TradeSymbols,";",s);
string current;
//---
while(k>0)
{
//---
current=StringSubstr(TradeSymbols,s,k-s);
//---
if(SymbolFind(Prefix+current+Suffix,false))
{
ArrayResize(aSymbols,ArraySize(aSymbols)+1);
aSymbols[ArraySize(aSymbols)-1]=current;
}
//---
s=k+1;
k=StringFind(TradeSymbols,";",s);
}
//--- Check for Symbols (Trading)
for(int i=0; i<ArraySize(aSymbols); i++)
{
//---
if(!SymbolFind(Prefix+aSymbols[i]+Suffix,true))
if(SymbolFind(Prefix+aSymbols[i]+Suffix,false))
SymbolSelect(Prefix+aSymbols[i]+Suffix,true);
}
//---
sTradeSymbols=TradeSymbols;
}
//--- InitFullSymbs
SetFull();
//--- Check for Currency Pairs
for(int i=0; i<ArraySize(UsedSymbols); i++)
{
//---
if(!SymbolFind(Prefix+UsedSymbols[i]+Suffix,true))
{
//---
if(LastReason==0)
{
//---
string message="All 28 currency pairs are not available !\nPerhaps the Prefix and/or Suffix were not set correctly.";
//---
MessageBox(message,MB_CAPTION,MB_OK|MB_ICONERROR);
}
//---
ObjectsDeleteAll(0,OBJPREFIX,-1,-1);
break;
return(INIT_FAILED);
}
}
//--- Calc Timeframe
if(CalcPeriod==DAILY)
{
CalcTF=PERIOD_D1;
ProfitMode=1;
ResetAlertUp=BuyLevel-15;
ResetAlertDwn=SellLevel+15;
}
//---
if(CalcPeriod==WEEKLY)
{
CalcTF=PERIOD_W1;
ProfitMode=2;
ResetAlertUp=BuyLevel-10;
ResetAlertDwn=SellLevel+10;
}
//---
if(CalcPeriod==MONTHLY)
{
CalcTF=PERIOD_MN1;
ProfitMode=3;
ResetAlertUp=BuyLevel-5;
ResetAlertDwn=SellLevel+5;
}
//--- Reset Alarms
if(CalcTF!=LastTimeFrame)
{
AUDAlarm=true;
CADAlarm=true;
CHFAlarm=true;
EURAlarm=true;
GBPAlarm=true;
JPYAlarm=true;
NZDAlarm=true;
USDAlarm=true;
LastTimeFrame=CalcTF;
}
//--- CheckData
if(TerminalInfoInteger(TERMINAL_CONNECTED) && (LastReason==0 || LastReason==REASON_PARAMETERS))
{
//---
ResetLastError();
//---
for(int i=0; i<ArraySize(UsedSymbols); i++)
{
//---
double test=iHigh(Prefix+UsedSymbols[i]+Suffix,CalcTF,0);
//---
if(test==0)
{
//---
for(int a=0;a<10; a++)
{
//---
Comment("Loading Data...");
Sleep(1);
//---
double _High=iHigh(Prefix+UsedSymbols[i]+Suffix,CalcTF,0);
double _Low=iLow(Prefix+UsedSymbols[i]+Suffix,CalcTF,0);
double _Close=iClose(Prefix+UsedSymbols[i]+Suffix,CalcTF,0);
//---
double _Bid=SymbolInfoDouble(Prefix+UsedSymbols[i]+Suffix,SYMBOL_BID);
double _Ask=SymbolInfoDouble(Prefix+UsedSymbols[i]+Suffix,SYMBOL_ASK);
//---
if(_High!=0 && _Low!=0 && _Close!=0 && _Bid!=0 && _Ask!=0)
break;
}
}
}
//---
Comment("");
}
//--- Init ChartSize
Chart_XSize = (int)ChartGetInteger(0,CHART_WIDTH_IN_PIXELS);
Chart_YSize = (int)ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS);
ChartX=Chart_XSize;
ChartY=Chart_YSize;
//--- CheckSoundIsEnabled
if(!GlobalVariableCheck(OBJPREFIX+"Sound"))
SoundIsEnabled=true;
else
SoundIsEnabled=GlobalVariableGet(OBJPREFIX+"Sound");
//--- Alert
if(!GlobalVariableCheck(OBJPREFIX+"Alarm"))
AlarmIsEnabled=true;
else
AlarmIsEnabled=GlobalVariableGet(OBJPREFIX+"Alarm");
if(!_Alert && !Push && !Mail)
{
//---
AlarmIsEnabled=false;
//---
if(ObjectFind(0,OBJPREFIX+"ALARMIO")==0)
if(ObjectGetInteger(0,OBJPREFIX+"ALARMIO",OBJPROP_COLOR)!=C'59,41,40')
ObjectSetInteger(0,OBJPREFIX+"ALARMIO",OBJPROP_COLOR,C'59,41,40');
}
//---
if(!GlobalVariableCheck(OBJPREFIX+"Dashboard"))
ShowTradePanel=true;
else
ShowTradePanel=GlobalVariableGet(OBJPREFIX+"Dashboard");
//--- Automated SL&TP&Lots
if(!GlobalVariableCheck(OBJPREFIX+"AutoSL"))
AutoSL=false;
else
AutoSL=GlobalVariableGet(OBJPREFIX+"AutoSL");
//---
if(!GlobalVariableCheck(OBJPREFIX+"AutoTP"))
AutoTP=false;
else
AutoTP=GlobalVariableGet(OBJPREFIX+"AutoTP");
//---
if(!GlobalVariableCheck(OBJPREFIX+"AutoLots"))
AutoLots=false;
else
AutoLots=GlobalVariableGet(OBJPREFIX+"AutoLots");
//---
if(!GlobalVariableCheck(OBJPREFIX+"Risk"))
RiskInp=0.25;
else
RiskInp=GlobalVariableGet(OBJPREFIX+"Risk");
//---
if(!GlobalVariableCheck(OBJPREFIX+"RR"))
RR=2;
else
RR=GlobalVariableGet(OBJPREFIX+"RR");
//---
PriceRowLeft=(int)GlobalVariableGet(OBJPREFIX+"PRL");
PriceRowRight=(int)GlobalVariableGet(OBJPREFIX+"PRR");
//---
if(LastReason==0)
ChartGetColor();
//--- Hide OneClick Arrow
ChartSetInteger(0,CHART_SHOW_ONE_CLICK,true);
ChartSetInteger(0,CHART_SHOW_ONE_CLICK,false);
//--- ChartChanged
if(LastReason==REASON_CHARTCHANGE)
_PlaySound("switch.wav");
//---
if(ShowTradePanel)
ChartMouseScrollSet(false);
else
ChartMouseScrollSet(true);
//---
if(ATRMulti<=0)
ATRMulti=0.01;
//---
if(SelectedMode!=LastMode)
ObjectsDeleteAll(0,OBJPREFIX,-1,-1);
//--- Init Speed Prices
for(int i=ArraySize(aSymbols)-1; i>=0; i--)
GlobalVariableSet(OBJPREFIX+Prefix+aSymbols[i]+Suffix+" - Price",(SymbolInfoDouble(Prefix+aSymbols[i]+Suffix,SYMBOL_ASK)+SymbolInfoDouble(Prefix+aSymbols[i]+Suffix,SYMBOL_BID))/2);
//--- Animation
if(LastReason==0 && ShowTradePanel)
{
//---
ObjectsCreateAll();
ObjectSetInteger(0,OBJPREFIX+"PRICEROW_Lª",OBJPROP_COLOR,clrNONE);
ObjectSetInteger(0,OBJPREFIX+"PRICEROW_Rª",OBJPROP_COLOR,clrNONE);
//---
SetStatus("6","Please wait...");
//---
for(int i=ArraySize(aSymbols)-1; i>=0; i--)
{
ObjectSetInteger(0,OBJPREFIX+"SYMBOL§"+" - "+Prefix+aSymbols[i]+Suffix,OBJPROP_COLOR,clrNONE);
ObjectSetInteger(0,OBJPREFIX+"SYMBOL%"+" - "+Prefix+aSymbols[i]+Suffix,OBJPROP_COLOR,clrNONE);
ObjectSetInteger(0,OBJPREFIX+"RANGE₱"+" - "+Prefix+aSymbols[i]+Suffix,OBJPROP_COLOR,clrNONE);
ObjectSetInteger(0,OBJPREFIX+"RANGE%"+" - "+Prefix+aSymbols[i]+Suffix,OBJPROP_COLOR,clrNONE);
ObjectSetInteger(0,OBJPREFIX+"POINTS"+" - "+Prefix+aSymbols[i]+Suffix,OBJPROP_COLOR,clrNONE);
ObjectSetInteger(0,OBJPREFIX+"PROFITS"+" - "+Prefix+aSymbols[i]+Suffix,OBJPROP_COLOR,clrNONE);
ObjectSetInteger(0,OBJPREFIX+"RETURN"+" - "+Prefix+aSymbols[i]+Suffix,OBJPROP_COLOR,clrNONE);
ObjectSetInteger(0,OBJPREFIX+"ASK"+" - "+Prefix+aSymbols[i]+Suffix,OBJPROP_COLOR,clrNONE);
ObjectSetInteger(0,OBJPREFIX+"BID"+" - "+Prefix+aSymbols[i]+Suffix,OBJPROP_COLOR,clrNONE);
ObjectSetInteger(0,OBJPREFIX+"OPENLOTS"+" - "+Prefix+aSymbols[i]+Suffix,OBJPROP_COLOR,clrNONE);
ObjectSetInteger(0,OBJPREFIX+"SPREAD"+" - "+Prefix+aSymbols[i]+Suffix,OBJPROP_COLOR,clrNONE);
}
//---
for(int i=ArraySize(aSymbols)-1; i>=0; i--)
{
//---
for(int x=(10)-1; x>=0; x--)
{
//--- SetObjects
ObjectSetInteger(0,OBJPREFIX+"SPEED#"+" - "+Prefix+aSymbols[i]+Suffix+IntegerToString(x,0,0),OBJPROP_COLOR,COLOR_FONT);
ObjectSetInteger(0,OBJPREFIX+"SYMBOL%"+" - "+Prefix+aSymbols[i]+Suffix,OBJPROP_COLOR,COLOR_FONT);
ObjectSetString(0,OBJPREFIX+"RANGE%"+" - "+Prefix+aSymbols[i]+Suffix,OBJPROP_TEXT,IntegerToString(MathAbs((x-10)*10))+"%");
ObjectSetInteger(0,OBJPREFIX+"RANGE%"+" - "+Prefix+aSymbols[i]+Suffix,OBJPROP_COLOR,COLOR_FONT);
ObjectSetString(0,OBJPREFIX+"SYMBOL%"+" - "+Prefix+aSymbols[i]+Suffix,OBJPROP_TEXT,"Loading...");
ObjectSetInteger(0,OBJPREFIX+"POINTS"+" - "+Prefix+aSymbols[i]+Suffix,OBJPROP_COLOR,COLOR_FONT);
ObjectSetInteger(0,OBJPREFIX+"PROFITS"+" - "+Prefix+aSymbols[i]+Suffix,OBJPROP_COLOR,COLOR_FONT);
ObjectSetInteger(0,OBJPREFIX+"RETURN"+" - "+Prefix+aSymbols[i]+Suffix,OBJPROP_COLOR,COLOR_FONT);
ObjectSetInteger(0,OBJPREFIX+"ASK"+" - "+Prefix+aSymbols[i]+Suffix,OBJPROP_COLOR,COLOR_FONT);
ObjectSetString(0,OBJPREFIX+"ASK"+" - "+Prefix+aSymbols[i]+Suffix,OBJPROP_TEXT,"Ready !");
ObjectSetInteger(0,OBJPREFIX+"BID"+" - "+Prefix+aSymbols[i]+Suffix,OBJPROP_COLOR,COLOR_FONT);
ObjectSetString(0,OBJPREFIX+"BID"+" - "+Prefix+aSymbols[i]+Suffix,OBJPROP_TEXT,"Check");
ObjectSetInteger(0,OBJPREFIX+"OPENLOTS"+" - "+Prefix+aSymbols[i]+Suffix,OBJPROP_COLOR,COLOR_FONT);
ObjectSetInteger(0,OBJPREFIX+"SPREAD"+" - "+Prefix+aSymbols[i]+Suffix,OBJPROP_COLOR,COLOR_FONT);
//---
Comment("");
Sleep(1);
}
}
//---
for(int i=1; i<11; i++)
{
ObjectSetInteger(0,OBJPREFIX+"PB#"+IntegerToString(i)+" - "+"AUD",OBJPROP_COLOR,COLOR_FONT);
ObjectSetInteger(0,OBJPREFIX+"PB#"+IntegerToString(i)+" - "+"CAD",OBJPROP_COLOR,COLOR_FONT);
ObjectSetInteger(0,OBJPREFIX+"PB#"+IntegerToString(i)+" - "+"CHF",OBJPROP_COLOR,COLOR_FONT);
ObjectSetInteger(0,OBJPREFIX+"PB#"+IntegerToString(i)+" - "+"EUR",OBJPROP_COLOR,COLOR_FONT);
ObjectSetInteger(0,OBJPREFIX+"PB#"+IntegerToString(i)+" - "+"GBP",OBJPROP_COLOR,COLOR_FONT);
ObjectSetInteger(0,OBJPREFIX+"PB#"+IntegerToString(i)+" - "+"JPY",OBJPROP_COLOR,COLOR_FONT);
ObjectSetInteger(0,OBJPREFIX+"PB#"+IntegerToString(i)+" - "+"NZD",OBJPROP_COLOR,COLOR_FONT);
ObjectSetInteger(0,OBJPREFIX+"PB#"+IntegerToString(i)+" - "+"USD",OBJPROP_COLOR,COLOR_FONT);
//---
ObjectSetString(0,OBJPREFIX+"AUD%",OBJPROP_TEXT,IntegerToString(MathAbs((i)*10))+"%");
ObjectSetString(0,OBJPREFIX+"CAD%",OBJPROP_TEXT,IntegerToString(MathAbs((i)*10))+"%");
ObjectSetString(0,OBJPREFIX+"CHF%",OBJPROP_TEXT,IntegerToString(MathAbs((i)*10))+"%");
ObjectSetString(0,OBJPREFIX+"EUR%",OBJPROP_TEXT,IntegerToString(MathAbs((i)*10))+"%");
ObjectSetString(0,OBJPREFIX+"GBP%",OBJPROP_TEXT,IntegerToString(MathAbs((i)*10))+"%");
ObjectSetString(0,OBJPREFIX+"JPY%",OBJPROP_TEXT,IntegerToString(MathAbs((i)*10))+"%");
ObjectSetString(0,OBJPREFIX+"NZD%",OBJPROP_TEXT,IntegerToString(MathAbs((i)*10))+"%");
ObjectSetString(0,OBJPREFIX+"USD%",OBJPROP_TEXT,IntegerToString(MathAbs((i)*10))+"%");
//---
Comment("");
Sleep(50);
}
//---
for(int i=0; i<ArraySize(aSymbols); i++)
{
//--- UpdateObjects
ObjectsUpdateAll(Prefix+aSymbols[i]+Suffix);
//--- Get Currencies
double AUD=AUD(),CAD=CAD(),CHF=CHF(),EUR=EUR(),GBP=GBP(),JPY=JPY(),NZD=NZD(),USD=USD();
//---
UpdateProBar("AUD",AUD);
UpdatePercent("AUD",AUD);
UpdateProBar("CAD",CAD);
UpdatePercent("CAD",CAD);
UpdateProBar("CHF",CHF);
UpdatePercent("CHF",CHF);
UpdateProBar("EUR",EUR);
UpdatePercent("EUR",EUR);
UpdateProBar("GBP",GBP);
UpdatePercent("GBP",GBP);
UpdateProBar("JPY",JPY);
UpdatePercent("JPY",JPY);
UpdateProBar("NZD",NZD);
UpdatePercent("NZD",NZD);
UpdateProBar("USD",USD);
UpdatePercent("USD",USD);
//---
GlobalVariableSet(OBJPREFIX+Prefix+aSymbols[i]+Suffix+" - Price",(SymbolInfoDouble(Prefix+aSymbols[i]+Suffix,SYMBOL_ASK)+SymbolInfoDouble(Prefix+aSymbols[i]+Suffix,SYMBOL_BID))/2);
//---
for(int x=0; x<(10); x++)
{
//---
double percent=StringToDouble(ObjectGetString(0,OBJPREFIX+"SYMBOL%"+" - "+Prefix+aSymbols[i]+Suffix,OBJPROP_TEXT));
//---
ObjectSetInteger(0,OBJPREFIX+"SPEED#"+" - "+Prefix+aSymbols[i]+Suffix+IntegerToString(x,0,0),OBJPROP_COLOR,±ClrBR(percent));
}
ObjectSetInteger(0,OBJPREFIX+"PRICEROW_Lª",OBJPROP_COLOR,COLOR_FONT);
ObjectSetInteger(0,OBJPREFIX+"PRICEROW_Rª",OBJPROP_COLOR,COLOR_FONT);
ObjectSetInteger(0,OBJPREFIX+"RANGE₱"+" - "+Prefix+aSymbols[i]+Suffix,OBJPROP_COLOR,COLOR_FONT);
//---
Comment("");
Sleep(50);
}
//---
ResetStatus();
//---
}
//---
FirstRun=false;
//--- Dropped Time
drop_time=TimeLocal();
//--- Border Color
if(ShowTradePanel)
{
//---
if(ObjectFind(0,OBJPREFIX+"BORDER[]")==0 || ObjectFind(0,OBJPREFIX+"BCKGRND[]")==0)
{
//---
if(ObjectGetInteger(0,OBJPREFIX+"BORDER[]",OBJPROP_COLOR)!=COLOR_BORDER)
{
ObjectSetInteger(0,OBJPREFIX+"BORDER[]",OBJPROP_COLOR,COLOR_BORDER);
ObjectSetInteger(0,OBJPREFIX+"BORDER[]",OBJPROP_BGCOLOR,COLOR_BORDER);
ObjectSetInteger(0,OBJPREFIX+"BCKGRND[]",OBJPROP_COLOR,COLOR_BORDER);
}
}
}
//---
if(!ShowTradePanel)
{
//---
if(ObjectFind(0,OBJPREFIX+"MIN"+"BCKGRND[]")==0)
{
//---
if(ObjectGetInteger(0,OBJPREFIX+"MIN"+"BCKGRND[]",OBJPROP_COLOR)!=COLOR_BORDER)
{
ObjectSetInteger(0,OBJPREFIX+"MIN"+"BCKGRND[]",OBJPROP_COLOR,COLOR_BORDER);
ObjectSetInteger(0,OBJPREFIX+"MIN"+"BCKGRND[]",OBJPROP_BGCOLOR,COLOR_BORDER);
}
}
}
//----
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---- DestroyTimer
EventKillTimer();
//--- Save global variables
if(reason!=REASON_INITFAILED && !MQLInfoInteger(MQL_TESTER))
{
//---
for(int i=0; i<ArraySize(aSymbols); i++)
{
//---
GlobalVariableDel(Prefix+aSymbols[i]+Suffix+" - Price");
//---
if(ShowTradePanel)
{
GlobalVariableSet(OBJPREFIX+Prefix+aSymbols[i]+Suffix+" - Stoploss",StringToDouble(ObjectGetString(0,OBJPREFIX+"SL<>"+" - "+Prefix+aSymbols[i]+Suffix,OBJPROP_TEXT)));
GlobalVariableSet(OBJPREFIX+Prefix+aSymbols[i]+Suffix+" - Takeprofit",StringToDouble(ObjectGetString(0,OBJPREFIX+"_TP<>"+" - "+Prefix+aSymbols[i]+Suffix,OBJPROP_TEXT)));
GlobalVariableSet(OBJPREFIX+Prefix+aSymbols[i]+Suffix+" - Lotsize",StringToDouble(ObjectGetString(0,OBJPREFIX+"LOTSIZE<>"+" - "+Prefix+aSymbols[i]+Suffix,OBJPROP_TEXT)));
}
}
//---
if(ShowTradePanel)
{
GlobalVariableSet(OBJPREFIX+"Stoploss",StringToDouble(ObjectGetString(0,OBJPREFIX+"SL<>",OBJPROP_TEXT)));
GlobalVariableSet(OBJPREFIX+"Takeprofit",StringToDouble(ObjectGetString(0,OBJPREFIX+"_TP<>",OBJPROP_TEXT)));
GlobalVariableSet(OBJPREFIX+"Lotsize",StringToDouble(ObjectGetString(0,OBJPREFIX+"LOTSIZE<>",OBJPROP_TEXT)));
}
//---
GlobalVariableSet(OBJPREFIX+"Theme",SelectedTheme);
//---
GlobalVariableSet(OBJPREFIX+"Dashboard",ShowTradePanel);
//---
GlobalVariableSet(OBJPREFIX+"Sound",SoundIsEnabled);
//---
GlobalVariableSet(OBJPREFIX+"Alarm",AlarmIsEnabled);
//---
GlobalVariableSet(OBJPREFIX+"AutoSL",AutoSL);
GlobalVariableSet(OBJPREFIX+"AutoTP",AutoTP);
GlobalVariableSet(OBJPREFIX+"AutoLots",AutoLots);
//---
GlobalVariableSet(OBJPREFIX+"RR",RR);
GlobalVariableSet(OBJPREFIX+"Risk",RiskInp);
//---
GlobalVariableSet(OBJPREFIX+"PRL",PriceRowLeft);
GlobalVariableSet(OBJPREFIX+"PRR",PriceRowRight);
//---
GlobalVariablesFlush();
}
//--- DeleteObjects
if(reason<=REASON_REMOVE || reason==REASON_CLOSE || reason==REASON_RECOMPILE || reason==REASON_INITFAILED || reason==REASON_ACCOUNT)
{
ObjectsDeleteAll(0,OBJPREFIX,-1,-1);
DelteMinWindow();
}
//---
if(reason<=REASON_REMOVE || reason==REASON_CLOSE || reason==REASON_RECOMPILE)
{
//---
if(ClearedTemplate)
ChartSetColor(2);
}
//--- UnblockScrolling
ChartMouseScrollSet(true);
//--- UserIsRegistred
if(!GlobalVariableCheck(OBJPREFIX+"Registred"))
GlobalVariableSet(OBJPREFIX+"Registred",1);
//---
LastMode=SelectedMode;
//--- StoreDeinitReason
LastReason=reason;
//----
}
//+------------------------------------------------------------------+
//| Timer function |
//+------------------------------------------------------------------+
void OnTimer()
{
//----
if(PairSuggest)
ResetTrigger();
//---
if(ArraySize(aSymbols)>ArraySize(UsedSymbols))
{
//---
for(int i=0; i<ArraySize(aSymbols); i++)
SpeedOmeter(Prefix+aSymbols[i]+Suffix);
}
else
{
//---
for(int i=0; i<ArraySize(UsedSymbols); i++)
SpeedOmeter(Prefix+UsedSymbols[i]+Suffix);
}
//--- Alert
if(drop_time<TimeLocal()-15)
{
//---
if((CalcPeriod==DAILY && Hour()>=4) || (CalcPeriod==WEEKLY && TimeDayOfWeek(TimeCurrent())>=2) || (CalcPeriod==MONTHLY && Day()>=4))
Alert();
}
//---
if(ShowTradePanel)
{
//---
ObjectsCreateAll();
//---
for(int i=0; i<ArraySize(aSymbols); i++)
{
ObjectsUpdateAll(Prefix+aSymbols[i]+Suffix);
GetSetInputs(Prefix+aSymbols[i]+Suffix);
}
//---
GetSetInputsA();
//---
OverAllInfo();
//---
CStrenghts();
//--- MoveWindow
if(LastReason==REASON_CHARTCHANGE)
{
Chart_XSize=(int)ChartGetInteger(0,CHART_WIDTH_IN_PIXELS);
Chart_YSize=(int)ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS);
//---
ChartX=Chart_XSize;
ChartY=Chart_YSize;
//---
LastReason=0;
}
//---
if(ChartX!=Chart_XSize || ChartY!=Chart_YSize)
{
ObjectsDeleteAll(0,OBJPREFIX,-1,-1);
//---
ObjectsCreateAll();
//---
ChartX=Chart_XSize;
ChartY=Chart_YSize;
}
//---
Chart_XSize=(int)ChartGetInteger(0,CHART_WIDTH_IN_PIXELS);
Chart_YSize=(int)ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS);
//--- Connected
if(TerminalInfoInteger(TERMINAL_CONNECTED))
{
//---
if(ObjectGetString(0,OBJPREFIX+"CONNECTION",OBJPROP_TEXT)!="ü")//GetObject
ObjectSetString(0,OBJPREFIX+"CONNECTION",OBJPROP_TEXT,"ü");//SetObject
//---
if(ObjectGetString(0,OBJPREFIX+"CONNECTION",OBJPROP_TOOLTIP)!="Connected")//GetObject
{
double Ping=TerminalInfoInteger(TERMINAL_PING_LAST);//SetPingToMs
ObjectSetString(0,OBJPREFIX+"CONNECTION",OBJPROP_TOOLTIP,"Connected..."+"\nPing: "+DoubleToString(Ping/1000,2)+" ms");//SetObject
}
}
//--- Disconnected
else
{
//---
if(ObjectGetString(0,OBJPREFIX+"CONNECTION",OBJPROP_TEXT)!="ñ")//GetObject
ObjectSetString(0,OBJPREFIX+"CONNECTION",OBJPROP_TEXT,"ñ");//SetObject
//---
if(ObjectGetString(0,OBJPREFIX+"CONNECTION",OBJPROP_TOOLTIP)!="No connection!")//GetObject
ObjectSetString(0,OBJPREFIX+"CONNECTION",OBJPROP_TOOLTIP,"No connection!");//SetObject
}
//--- ResetStatus
if(stauts_time<TimeLocal()-1)
ResetStatus();
//---
Comment("");
ChartRedraw();
}
else
CreateMinWindow();
//----
}
//+------------------------------------------------------------------+
//| ChartEvent function |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
const long &lparam,
const double &dparam,
const string &sparam)
{
//----
if(id==CHARTEVENT_KEYDOWN)
{
//---
if(KeyboardTrading)
{
//---
if(lparam==StringGetChar(BuyKey,0))
{
//--- SendSellOrder
OrderSend(_Symbol,OP_BUY);
//--- ResetButton
ObjectSetInteger(0,OBJPREFIX+"BUY"+" - "+_Symbol,OBJPROP_STATE,false);//SetObject
}
//---
if(lparam==StringGetChar(SellKey,0))
{
//--- SendSellOrder
OrderSend(_Symbol,OP_SELL);
//--- ResetButton
ObjectSetInteger(0,OBJPREFIX+"SELL"+" - "+_Symbol,OBJPROP_STATE,false);//SetObject
}
//---
if(lparam==StringGetChar(CloseKey,0))
{
//--- NoOrders
if(OpenPos(_Symbol,OP_ALL)==0)
{
//---
SetStatus("ý","No open orders...");
Sleep(100);
//---
ObjectSetInteger(0,OBJPREFIX+"CLOSE"+" - "+_Symbol,OBJPROP_STATE,false);//SetObject
}
//--- CloseOrder(s)
OrderClose(_Symbol);
//--- ResetButton
ObjectSetInteger(0,OBJPREFIX+"CLOSE"+" - "+_Symbol,OBJPROP_STATE,false);//SetObject
}
//--- Switch Symbol (UP)
if(lparam==KEY_UP)
{
//---
int index=0;
//---
for(int i=0; i<ArraySize(aSymbols); i++)
{
if(_Symbol==Prefix+aSymbols[i]+Suffix)
{
//---
index=i-1;
//---
if(index<0)
index=ArraySize(aSymbols)-1;
//---
if(SymbolFind(Prefix+aSymbols[index]+Suffix,false))
{
ChartSetSymbolPeriod(0,Prefix+aSymbols[index]+Suffix,PERIOD_CURRENT);
SetStatus("ÿ","Switched to "+aSymbols[index]);
break;
}
}
}
}
//--- Switch Symbol (DOWN)
if(lparam==KEY_DOWN)
{
//---
int index=0;
//---
for(int i=0; i<ArraySize(aSymbols); i++)
{
//---
if(_Symbol==Prefix+aSymbols[i]+Suffix)
{
//---
index=i+1;
//---
if(index>=ArraySize(aSymbols))
index=0;
//---
if(SymbolFind(Prefix+aSymbols[index]+Suffix,false))
{
ChartSetSymbolPeriod(0,Prefix+aSymbols[index]+Suffix,PERIOD_CURRENT);
SetStatus("ÿ","Switched to "+aSymbols[index]);
break;
}
}
}
}
}
}
//--- OBJ_CLICKS