-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIbrkthrough.mq5
More file actions
1335 lines (968 loc) · 60.1 KB
/
Ibrkthrough.mq5
File metadata and controls
1335 lines (968 loc) · 60.1 KB
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
//+------------------------------------------------------------------+
//| Ibrkthrough.mq5 |
//| Copyright 2024, kayc Ltd. |
//| kayc.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, kayc Ltd."
#property link "kayc.com"
#property version "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
#include <Trade\Trade.mqh>
#include <Ibrk.mqh>
//#include <MQL5Book/ChartModeMonitor.mqh>
#define Bid tickd("bid",_Symbol)
#define Ask tickd("ask",_Symbol)
//+------------------------------------------------------------------+
input group "";
input group "====== General Settings ====";
input string ProductKey = "V10N-CD56-EU12-JP89-FR74-MN23";
input bool AllowSignalTG = true;
input bool allowWeekend = false;
input double PercentEquityUseable = 1.3; // Acc Risk % per Trade (min 2%)
input double Minlot = 0.01;
input double Maxlot = 100.0;
input double fixedlots = 0;
input int farBackSet=400;
input int alarmExpin=3;
input int ExpireSec = 3500;
//+------------------------------------------------------------------+
input group "====== Sar Settings ====";
input double sarStep = 0.01;//0.0065;
input double sarMax = 0.2;
double buyerBoxPercent = 0.545,sellerBoxPercent = 0.20, lastgroupVolbuy[99],lastgroupVolsell[99],dayvolsupport=0.0,daybrksupport=0.0,lastsarcap[10];
double emaShort[99999], emaLong[99999],lastDealP,daybrken[10],emaShort1,
onPrevVal[100],maxdayloss=0.0,targetprofit=0.0,maxdaytrades=0,xframeH[999],xframeL[999],
optH[1000],optL[1000],optH2[1000],optL2[1000],lastvolsupport[10],alarm[1000],positionEx[1000];
int Magic = MathRand(),EMA_Short = 10,BB = 0,BB4hr = 0,BB1d = 0,BB2 = 0,BB3=0,chgDealP=0,adjonline=0,E3adj=0,countinday=0,countin4h=0,onPrev[100],sarstage=0,voldirec=0,alarmState[1000],alarmExp[1000],
predictedNy=0,stagecount=0,mastage=0,nextentry=0,mafirst=0,optAtr[200],last4mixedvol[99],
optVw1[1000],optVw2[1000],optVl[1000],optVl2[1000],lastcandlestckpattrn[10],last1hrdirec[10],last4hrdirec[10],lastoveralldirc[10],lastvoldirec[10],lastsardirc[10],confirmE[200],isswing=0,istrueedge[100],
onlyalloweddirc[10],Oallow[10],positionExTYP[1000];
string entryCom[10],startdatee="",tgId = "-100217446", tgToken = "7452458:AAGBEyQZo0rQCdWR6Y_HFjwKM";
ulong Epending[100],EEE[100],positionExT[1000];
int firstdiscount=0,sar,maH,maL,ma200,sarZone[100],E4ok=0,E2ok=0,E2okpending=0,nyday=0,londonday=0,min1Dvol=0,min30vol=0,min15vol=0,min4Hvol=0,
trendOn=0,trendIs=0,barTotal,barDailyTotal,bar4Hour,bar3min,bar1Hour,bar30min,bar30minTotal,avZ[5],volINST[4],volOverall=0,volINSTD[4],volOverallD=0,dayOverall=0,hourOverall=0,dailyTradeLog=0,firstOnHour=0,liveZone=0;
double zone[1000000],initialBal = 0.0,Lots=Minlot,equity = (double)initialBal * (double)PercentEquityUseable/100,point=0.0,E2okstop=0.0,E2okentry=0.0,hrhrange=0.0,hrlrange=0.0,dayhrange=0.0,
daylrange=0.0,hrlyatr=0.0,hrly1atr=0.0,min30atr=0.0,dailyatr=0.0,min15atr=0.0,bagVal[100],trending1=0.0,trending2=0.0,entrySL[10],entryTP[10],entryP[10],needbrk=0.0,stopline=0.0,E4okentry=0.0;
bool firstTick=false;
datetime entryExp[10];
ENUM_TIMEFRAMES timeF = PERIOD_CURRENT,alarmPERIOD[1000];
int check[100],bag[100],bagPE[100],bagStat[100],action=0,swit=0,wilup=0,entryType[10],yesbrk=0,activeTrend=1,newbox=0,posi1Chg=0,posi2Chg=0,usedbox=0,firsttbox=0,noentry =0,isFirst=0,posiLine=0;
bool makevoid=false,MrkOpen=allowWeekend;
string alarmSysm[1000],positionExSym[1000];
CTrade trade;
CGraphicalPanel panel;
int OnInit()
{
initialBal=AccountInfoDouble(ACCOUNT_EQUITY);
if(ProductKey != "V10N-CD56-EU12-JP89-FR74-MN23") {initialBal=0;Comment(" ERROR :: Invalid Access Key !");}
if(ProductKey != "V10N-CD56-EU12-JP89-FR74-MN23") {return (INIT_FAILED);}
if(Period() != PERIOD_M15) {Comment(" ERROR :: Invalid Timeframe, Please Switch from ",timeF," to PERIOD_M15 !");}
if(Period() != PERIOD_M15) {return (INIT_FAILED);}
//if(initialBal <= 0 || AccountInfoDouble(ACCOUNT_EQUITY) < initialBal) {Print("Account bal Less than BalSet. Topup account. or reduce BalSet!");return (INIT_FAILED);}
Print("[Init success] Date: "+TimeToString(TimeCurrent(), TIME_DATE|TIME_MINUTES));
startdatee=TimeToString(TimeCurrent(), TIME_DATE|TIME_MINUTES);
Print("isTrade Session Open?: ", trade_session());
MrkOpen=trade_session();
//
// if(!CheckInputs()){return INIT_PARAMETERS_INCORRECT;}
//create panel
if(!panel.OnInit()){return INIT_FAILED;}
trade.SetExpertMagicNumber(Magic);
//handleVol = ;//iVolumes(_Symbol,PERIOD_M5,VOLUME_REAL);
ChartSetInteger(0,CHART_SHOW_VOLUMES,CHART_VOLUME_TICK);
ChartSetInteger(0,CHART_MODE,CHART_LINE);
ChartSetInteger(0,CHART_AUTOSCROLL,true);
ChartSetInteger(0,CHART_SHOW_GRID,false);
ChartSetInteger(0,CHART_SHOW_PERIOD_SEP,false);
ChartSetInteger(0,CHART_SHIFT,30);
ChartSetDouble(0,CHART_SHIFT_SIZE,30);
ChartSetInteger(0,CHART_DRAG_TRADE_LEVELS,true);
ChartSetInteger(0,CHART_SHOW_TICKER,true);
ChartSetInteger(0,CHART_SHOW_OHLC,true);
ChartSetInteger(0,CHART_SHOW_PERIOD_SEP,true);
ChartSetInteger(0,CHART_COLOR_CHART_LINE,clrAzure);
ChartSetInteger(0,CHART_SHOW_ASK_LINE,true);
ChartSetInteger(0,CHART_COLOR_ASK,clrBisque);
//int flags[] = {
// 2,CHART_FOREGROUND,50,false
//};
// ChartModeMonitor m(flags);
//ChartSetDouble(0,CHART_LINE,2);
sar = iSAR(NULL, PERIOD_CURRENT,sarStep,sarMax);
maH = iMA(NULL, PERIOD_CURRENT, 1, 0, MODE_EMA, PRICE_HIGH);
maL = iMA(NULL, PERIOD_CURRENT, 1, 0, MODE_EMA, PRICE_LOW);
ma200 = iMA(NULL, PERIOD_CURRENT, 200, 0, MODE_EMA, PRICE_CLOSE);
int barTotal = iBars(NULL,PERIOD_CURRENT),bar3min=iBars(NULL,PERIOD_M3),barDailyTotal=iBars(NULL,PERIOD_D1);
int VDDDV = 10;
for(int vDigits = _Digits; vDigits > 1; vDigits--){VDDDV=VDDDV*10;}
point=(double)1/VDDDV;
printf("ACCOUNT_LOGIN = %d",AccountInfoInteger(ACCOUNT_LOGIN));
printf("ACCOUNT_LEVERAGE = %d",AccountInfoInteger(ACCOUNT_LEVERAGE));
bool thisAccountTradeAllowed=AccountInfoInteger(ACCOUNT_TRADE_ALLOWED);
bool EATradeAllowed=AccountInfoInteger(ACCOUNT_TRADE_EXPERT);
ENUM_ACCOUNT_TRADE_MODE tradeMode=(ENUM_ACCOUNT_TRADE_MODE)AccountInfoInteger(ACCOUNT_TRADE_MODE);
ENUM_ACCOUNT_STOPOUT_MODE stopOutMode=(ENUM_ACCOUNT_STOPOUT_MODE)AccountInfoInteger(ACCOUNT_MARGIN_SO_MODE);
//--- Inform about the possibility to perform a trade operation
if(thisAccountTradeAllowed)
Print("Trade for this account is permitted");
else
Print("Trade for this account is prohibited!");
//--- Find out if it is possible to trade on this account by Expert Advisors
if(EATradeAllowed)
Print("Trade by Expert Advisors is permitted for this account");
else
Print("Trade by Expert Advisors is prohibited for this account!");
//--- Find out the account type
switch(tradeMode)
{
case(ACCOUNT_TRADE_MODE_DEMO):
Print("This is a demo account");
break;
case(ACCOUNT_TRADE_MODE_CONTEST):
Print("This is a competition account");
break;
default:Print("This is a real account!");
}
//--- Find out the StopOut level setting mode
switch(stopOutMode)
{
case(ACCOUNT_STOPOUT_MODE_PERCENT):
Print("The StopOut level is specified percentage");
break;
default:Print("The StopOut level is specified in monetary terms");
}
/*
if(firstTick == false){firstTick = true;
int vxi=0;
while(vxi != 1){if(Magic > 9999 || Magic < 1000){Magic=MathRand();}else{vxi=1;}}
// strategy();
//runner back
int Hc = farBackSet-1,Oc=1;
double slowoSar[9999];
CopyBuffer(sar,0,1,farBackSet,slowoSar);
ArraySetAsSeries(slowoSar,true);
double emaL[9999],emaH[9999];
CopyBuffer(maL,0,1,farBackSet,emaL);
ArraySetAsSeries(emaL,true);
CopyBuffer(maH,0,1,farBackSet,emaH);
ArraySetAsSeries(emaH,true);
for(int Lc = Hc; Lc >= 1; Lc--){
int ck = (farBackSet-1)-Oc;
double cot = slowoSar[Lc];
strategy(slowoSar[Oc],Lc,Oc,emaH[Oc],emaL[Oc],emaH[Oc-1],emaL[Oc-1],Lc);//slowoMa[Lc]//ck/lc
Hc -= 1;
Oc += 1;
}
}//runerbackk end
*/
ArraySetAsSeries(entryType,true);
ArraySetAsSeries(entryExp,true);
ArraySetAsSeries(entryP,true);
ArraySetAsSeries(entrySL,true);
ArraySetAsSeries(entryTP,true);
ArraySetAsSeries(entryCom,true);
ArraySetAsSeries(alarm,true);
ArraySetAsSeries(alarmSysm,true);
ArraySetAsSeries(alarmState,true);
ArraySetAsSeries(alarmPERIOD,true);
ArraySetAsSeries(alarmExp,true);
ArraySetAsSeries(positionExSym,true);
ArraySetAsSeries(positionEx,true);
ArraySetAsSeries(positionExTYP,true);
ArraySetAsSeries(positionExT,true);
EventSetTimer(1);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//logger();
//report to telegrem progrem on sysbol exited/closed.
//
EventKillTimer();
//panel.Destroy(reason);
Print("[Logged out] log: "+IntegerToString(reason)+" |Date| From: "+startdatee+" To: "+TimeToString(TimeCurrent(), TIME_DATE|TIME_MINUTES));
//ObjectsDeleteAll(0);
}
void OnTimer()
{
//check for changes in price accross alerms
int totalalarm=0;
for(int ni =0;ni < 999;ni++){
if(alarm[ni] > 0.0){totalalarm+=1;}
}
for(int ni =0;ni < 999;ni++){
if(alarm[ni] > 0.0 && alarmSysm[ni] != ""){
double tiik=0.0;
if(SymbolSelect(alarmSysm[ni],true)){
MqlTick tick;
if(SymbolInfoTick(alarmSysm[ni], tick)){
tiik=tick.bid;
// Print("tick('bid',alarmSysm[ni]) < alarm[ni]",tiik," < ",alarm[ni]," , alarmState[ni] ",alarmState[ni]," alarmSysm[ni] ",alarmSysm[ni]);
}
}
if(alarmState[ni] == 1 && tiik > alarm[ni] && tiik > 0.0){
//send msg
string texts = "⛵ Alarm! Price at "+DoubleToString(alarm[ni])+" :: "+(string)alarmSysm[ni]+" | "+
" Total alarm: ("+totalalarm+") (ACCT: "+IntegerToString(AccountInfoInteger(ACCOUNT_LOGIN))+" :: "+AccountInfoString(ACCOUNT_NAME)+")";
if(AllowSignalTG){ Print(" TG Requst: ",(string)sendMessage(texts,tgId,tgToken));
alarm[ni]=0.0;alarmState[ni]=0;alarmSysm[ni]="";alarmExp[ni]=0;alarmPERIOD[ni]=0;}
}else if(alarmState[ni] == 2 && tiik < alarm[ni] && tiik > 0.0){
//send msg
string texts = "⛵ Alarm! Price at "+DoubleToString(alarm[ni])+" :: "+(string)alarmSysm[ni]+" | "+
" Total alarm: ("+totalalarm+") (ACCT: "+IntegerToString(AccountInfoInteger(ACCOUNT_LOGIN))+" :: "+AccountInfoString(ACCOUNT_NAME)+")";
if(AllowSignalTG){ Print(" TG Requst: ",(string)sendMessage(texts,tgId,tgToken));
alarm[ni]=0.0;alarmState[ni]=0;alarmSysm[ni]="";alarmExp[ni]=0;alarmPERIOD[ni]=0;}
/////////////////////////
}else if(alarmState[ni] == 3 && close(1,alarmPERIOD[ni],alarmSysm[ni]) > alarm[ni]){
//send msg
string texts = "⛵ Alarm! Price Closed for "+DoubleToString(alarm[ni])+" :: "+(string)alarmSysm[ni]+" | "+
" Total alarm: ("+totalalarm+") (ACCT: "+IntegerToString(AccountInfoInteger(ACCOUNT_LOGIN))+" :: "+AccountInfoString(ACCOUNT_NAME)+")";
if(AllowSignalTG){ Print(" TG Requst: ",(string)sendMessage(texts,tgId,tgToken));
alarm[ni]=0.0;alarmState[ni]=0;alarmSysm[ni]="";alarmExp[ni]=0;alarmPERIOD[ni]=0;}
}else if(alarmState[ni] == 4 && close(1,alarmPERIOD[ni],alarmSysm[ni]) < alarm[ni]){
//send msg
string texts = "⛵ Alarm! Price Closed for "+DoubleToString(alarm[ni])+" :: "+(string)alarmSysm[ni]+" | "+
" Total alarm: ("+totalalarm+") (ACCT: "+IntegerToString(AccountInfoInteger(ACCOUNT_LOGIN))+" :: "+AccountInfoString(ACCOUNT_NAME)+")";
if(AllowSignalTG){ Print(" TG Requst: ",(string)sendMessage(texts,tgId,tgToken));
alarm[ni]=0.0;alarmState[ni]=0;alarmSysm[ni]="";alarmExp[ni]=0;alarmPERIOD[ni]=0;}
}
}
}
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
//if(initialBal <= 0 || AccountInfoDouble(ACCOUNT_EQUITY) < initialBal) {OnDeinit(55555);}
int bars = iBars(NULL, timeF), min3Bars=iBars(NULL,PERIOD_M3),barDaily=iBars(NULL,PERIOD_D1);
if(firstTick == false){firstTick = true;
Print(" TG Requst: ",(string)sendMessage("..Online (ACCT: "+AccountInfoInteger(ACCOUNT_LOGIN)+" :: "+AccountInfoString(ACCOUNT_NAME)+"):"+TimeToString(TimeCurrent()-10000, TIME_DATE)+" [ "+_Symbol+", Lots: "+Lots+" ] [ ",tgId,tgToken));
int vxi=0;
while(vxi != 1){if(Magic > 9999 || Magic < 1000){Magic=MathRand();}else{vxi=1;}}
// strategy();
//runner back
int Hc = farBackSet-1,Oc=1;
double slowoSar[9999];
CopyBuffer(sar,0,1,farBackSet,slowoSar);
ArraySetAsSeries(slowoSar,true);
double emaL[9999],emaH[9999];
CopyBuffer(maL,0,1,farBackSet,emaL);
ArraySetAsSeries(emaL,true);
CopyBuffer(maH,0,1,farBackSet,emaH);
ArraySetAsSeries(emaH,true);
for(int Lc = Hc; Lc >= 1; Lc--){
int ck = (farBackSet-1)-Oc;
double cot = slowoSar[Lc];
//strategy(slowoSar[Oc],Lc,Oc,emaH[Oc],emaL[Oc],emaH[Oc-1],emaL[Oc-1],Lc);//slowoMa[Lc]//ck/lc
Hc -= 1;
Oc += 1;
}
}//runerbackk end
//+------------------------------------------------------------------+
//---Daily
if(barDailyTotal != barDaily){
barDailyTotal=barDaily;
//---
for(int in=0;in<999;in++){
if(alarmExp[in] > 0){alarmExp[in]-=1;}
if(alarmExp[in] == 0){alarm[in]=0.0;alarmState[in]=0;alarmSysm[in]="";alarmPERIOD[in]=0;}
}
ENUM_TIMEFRAMES tim = PERIOD_D1;
}
//m3 confirmation
//+------------------------------------------------------------------+
//---3min start
if(bar3min != min3Bars){
bar3min=min3Bars;
//---
ENUM_TIMEFRAMES tim = PERIOD_M3;
}
/////////////////////////////////////////////////////////////////
if(barTotal != bars){
barTotal=bars;
//Print("period_m15 "+PERIOD_M3+" period_h1 "+PERIOD_H1+" preiod() "+);
for(int in=1;in<=10;in++){
//
if(confirmE[(int)(in*10)+2] >= 1){confirmE[(int)(in*10)+2]-=1;}
//
}
double emaL[9999],emaH[9999];
CopyBuffer(maL,0,1,2,emaL);
ArraySetAsSeries(emaL,true);
CopyBuffer(maH,0,1,2,emaH);
ArraySetAsSeries(emaH,true);
//strategy(sar_val(1),1,1,emaH[1],emaL[1],emaH[0],emaL[0]);
}
/////////////////////////////////////////////////////////////////
datetime asianStart = StringToTime("00:00"); // Asian session start
datetime asianEnd = StringToTime("06:00"); // 6:00 Asian session end
datetime londonStart = StringToTime("07:00"); // 7:00 London session start
datetime londonEnd = StringToTime("16:00"); // 16:00 London session end
datetime newyorkStart = StringToTime("13:00");// 13:00 New York session start
datetime newyorkEnd = StringToTime("21:00"); // 21:00 New York session end
//OrdersTotal()
//---
if(OrdersTotal() > 0){
for (int pos_0 = OrdersTotal()-1; pos_0 >= 0; pos_0--) {
ulong orderTicket = OrderGetTicket(pos_0);
//---
//if(OrderGetString(ORDER_SYMBOL) != _Symbol){continue;}
//if(OrderGetInteger(ORDER_MAGIC) != Magic){continue;}
//---
datetime expiration = TimeCurrent()+ExpireSec;
if((OrderGetString(ORDER_COMMENT) == "")){
double sslss=0.0,openp=0.0,ttpp=0.0;
string sysm="";
//check for changes in price accross alerms
int totalalarm=0;
for(int ni =0;ni < 999;ni++){
if(alarm[ni] > 0.0){totalalarm+=1;}
}
if(OrderSelect(orderTicket)){
sslss=OrderGetDouble(ORDER_SL);openp=OrderGetDouble(ORDER_PRICE_OPEN);ttpp=OrderGetDouble(ORDER_TP);sysm=OrderGetString(ORDER_SYMBOL);}
if(OrderGetInteger(ORDER_TYPE) == ORDER_TYPE_BUY_STOP && sslss > 0.0){
getLots(openp-sslss,sysm);
entryType[2]=1;entryP[2]=openp;entrySL[2]=sslss;entryTP[2]=entryP[2]+((entryP[2]-entrySL[2])*2);entryExp[2]=expiration;entryCom[2]="IBRK1";//1:1
trade.OrderDelete(orderTicket);
entires(Lots,sysm);
continue;
//entryType[2]=1;entryP[2]=OrderGetDouble(ORDER_PRICE_OPEN);entrySL[2]=OrderGetDouble(ORDER_SL);entryTP[2]=entryP[2]+((entryP[2]-entrySL[2])*2.3);entryExp[2]=expiration;entryCom[2]="IBRK2";//1:1.3
//entires(Lots/4.0,OrderGetString(ORDER_SYMBOL));
//entryType[2]=1;entryP[2]=OrderGetDouble(ORDER_PRICE_OPEN);entrySL[2]=OrderGetDouble(ORDER_SL);entryTP[2]=0.0;entryExp[2]=expiration;entryCom[2]="IBRK3";//x
//entires(Lots/2.0,OrderGetString(ORDER_SYMBOL));
}else if(OrderGetInteger(ORDER_TYPE) == ORDER_TYPE_SELL_STOP && sslss > 0.0){
getLots(sslss-openp,sysm);
entryType[2]=2;entryP[2]=openp;entrySL[2]=sslss;entryTP[2]=entryP[2]-((entrySL[2]-entryP[2])*2);entryExp[2]=expiration;entryCom[2]="IBRK1";//1:1
trade.OrderDelete(orderTicket);
entires(Lots,sysm);
continue;
//entryType[2]=2;entryP[2]=OrderGetDouble(ORDER_PRICE_OPEN);entrySL[2]=OrderGetDouble(ORDER_SL);entryTP[2]=entryP[2]-((entrySL[2]-entryP[2])*2.3);entryExp[2]=expiration;entryCom[2]="IBRK2";//1:1.3
//entires(Lots/4.0,OrderGetString(ORDER_SYMBOL));
//entryType[2]=2;entryP[2]=OrderGetDouble(ORDER_PRICE_OPEN);entrySL[2]=OrderGetDouble(ORDER_SL);entryTP[2]=0.0;entryExp[2]=expiration;entryCom[2]="IBRK3";//x
//entires(Lots/2.0,OrderGetString(ORDER_SYMBOL));
}else if(OrderGetInteger(ORDER_TYPE) == ORDER_TYPE_BUY_LIMIT){
//
bool alarmok = true;
for(int in=0;in < 999;in++){
if(alarm[in] == openp && alarmSysm[in] == sysm){
alarmok=false; alarm[in]=0.0;alarmState[in]=0;alarmSysm[in]="";alarmExp[in]=0; alarmPERIOD[in]=0;
}
}
if(alarmok){
for(int in=0;in < 999;in++){
if(alarm[in] <= 0.0 && alarmSysm[in] == ""){
alarm[in]=openp;
alarmSysm[in]=sysm;
alarmState[in]=2;
alarmExp[in]=alarmExpin;
alarmPERIOD[in]=PERIOD_CURRENT;
if(ttpp > 0.0){
//tp set = wait for close below .15min
alarmState[in]=4;
}
string statee=(alarmState[in] == 2)? "onTick" : "onClose" ;
string texts = "🌐 Alarm SET at Price "+DoubleToString(alarm[in])+" :: "+(string)alarmSysm[in]+" ~ Type: "+statee+" :: Total alarm: ("+(totalalarm+1)+") (ACCT: "+IntegerToString(AccountInfoInteger(ACCOUNT_LOGIN))+" :: "+AccountInfoString(ACCOUNT_NAME)+")";
if(AllowSignalTG){ Print(" TG Requst: ",(string)sendMessage(texts,tgId,tgToken)); }
break;
}
}
}
}else if(OrderGetInteger(ORDER_TYPE) == ORDER_TYPE_SELL_LIMIT){
//
bool alarmok = true;
for(int in=0;in < 999;in++){
if(alarm[in] == openp && alarmSysm[in] == sysm){
alarmok=false; alarm[in]=0.0;alarmState[in]=0;alarmSysm[in]="";alarmExp[in]=0;alarmPERIOD[in]=0;
}
}
if(alarmok){
for(int in=0;in < 999;in++){
if(alarm[in] <= 0.0 && alarmSysm[in] == ""){
alarm[in]=openp;
alarmSysm[in]=sysm;
alarmState[in]=1;
alarmExp[in]=alarmExpin;
alarmPERIOD[in]=PERIOD_CURRENT;
if(ttpp > 0.0){
//tp set = wait for close below .15min
alarmState[in]=3;
}
string statee=(alarmState[in] == 1)? "onTick" : "onClose" ;
string texts = "🌐 Alarm SET at Price "+DoubleToString(alarm[in])+" :: "+(string)alarmSysm[in]+" ~ Type: "+statee+" :: Total alarm: ("+(totalalarm+1)+") (ACCT: "+IntegerToString(AccountInfoInteger(ACCOUNT_LOGIN))+" :: "+AccountInfoString(ACCOUNT_NAME)+")";
if(AllowSignalTG){ Print(" TG Requst: ",(string)sendMessage(texts,tgId,tgToken)); }
break;
}
}
}
}
//
trade.OrderDelete(orderTicket);
}
}}
////////////////////////////////////////
//drop closed posistions
/* for(int in=0;in < 999;in++){
if(positionEx[in] > 0 && !PositionSelectByTicket(positionEx[in])){
positionEx[in]=0.0;
positionExSym[in]="";
}
}*/
//
if(PositionsTotal() > 0){
//int isexist=0;
for(int in=0;in < 999;in++){positionExSym[in]="";positionEx[in]=0.0;positionExT[in]=0;positionExTYP[in]=0;}
for (int pos_0 = PositionsTotal() -1; pos_0 >= 0; pos_0--) {
ulong positionTicket = PositionGetTicket(pos_0);
positionExT[pos_0]=positionTicket;
positionExSym[pos_0]=PositionGetSymbol(POSITION_SYMBOL);
positionEx[pos_0]=PositionGetDouble(POSITION_SL);
positionExTYP[pos_0]=PositionGetInteger(POSITION_TYPE);
//work on adj to void per symbol and 2nd position to update sl.
//positionExSym[in]
// Print(pos_0," positionExSym[pos_0]",positionExSym[pos_0],", positionEx[pos_0]",positionEx[pos_0],", positionExT[pos_0]",positionExT[pos_0],", positionExTYP[pos_0]",positionExTYP[pos_0]," ,POSITION_TYPE_BUY ",POSITION_TYPE_BUY," ,POSITION_TYPE_SELL ",POSITION_TYPE_SELL);
// if(PositionGetSymbol(POSITION_SYMBOL) != positionExSym[in]){ continue;}
// if((PositionGetString(POSITION_COMMENT) == (string)("IBRK2"))){isexist=1;}
}
for(int in=0;in < 999;in++){
for(int in2=0;in2 < 999;in2++){
if(in2 == in){continue;}
if(positionExSym[in] == positionExSym[in2] && positionExT[in] != positionExT[in2] && positionExSym[in] != ""){
if(PositionSelectByTicket(positionExT[in2])){positionEx[in2]=PositionGetDouble(POSITION_SL);}
if(PositionSelectByTicket(positionExT[in])){positionEx[in]=PositionGetDouble(POSITION_SL);}
// Print("found SL",positionEx[in]," , ",positionEx[in2]);
//adj sl appropraiately. call to check ticket sl and type for mor sig and adj.
if(positionExTYP[in] == positionExTYP[in2] && positionEx[in] != positionEx[in2]){
if(positionExTYP[in2] == POSITION_TYPE_BUY && positionEx[in] > 0 && positionEx[in2] > 0){
ulong tiik = (positionEx[in] > positionEx[in2]) ? positionExT[in2] : positionExT[in];
double ssls = (positionEx[in] > positionEx[in2]) ? positionEx[in] : positionEx[in2];
if(PositionSelectByTicket(tiik)){trade.PositionModify(tiik,ssls,PositionGetDouble(POSITION_TP));}
}else if(positionExTYP[in2] == POSITION_TYPE_SELL && positionEx[in] > 0 && positionEx[in2] > 0){
ulong tiik = (positionEx[in] < positionEx[in2]) ? positionExT[in2] : positionExT[in];
double ssls = (positionEx[in] < positionEx[in2]) ? positionEx[in] : positionEx[in2];
if(PositionSelectByTicket(tiik)){trade.PositionModify(tiik,ssls,PositionGetDouble(POSITION_TP));}
}
}
}}}
/*
for (int pos_0 = PositionsTotal() -1; pos_0 >= 0; pos_0--) {
ulong positionTicket = PositionGetTicket(pos_0);
//if(PositionGetSymbol(POSITION_SYMBOL) != _Symbol || Period() != PERIOD_H1){ continue;}
//if(PositionGetInteger(POSITION_MAGIC) != Magic){ continue;}
//Print("i still exist ",pos_0," ticket: ",positionTicket);
//---
//if(isexist == 0 && (PositionGetString(POSITION_COMMENT) == (string)("IBRK3"))){
if(true){
double newSL=0.0;
if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY && PositionGetDouble(POSITION_PRICE_OPEN) > PositionGetDouble(POSITION_SL)){
newSL=PositionGetDouble(POSITION_PRICE_OPEN)+MaxSpread*point;
if(newSL < PositionGetDouble(POSITION_SL)){ newSL = PositionGetDouble(POSITION_SL);}
}else if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL && PositionGetDouble(POSITION_PRICE_OPEN) < PositionGetDouble(POSITION_SL)){
newSL=PositionGetDouble(POSITION_PRICE_OPEN)-MaxSpread*point;
if(newSL > PositionGetDouble(POSITION_SL)){ newSL = PositionGetDouble(POSITION_SL);}
}
newSL=NormalizeDouble(newSL,_Digits);
if(newSL != PositionGetDouble(POSITION_SL)){
trade.PositionModify(positionTicket,newSL,PositionGetDouble(POSITION_TP));
}
}
}*/
}
//gold standard.
equity = NormalizeDouble(((double)AccountInfoDouble(ACCOUNT_EQUITY) * (double)PercentEquityUseable/100),2);
initialBal=NormalizeDouble(initialBal,2);
int sprd = (double)(Ask-Bid)/point;
//update panel
//Print("valll9090909090: ", equity," ", Ask-Bid," ",_Digits," ", point);//ot=OrdersTotal();PositionsTotal()
panel.Update(Lots,initialBal,PercentEquityUseable,equity,TimeToString(TimeCurrent(), TIME_DATE|TIME_MINUTES),sprd,(int)0,(int)0,avZ[3],avZ[4],volOverall,volINST[1],volINST[2],dayOverall);
}
//+------------------------------------------------------------------+
ENUM_DAY_OF_WEEK day_of_week;
//+------------------------------------------------------------------+
//| Function: Check if trade session is open and excl. Sat and Sun |
//+------------------------------------------------------------------+
int getday(){
datetime time_now = TimeCurrent();
MqlDateTime time;
TimeToStruct(time_now, time);
return (int)time.day_of_week;
}
bool trade_session()
{datetime time_now = TimeCurrent();
MqlDateTime time;
TimeToStruct(time_now, time);
uint week_day_now = time.day_of_week;
uint seconds_now = (time.hour * 3600) + (time.min * 60) + time.sec;
if(week_day_now == 0)
day_of_week = SUNDAY;
if(week_day_now == 1)
day_of_week = MONDAY;
if(week_day_now == 2)
day_of_week = TUESDAY;
if(week_day_now == 3)
day_of_week = WEDNESDAY;
if(week_day_now == 4)
day_of_week = THURSDAY;
if(week_day_now == 5)
day_of_week = FRIDAY;
if(week_day_now == 6)
day_of_week = SATURDAY;
datetime from, to;
uint session = 0;
while(SymbolInfoSessionTrade(_Symbol, day_of_week, session, from, to))
{
session++;
}
uint trade_session_open_seconds = uint(from);
uint trade_session_close_seconds = uint(to);
if(trade_session_open_seconds < seconds_now && trade_session_close_seconds > seconds_now && week_day_now >= 1 && week_day_now <= 5)
return(true);
return(false);
}
//---
double tickd(string val="bid", string sysm = ""){
if(val == "bid"){
return (double)SymbolInfoDouble(sysm, SYMBOL_BID);
}else if(val == "ask"){
return (double)SymbolInfoDouble(sysm, SYMBOL_ASK);
}else{ return 0.0;}
}
void getLots(double range,string sysm){
//range == entry - sl. pips
//lot assigner
int didgi=SymbolInfoInteger(sysm, SYMBOL_DIGITS);
double pointt=0.0;
int VDpiV = 10;
for(int vDigits = didgi; vDigits > 1; vDigits--){VDpiV=VDpiV*10;}
pointt=(double)1/VDpiV;
//double calclot = (double)equity/NormalizeDouble((range/pointt),didgi);//hrlyatr
double calclot=CalculateUniversalLotSize(sysm,(double)equity,NormalizeDouble((range/pointt),didgi));
/// Print("pointt ",pointt," calclot: ",calclot," range: ",NormalizeDouble((range/pointt),didgi)," equity: ",equity," '' ",SymbolInfoDouble(sysm,SYMBOL_TRADE_CONTRACT_SIZE)," SymbolInfoInteger(symbol, SYMBOL_DIGITS) ",SymbolInfoInteger(sysm, SYMBOL_DIGITS));
//Print(" calclot "+calclot+" atr1.5 "+ NormalizeDouble(hrlyatr*1.5,_Digits)+" equity "+equity);
if(calclot < Minlot){Lots=Minlot;}else{Lots = NormalizeDouble(calclot,2);}
if(Lots > Maxlot) Lots = Maxlot;
if(fixedlots > 0) Lots = fixedlots;//disabling trade so spreadbeyond max and holidays dont trade. (but if a trade already open up data could handle closing well)
}
double CalculateUniversalLotSize(string symbol, double riskAmount, double stopLossPips)
{
double tickSize, tickValue, contractSize=SymbolInfoDouble(symbol, SYMBOL_TRADE_CONTRACT_SIZE), pointSize, pipSize;
int digits=SymbolInfoInteger(symbol, SYMBOL_DIGITS);
// Get symbol info
if (!SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_SIZE, tickSize) ||
!SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_VALUE, tickValue))
{
Print("Failed to get symbol info");
return 0;
}
// stopLossPips=stopLossPips/pointt;
pointSize = tickSize; // MetaTrader defines tick = point
pipSize = (digits == 5 || digits == 3) ? pointSize * 10 : pointSize;
// Calculate pip value per lot
double pipValuePerLot = (tickValue / tickSize) * pipSize;
if((contractSize <= 10.0) || (contractSize <= 100.0 && digits != 3)){
//pipValuePerLot *= contractSize;
}else{
riskAmount=riskAmount*10;
//mannualy set to offset xauusd if future. improvement to patch plz apply to me!.
}
// Final lot size
double lotSize = riskAmount / (stopLossPips * pipValuePerLot);
// Normalize to broker's allowed step
double lotStep = SymbolInfoDouble(symbol, SYMBOL_VOLUME_STEP);
lotSize = MathFloor(lotSize / lotStep) * lotStep;
//Print("contractSize: ",contractSize," pipValuePerLot: ",pipValuePerLot," tickSize ",tickSize," tickValue ",tickValue," pointSize ",pointSize," pipSize ",pipSize," lotStep ",lotStep);
return NormalizeDouble(lotSize, 2); // Usually 2 decimal places
}
long vol(int posi=1,ENUM_TIMEFRAMES frame=PERIOD_CURRENT){
return iVolume(_Symbol,frame,posi);
}
double sar_val(int posi = 0, ENUM_TIMEFRAMES frame = PERIOD_CURRENT){
double slowSar[99999];
CopyBuffer(sar,0,1,2,slowSar);
ArraySetAsSeries(slowSar,true);
return NormalizeDouble(slowSar[posi], _Digits);
}
double high(int posi = 0, ENUM_TIMEFRAMES frame = PERIOD_CURRENT,string sysm=NULL){
return NormalizeDouble(iHigh(sysm, frame, posi), SymbolInfoInteger(sysm, SYMBOL_DIGITS));
}
double low(int posi = 0, ENUM_TIMEFRAMES frame = PERIOD_CURRENT,string sysm=NULL){
return NormalizeDouble(iLow(sysm, frame, posi), SymbolInfoInteger(sysm, SYMBOL_DIGITS));
}
double close(int posi = 0, ENUM_TIMEFRAMES frame = PERIOD_CURRENT,string sysm=NULL){
return NormalizeDouble(iClose(sysm, frame, posi), SymbolInfoInteger(sysm, SYMBOL_DIGITS));
}
double open(int posi = 0, ENUM_TIMEFRAMES frame = PERIOD_CURRENT,string sysm=NULL){
return NormalizeDouble(iOpen(sysm, frame, posi), SymbolInfoInteger(sysm, SYMBOL_DIGITS));
}
datetime time(int posi = 0, ENUM_TIMEFRAMES frame = PERIOD_CURRENT,string sysm=NULL){
return iTime(sysm, frame, posi);
}
void line (int type=1, string name="line",double place=0.0, int shift=0,int col =1, int style=0, ENUM_TIMEFRAMES tim=PERIOD_CURRENT){
//1 = OBJ_HLINE, 0 = OBJ_VLINE
//1 = STYLE_DASH, 2 = STYLE_DOT,0 solid, 3 mixture of dot and dash
if(type == 1){ObjectCreate(0,name,OBJ_HLINE, 0,time(shift, tim),place);
}else{ObjectCreate(0,name,OBJ_VLINE, 0,time(shift, tim),place);}
needObj(name,col,style);
}
void block(string name="box",double xPricE1 = 0.0, double xPricE2 = 0.0,int yPosition1 = 0,int yPosition2 = 0, int col=1,ENUM_TIMEFRAMES tim=PERIOD_CURRENT,int style=0,int width=1){
ObjectCreate(0,name, OBJ_RECTANGLE, 0, time(yPosition1,tim), xPricE1, time(yPosition2,tim), xPricE2);
needObj(name,col,style,width);
}
void trendL(string name="trendL",double xPricE1 = 0.0, double xPricE2 = 0.0,int yPosition1 = 0,int yPosition2 = 0, int col=1,ENUM_TIMEFRAMES tim=PERIOD_CURRENT,int style=0,int width=1){
ObjectCreate(0,name, OBJ_TREND, 0, time(yPosition1,tim), xPricE1, time(yPosition2,tim), xPricE2);
needObj(name,col,style,width);
}
void needObj(string name,int col,int style,int width=1){
if(col == 1){ObjectSetInteger(0,name,OBJPROP_COLOR,Blue);
}else if(col == 2){ObjectSetInteger(0,name,OBJPROP_COLOR,LightBlue);
}else if(col == 3){ObjectSetInteger(0,name,OBJPROP_COLOR,Pink);
}else if(col == 4){ObjectSetInteger(0,name,OBJPROP_COLOR,Red);
}else if(col == 5){ObjectSetInteger(0,name,OBJPROP_COLOR,DeepPink);
}else if(col == 6){ObjectSetInteger(0,name,OBJPROP_COLOR,Yellow);
}else if(col == 7){ObjectSetInteger(0,name,OBJPROP_COLOR,Green);
}else if(col == 8){ObjectSetInteger(0,name,OBJPROP_COLOR,LightGreen);
}else if(col == 9){ObjectSetInteger(0,name,OBJPROP_COLOR,White);
}else if(col == 10){ObjectSetInteger(0,name,OBJPROP_COLOR,Purple);
}else if(col == 11){ObjectSetInteger(0,name,OBJPROP_COLOR,Gray);
}else if(col == 12){ObjectSetInteger(0,name,OBJPROP_COLOR,PowderBlue);
}else if(col == 13){ObjectSetInteger(0,name,OBJPROP_COLOR,DarkOliveGreen);
}else if(col == 14){ObjectSetInteger(0,name,OBJPROP_COLOR,Black);
}else{ ObjectSetInteger(0,name,OBJPROP_COLOR,Black);}
ObjectSetInteger(0,name,OBJPROP_STYLE,style);
ObjectSetInteger(0,name,OBJPROP_WIDTH,width);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
//---
double hihi(int from, int to, int viewby=0, ENUM_TIMEFRAMES perio=PERIOD_CURRENT)
{ double kk = high(from, perio);
int okh = to - from,
got = 0,jj = from;
for(int i = 0; i < okh; i++)
{
got = to - i;
if(high(got, perio) > kk)
{ kk = high(got, perio);jj=got;}
}
if(viewby == 1) kk=jj;
return kk;
}
double lolo(int from, int to, int viewby=0, ENUM_TIMEFRAMES perio=PERIOD_CURRENT)
{double kk = low(from, perio);
int okh = to - from,
got = 0,jj=from;;
for(int i = 0; i < okh; i++)
{ got = to - i;
if(low(got, perio) < kk)
{ kk = low(got, perio);jj=got;}
}
if(viewby == 1) kk=jj;
return kk;
}
//---
double hihiC(int from, int to, int viewby=0, ENUM_TIMEFRAMES perio=PERIOD_CURRENT)
{ double kk = open(from, perio);
int okh = to - from,
got = 0,jj = from;
for(int i = 0; i < okh; i++)
{
got = to - i;
if(open(got, perio) > kk)
{ kk = open(got, perio);jj=got;}
}
if(viewby == 1) kk=jj;
return kk;
}
double loloC(int from, int to, int viewby=0, ENUM_TIMEFRAMES perio=PERIOD_CURRENT)
{double kk = close(from, perio);
int okh = to - from,
got = 0,jj=from;;
for(int i = 0; i < okh; i++)
{ got = to - i;
if(close(got, perio) < kk)
{ kk = close(got, perio);jj=got;}
}
if(viewby == 1) kk=jj;
return kk;
}
//---
double volhh(int from, int to, int viewby=0, ENUM_TIMEFRAMES perio=PERIOD_CURRENT)
{ double kk = vol(from, perio);
int okh = to - from,
got = 0,jj = from;
for(int i = 0; i < okh; i++)
{
got = to - i;
if(vol(got, perio) > kk)
{ kk = vol(got, perio);jj=got;}
}
if(viewby == 1) kk=jj;
return kk;
}
double volll(int from, int to, int viewby=0, ENUM_TIMEFRAMES perio=PERIOD_CURRENT)
{double kk = vol(from, perio);
int okh = to - from,
got = 0,jj=from;;
for(int i = 0; i < okh; i++)
{ got = to - i;
if(vol(got, perio) < kk)
{ kk = vol(got, perio);jj=got;}
}
if(viewby == 1) kk=jj;
return kk;
}