This repository has been archived by the owner on Nov 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
FXTT_Fx_Scanner.mq4
851 lines (804 loc) · 71.1 KB
/
FXTT_Fx_Scanner.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
//+------------------------------------------------------------------+
//| FXTT_StrategyChecklist.mq4 |
//| Copyright 2016, Carlos Oliveira |
//| https://www.forextradingtools.eu |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, Carlos Oliveira"
#property link "https://www.forextradingtools.eu/products/indicators/forex-scanner-free-indicator/?utm_campaign=properties.indicator&utm_medium=special&utm_source=mt4terminal"
#property version "1.00"
#property strict
#property indicator_chart_window
string INDI_NAME="MPSCN-";
input int TimerInterval=60; //Update interval (secs)
input int FontSize=10; //Font Size
input string FontName="Calibri"; //Font Name
input string Group0; //---------------------------------------------------
input bool ShowPrice=true; //Show Price
input string Group01; //---------------------------------------------------
input bool ShowSpread=true; //Show Spread
input string Group1; //---------------------------------------------------
input bool ShowATR=true; //Show ATR
input ENUM_TIMEFRAMES AtrTimeframe=PERIOD_H1; //ATR Timeframe
input int AtrPeriod=20; //ATR Period
input string Group2; //---------------------------------------------------
input bool ShowVolume=true; //Show Volume
input ENUM_TIMEFRAMES VolumeTimeframe=PERIOD_H1; //Volume Timeframe
input int VolumePeriod=60; //Volume Period
input string Group3; //---------------------------------------------------
input bool ShowRsi=true; //Show RSI
input ENUM_TIMEFRAMES RsiTimeframe=PERIOD_H1; //RSI Timeframe
input int RsiPeriod=14; //RSI Period
input int RsiUpperLevel = 75; //RSI Upper Level
input int RsiLowerLevel = 25; //RSI Lower Level
input string Group4; //---------------------------------------------------
input bool ShowStoch=true; //Show Stochastic
input ENUM_TIMEFRAMES StochTimeframe=PERIOD_H1; //Stoch Timeframe
input int StochK = 5; //%K period
input int StochD = 3; //%D period
input int StochSlow = 3;//Slowing
input ENUM_MA_METHOD StochMethod= MODE_SMA; //MA Method
input ENUM_STO_PRICE StochPrice = STO_LOWHIGH; //Price Field
input int StochUpperLevel = 80; //Stoch Upper Level
input int StochLowerLevel = 20; //Stoch Lower Level
input string Group5; //---------------------------------------------------
input bool ShowAdx=true; //Show ADX
input ENUM_TIMEFRAMES AdxTimeframe=PERIOD_H1; //ADX Timeframe
input int AdxPeriod=20; //ADX Period
input ENUM_APPLIED_PRICE AdxAppliedPrice=PRICE_CLOSE; //ADX Applied Price
input string Group6; //---------------------------------------------------
input bool ShowPivots=true; //Show Pivots
int GUIXOffset = 20;
int GUIYOffset = 45;
int GUIHeaderXOffset = 20;
int GUIHeaderYOffset = 0;
int GUIColOffset=100;
int ListXOffset = 10;
int ListYOffset = 15;
int ListXMultiplier = 10;
int ListYMultiplier = 15;
datetime TimeMissing;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
ChartColorSet(CHART_COLOR_BACKGROUND,clrBlack);
ChartColorSet(CHART_COLOR_FOREGROUND,clrWhite);
ChartColorSet(CHART_COLOR_GRID,clrNONE);
ChartColorSet(CHART_COLOR_VOLUME,clrNONE);
ChartColorSet(CHART_COLOR_CHART_UP,clrNONE);
ChartColorSet(CHART_COLOR_CHART_DOWN,clrNONE);
ChartColorSet(CHART_COLOR_CHART_LINE,clrNONE);
ChartColorSet(CHART_COLOR_CANDLE_BULL,clrNONE);
ChartColorSet(CHART_COLOR_CANDLE_BEAR,clrNONE);
ChartColorSet(CHART_COLOR_BID,clrNONE);
ChartColorSet(CHART_COLOR_ASK,clrNONE);
ChartColorSet(CHART_COLOR_LAST,clrNONE);
ChartColorSet(CHART_COLOR_STOP_LEVEL,clrNONE);
ChartModeSet(CHART_LINE);
//---
EventSetTimer(1);
DrawHeader();
DrawScanner();
return(INIT_SUCCEEDED);
}
//+-------------------------------------------------------------------------------------------+
int deinit()
{
ObjectsDeleteAll(ChartID(),INDI_NAME);
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
DrawMissingTime();
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
//| Timer function |
//+------------------------------------------------------------------+
void OnTimer()
{
DrawMissingTime();
if(TimeSeconds(TimeCurrent())%TimerInterval==0)
{
DrawScanner();
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
long getAvgVolume(string symbol,int period)
{
long volume_total=0;
for(int i=0; i<period; i++)
{
volume_total+=iVolume(symbol,VolumeTimeframe,i);
}
return volume_total / period;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double getRange(string symbol,int period)
{
int DataPeriod=PERIOD_D1;
int DataBar=iBarShift(symbol,DataPeriod,Time[0]);
double range = iHigh(symbol, period, DataBar) - iLow(symbol, period, DataBar);
double point = MarketInfo(symbol, MODE_POINT);
if(point > 0) return (NormalizeDouble(range / point, 0));
return 1;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void DrawMissingTime(int deltaY=0)
{
int x=GUIXOffset+ListXOffset,y=20;
DrawLabel("CurTimeLbl",x,y,"Server Time:"+TimeToStr(TimeCurrent(),TIME_MINUTES),FontSize,FontName,clrWhite);
DrawLabel("LocalTimeLbl",x+=150,y,"Local Time:"+TimeToStr(TimeLocal(),TIME_MINUTES),FontSize,FontName,clrWhite);
DrawLabel("TimeLeftLbl",x+=150,y,"Time until Candle close:",FontSize,FontName,clrWhite);
DrawTimeMissingColum(PERIOD_M1,x+=150,y);
DrawTimeMissingColum(PERIOD_M5,x+=GUIColOffset,y);
DrawTimeMissingColum(PERIOD_M15,x+=GUIColOffset,y,30);
DrawTimeMissingColum(PERIOD_H1,x+=GUIColOffset, y);
DrawTimeMissingColum(PERIOD_H4,x+=GUIColOffset, y);
DrawTimeMissingColum(PERIOD_D1,x+=GUIColOffset, y);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void DrawTimeMissingColum(int period,int x,int y,int dxOffset=25)
{
int dx=x;
color timeColor;
string periodStr= GetPeriodStr(period);
string timeLeft = GetTimeToClose(period, timeColor);
DrawLabel("TimeLeftLbl_"+periodStr,dx,y,periodStr+":",FontSize,FontName,clrWhite);
DrawLabel("TimeLeftVal_"+periodStr,dx+=dxOffset,y,timeLeft,FontSize,FontName,timeColor);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
string GetTimeToClose(int period,color &timeColor)
{
int periodMinutes = periodToMinutes(period);
int shift = periodMinutes*60;
int currentTime = (int)TimeCurrent();
int localTime = (int)TimeLocal();
int barTime = (int)iTime(period);
int diff = (int)MathMax(round((currentTime-localTime)/3600.0)*3600,-24*3600);
string time=getTime(barTime+periodMinutes*60-localTime-diff,timeColor);
time=(TerminalInfoInteger(TERMINAL_CONNECTED)) ? time : time+" x";
return time;
}
//+------------------------------------------------------------------+
void DrawLabel(string name,int x,int y,string label,int size=9,string font="Arial",color clr=DimGray,string tooltip="")
{
name=INDI_NAME+":"+name;
ObjectDelete(name);
ObjectCreate(name,OBJ_LABEL,0,0,0);
ObjectSetText(name,label,size,font,clr);
ObjectSet(name,OBJPROP_CORNER,0);
ObjectSet(name,OBJPROP_XDISTANCE,x);
ObjectSet(name,OBJPROP_YDISTANCE,y);
ObjectSetString(0,name,OBJPROP_TOOLTIP,tooltip);
//--- justify text
//ObjectSet(name, OBJPROP_ANCHOR, 0);
//ObjectSetString(0, name, OBJPROP_TOOLTIP, tooltip);
//ObjectSet(name, OBJPROP_SELECTABLE, 0);
//---
}
//+------------------------------------------------------------------+
//| The function sets chart background color. |
//+------------------------------------------------------------------+
bool ChartColorSet(int prop_id,const color clr,const long chart_ID=0)
{
//--- reset the error value
ResetLastError();
//--- set the chart background color
if(!ChartSetInteger(chart_ID,prop_id,clr))
{
//--- display the error message in Experts journal
Print(__FUNCTION__+", Error Code = ",GetLastError());
return(false);
}
//--- successful execution
return(true);
}
//+------------------------------------------------------------------+
//| Set chart display type (candlesticks, bars or |
//| line). |
//+------------------------------------------------------------------+
bool ChartModeSet(const long value,const long chart_ID=0)
{
//--- reset the error value
ResetLastError();
//--- set property value
if(!ChartSetInteger(chart_ID,CHART_MODE,value))
{
//--- display the error message in Experts journal
Print(__FUNCTION__+", Error Code = ",GetLastError());
return(false);
}
//--- successful execution
return(true);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
void DrawScanner()
{
Print("=============>DrawScanner");
for(int x=0; x<SymbolsTotal(true); x++)
{
DrawSymbol(SymbolName(x,true),x);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void DrawSymbol(string symbolName,int symbolIdx)
{
int x= GUIXOffset+ListXOffset + ListXMultiplier;
int y= GUIYOffset+ListYOffset + ListYMultiplier *symbolIdx;
DrawSymbolColumn(symbolName,x,y,symbolName,FontSize,FontName);
if(ShowPrice)
DrawPriceColumn(symbolName,x+=GUIColOffset,y,symbolName,FontSize,FontName);
if(ShowSpread)
DrawSpreadColumn(symbolName,x+=GUIColOffset,y,symbolName,FontSize,FontName);
if(ShowATR)
DrawRangeColumn(symbolName,x+=GUIColOffset,y,symbolName,FontSize,FontName);
if(ShowVolume)
DrawVolumeColumn(symbolName,x+=GUIColOffset,y,symbolName,FontSize,FontName);
if(ShowRsi)
DrawRsiColumn(symbolName,x+=GUIColOffset,y,symbolName,FontSize,FontName);
if(ShowStoch)
DrawStochColumn(symbolName,x+=GUIColOffset,y,symbolName,FontSize,FontName);
if(ShowAdx)
DrawAdxColumn(symbolName,x+=GUIColOffset,y,symbolName,FontSize,FontName);
if(ShowPivots)
DrawPivotsColumn(symbolName,x+=GUIColOffset,y,symbolName,FontSize,FontName);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double getPoint(string symbol)
{
return MarketInfo(symbol,MODE_POINT);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double getModifier(string symbol)
{
int digits=(int)MarketInfo(symbol,MODE_DIGITS);
double modifier=1;
if(digits==3 || digits==5)
modifier=10.0;
return modifier;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void DrawRsiColumn(string symbolName,int x,int y,string text,int fontSize=8,string fontName="Calibri")
{
double rsi=NormalizeDouble(iRSI(symbolName,RsiTimeframe,RsiPeriod,PRICE_CLOSE,0),0);
string tooltip=symbolName+"\n.: "+GetPeriodStr(RsiTimeframe)+" RSI ("+IntegerToString(RsiPeriod)+"):.\nCurrent ("+DoubleToStr(rsi,1)+")";
DrawLabel("rsi_"+symbolName,x,y,DoubleToStr(rsi,1),fontSize,fontName,GetRsiColor(rsi),tooltip);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void DrawStochColumn(string symbolName,int x,int y,string text,int fontSize=8,string fontName="Calibri")
{
double stoch=iStochastic(symbolName,StochTimeframe,StochK,StochD,StochSlow,StochMethod,StochPrice,MODE_MAIN,0);
string tooltip=symbolName+"\n.: "+GetPeriodStr(StochTimeframe)+" Stoch :.\nCurrent ("+DoubleToStr(stoch,1)+")";
DrawLabel("stoch_"+symbolName,x,y,DoubleToStr(stoch,1),fontSize,fontName,GetStochColor(stoch),tooltip);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void DrawAdxColumn(string symbolName,int x,int y,string text,int fontSize=8,string fontName="Calibri")
{
double adx=iADX(symbolName,AdxTimeframe,AdxPeriod,AdxAppliedPrice,MODE_MAIN,0);
string tooltip=symbolName+"\n.: "+GetPeriodStr(AdxTimeframe)+" ADX ("+IntegerToString(AdxPeriod)+"):.\nCurrent ("+DoubleToStr(adx,1)+")";
DrawLabel("adx_"+symbolName,x,y,GetAdxStr(adx),fontSize,fontName,GetAdxColor(adx),tooltip);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
string GetAdxStr(double adx)
{
if(adx<=25)
return "No Trend";
if(adx<=50)
return "Weak Trend";
if(adx<=75)
return "Strong Trend";
return "Very Strong Trend";
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
color GetAdxColor(double adx)
{
if(adx<=25)
return clrWhite;
if(adx<=50)
return clrGreen;
if(adx<=75)
return clrYellow;
return clrRed;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void DrawPriceColumn(string symbolName,int x,int y,string text,int fontSize=8,string fontName="Calibri")
{
int digits=(int)MarketInfo(symbolName,MODE_DIGITS);
double vAsk=NormalizeDouble(MarketInfo(symbolName,MODE_ASK),digits);
double vBid=NormalizeDouble(MarketInfo(symbolName,MODE_BID),digits);
double vSpread=NormalizeDouble(MarketInfo(symbolName,MODE_SPREAD),digits);
string tooltip=symbolName+"\n.: Price :.\nAsk: "+(string)vAsk+"\nBid: "+(string)vBid+"\nSpread: "+(string)vSpread;
DrawLabel("price_"+symbolName,x,y,(string)vBid,fontSize,fontName,clrWhite,tooltip);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void DrawSpreadColumn(string symbolName,int x,int y,string text,int fontSize=8,string fontName="Calibri")
{
int digits=(int)MarketInfo(symbolName,MODE_DIGITS);
double vAsk=NormalizeDouble(MarketInfo(symbolName,MODE_ASK),digits);
double vBid=NormalizeDouble(MarketInfo(symbolName,MODE_ASK),digits);
double vSpread=NormalizeDouble(MarketInfo(symbolName,MODE_SPREAD),digits);
string tooltip=symbolName+"\n.: SPREAD :.\nAsk: "+(string)vAsk+"\nBid: "+(string)vBid+"\nSpread: "+(string)vSpread;
DrawLabel("spread_"+symbolName,x,y,(string)vSpread,fontSize,fontName,clrWhite,tooltip);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void DrawPivotsColumn(string symbolName,int x,int y,string text,int fontSize=8,string fontName="Calibri")
{
double pivots[7];
int digits=(int)MarketInfo(symbolName,MODE_DIGITS);
double vAsk=MarketInfo(symbolName,MODE_BID);
double pivot=NormalizeDouble((GetPivotValue(symbolName,PERIOD_D1)),digits);
pivots[0]=pivot;
pivots[1]=NormalizeDouble((GetPivotResistance(symbolName,PERIOD_D1,pivot,1)),digits);
pivots[2]=NormalizeDouble((GetPivotResistance(symbolName,PERIOD_D1,pivot,2)),digits);
pivots[3]=NormalizeDouble((GetPivotResistance(symbolName,PERIOD_D1,pivot,3)),digits);
pivots[4]=NormalizeDouble((GetPivotSupport(symbolName,PERIOD_D1,pivot,1)),digits);
pivots[5]=NormalizeDouble((GetPivotSupport(symbolName,PERIOD_D1,pivot,2)),digits);
pivots[6]=NormalizeDouble((GetPivotSupport(symbolName,PERIOD_D1,pivot,3)),digits);
int closestIdx=GetClosestPivot(vAsk,pivots);
double pips=vAsk-pivots[closestIdx];
string tooltip=symbolName+"\n.: Daily Pivots :.\nPP: "+DoubleToStr(pivots[0])+"\nR1: "+DoubleToStr(pivots[1]);
string pivotText=GetPivotDirection(pips)+" "+GetPivotStr(closestIdx);
DrawLabel("pivots_"+symbolName,x,y,pivotText,fontSize,fontName,GetPivotColor(closestIdx),tooltip);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
color GetPivotColor(int pivotIdx)
{
if(pivotIdx==0)
return clrWhite;
if(pivotIdx<=3)
return clrGreen;
return clrRed;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int GetClosestPivot(double ask,double &pivots[])
{
int idx=0;
double minDistance=1.7976931348623158e+308;
for(int i=0;i<ArraySize(pivots);i++)
{
double dist=MathAbs(ask-pivots[i]);
if(dist<minDistance)
{
minDistance=dist;
idx=i;
}
}
return idx;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
string GetPivotDirection(double value)
{
if(value>0)
return "Above";
return "Bellow";
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double GetPivotValue(string symbolName,int timeframe)
{
//Pivot point (PP) = (High + Low + Close) / 3
return (iHigh(symbolName,timeframe,1)+iLow(symbolName,timeframe,1)+iClose(symbolName,timeframe,1))/3;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double GetPivotResistance(string symbolName,int timeframe,double pivotValue,int resistanceIdx=1)
{
switch(resistanceIdx)
{
case 3:
//Third resistance (R3) = High + 2(PP – Low)
return iHigh(symbolName,timeframe,1) + 2*(pivotValue - iLow(symbolName,timeframe,1));
case 2:
//Second resistance (R2) = PP + (High – Low)
return pivotValue + (iHigh(symbolName,timeframe,1)-iLow(symbolName,timeframe,1));
default:
//First resistance (R1) = (2 x PP) – Low
return (2*pivotValue) - iLow(symbolName,timeframe,1);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
double GetPivotSupport(string symbolName,int timeframe,double pivotValue,int supportIdx=1)
{
switch(supportIdx)
{
case 3:
//Third support (S3) = Low – 2(High – PP)
return iLow(symbolName,timeframe,1) - 2*(iHigh(symbolName,timeframe,1)-pivotValue);
case 2:
//Second support (S2) = PP – (High – Low)
return pivotValue - (iHigh(symbolName,timeframe,1) - iLow(symbolName,timeframe,1));
default:
//First support (S1) = (2 x PP) – High
return (2*pivotValue) - iHigh(symbolName,timeframe,1);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void DrawVolumeColumn(string symbolName,int x,int y,string text,int fontSize=8,string fontName="Calibri")
{
long volume=iVolume(symbolName,VolumeTimeframe,0);
double volAvg=(double)getAvgVolume(symbolName,VolumePeriod);
double volPercent=(volume/volAvg)*100;
string tooltip=symbolName+"\n.: "+GetPeriodStr(VolumeTimeframe)+" Volume ("+IntegerToString(VolumePeriod)+"):.\nCurrent ("+DoubleToStr(volume,0)+")\nAverage ("+DoubleToStr(volAvg,0)+")";
DrawLabel("vol"+symbolName,x,y,DoubleToStr(volPercent,2)+"%",fontSize,fontName,GetPercentColor(volPercent),tooltip);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void DrawRangeColumn(string symbolName,int x,int y,string text,int fontSize=8,string fontName="Calibri")
{
double atr=0;
double point=getPoint(symbolName);
double modifier=getModifier(symbolName);
if(point>0)
atr=(NormalizeDouble(iATR(symbolName,AtrTimeframe,AtrPeriod,0)/point,0))/modifier;
double range=getRange(symbolName,AtrTimeframe)/modifier;
double rangePercent=(range/atr)*100;
string tooltip=symbolName+"\n.: "+GetPeriodStr(AtrTimeframe)+" ATR ("+IntegerToString(AtrPeriod)+"):.\nCurrent ("+DoubleToStr(range,1)+")\nAverage ("+DoubleToStr(atr,1)+")";
DrawLabel("atr_"+symbolName,x,y,DoubleToStr(rangePercent,1)+"%",fontSize,fontName,GetPercentColor(rangePercent),tooltip);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
color GetRsiColor(double value)
{
if(value>=RsiUpperLevel)
return clrGreen;
if(value<=RsiLowerLevel)
return clrRed;
return clrWhite;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
color GetStochColor(double value)
{
if(value>=StochUpperLevel)
return clrGreen;
if(value<=StochLowerLevel)
return clrRed;
return clrWhite;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
color GetPercentColor(double value)
{
if(value<=25)
return clrWhite;
if(value<=50)
return clrGreen;
if(value<=75)
return clrYellow;
if(value<=100)
return clrRed;
return clrPurple;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void DrawSymbolColumn(string symbolName,int x,int y,string text,int fontSize=8,string fontName="Calibri")
{
DrawLabel("lbl_"+symbolName,x,y,text,fontSize,fontName,clrWhite,symbolName);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void DrawHeader()
{
string objName="Header";
int x = GUIXOffset+GUIHeaderXOffset;
int y = GUIYOffset+GUIHeaderYOffset;
DrawLabel(objName+"name",x,y,"Name",FontSize,FontName,clrWhite,"Name");
DrawHorizontalLine(objName+"namehline",x,y,15);
if(ShowPrice)
{
DrawLabel(objName+"price",x+=GUIColOffset,y,"Price",FontSize,FontName,clrWhite,"Price");
DrawHorizontalLine(objName+"pricehline",x,y,15);
}
if(ShowSpread)
{
DrawLabel(objName+"spread",x+=GUIColOffset,y,"Spread",FontSize,FontName,clrWhite,"Spread");
DrawHorizontalLine(objName+"spreadhline",x,y,15);
}
if(ShowATR)
{
DrawLabel(objName+"range",x+=GUIColOffset,y,"ATR ("+GetPeriodStr(AtrTimeframe)+")",FontSize,FontName,clrWhite,"Range");
DrawHorizontalLine(objName+"rangehline",x,y,15);
}
if(ShowVolume)
{
DrawLabel(objName+"curvolume",x+=GUIColOffset,y,"Vol ("+GetPeriodStr(VolumeTimeframe)+")",FontSize,FontName,clrWhite,"Volume");
DrawHorizontalLine(objName+"volhline",x,y,15);
}
if(ShowRsi)
{
DrawLabel(objName+"rsi",x+=GUIColOffset,y,"RSI ("+GetPeriodStr(RsiTimeframe)+")",FontSize,FontName,clrWhite,"Pivots");
DrawHorizontalLine(objName+"rsihline",x,y,15);
}
if(ShowStoch)
{
DrawLabel(objName+"stoch",x+=GUIColOffset,y,"Stoch ("+GetPeriodStr(StochTimeframe)+")",FontSize,FontName,clrWhite,"Stochastic");
DrawHorizontalLine(objName+"stochhline",x,y,15);
}
if(ShowAdx)
{
DrawLabel(objName+",adx",x+=GUIColOffset,y,"ADX ("+GetPeriodStr(AdxTimeframe)+")",FontSize,FontName,clrWhite,"ADX");
DrawHorizontalLine(objName+"adxhline",x,y,15);
}
if(ShowPivots)
{
DrawLabel(objName+"pivots",x+=GUIColOffset,y,"Pivots",FontSize,FontName,clrWhite,"Pivots");
DrawHorizontalLine(objName+"pvotshline",x,y,15);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void DrawHorizontalLine(string objName,int x,int y,int length=250)
{
string line;
for(int i=0;i<length;i++)
line += "_";
DrawLabel(objName+"1",x,y,line,FontSize,FontName,clrWhite,"");
//DrawLabel(objName+"2",x+380,y,line,FontSize,FontName,clrWhite,"");
}
//+------------------------------------------------------------------+
int periodToMinutes(int period)
{
int i;
static int _per[]={1,2,3,4,5,6,10,12,15,20,30,60,120,180,240,360,480,720,1440,10080,43200,0x4001,0x4002,0x4003,0x4004,0x4006,0x4008,0x400c,0x4018,0x8001,0xc001};
static int _min[]={1,2,3,4,5,6,10,12,15,20,30,60,120,180,240,360,480,720,1440,10080,43200};
//---
if(period==PERIOD_CURRENT)
period=Period();
for(i=0;i<20;i++) if(period==_per[i]) break;
return(_min[i]);
}
//+------------------------------------------------------------------+
datetime iTime(int period)
{
datetime times[];
if(CopyTime(Symbol(),period,0,1,times)<=0)
return(TimeLocal());
return(times[0]);
}
//+------------------------------------------------------------------+
string getTime(int times,color &theColor)
{
string stime="";
int seconds;
int minutes;
int hours;
if(times<0)
{
theColor=clrRed;
times=(int)fabs(times);
}
else if(times>0)
{
theColor=clrYellow;
}
seconds = (times%60);
hours = (times-times%3600)/3600;
minutes = (times-seconds)/60-hours*60;
//---
if(hours>0)
if(minutes<10)
stime = stime+(string)hours+":0";
else stime = stime+(string)hours+":";
stime=stime+(string)minutes;
if(seconds<10)
stime=stime+":0"+(string)seconds;
else stime=stime+":"+(string)seconds;
return(stime);
}
//+------------------------------------------------------------------+
string GetPivotStr(int pivotIdx)
{
switch(pivotIdx)
{
case 1:
return "R1";
case 2:
return "R2";
case 3:
return "R3";
case 4:
return "S1";
case 5:
return "S2";
case 6:
return "S3";
default:
return "PP";
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
string GetPeriodStr(int period)
{
string TMz="";
switch(period)
{
case 1: TMz = "M1"; break;
case 2: TMz = "M2"; break;
case 3: TMz = "M3"; break;
case 4: TMz = "M4"; break;
case 5: TMz = "M5"; break;
case 6: TMz = "M6"; break;
case 7: TMz = "M7"; break;
case 8: TMz = "M8"; break;
case 9: TMz = "M9"; break;
case 10: TMz = "M10"; break;
case 11: TMz = "M11"; break;
case 12: TMz = "M12"; break;
case 13: TMz = "M13"; break;
case 14: TMz = "M14"; break;
case 15: TMz = "M15"; break;
case 20: TMz = "M20"; break;
case 25: TMz = "M25"; break;
case 30: TMz = "M30"; break;
case 40: TMz = "M40"; break;
case 45: TMz = "M45"; break;
case 50: TMz = "M50"; break;
case 60: TMz = "H1"; break;
case 120: TMz = "H2"; break;
case 180: TMz = "H3"; break;
case 240: TMz = "H4"; break;
case 300: TMz = "H5"; break;
case 360: TMz = "H6"; break;
case 420: TMz = "H7"; break;
case 480: TMz = "H8"; break;
case 540: TMz = "H9"; break;
case 600: TMz = "H10"; break;
case 660: TMz = "H11"; break;
case 720: TMz = "H12"; break;
case 1440: TMz = "D1"; break;
case 10080: TMz = "W1"; break;
case 43200: TMz = "M1"; break;
}
return TMz;
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Create a trend line by the given coordinates |
//+------------------------------------------------------------------+
bool TrendCreate(const long chart_ID=0, // chart's ID
const string name="TrendLine", // line name
const int sub_window=0, // subwindow index
datetime time1=0, // first point time
double price1=0, // first point price
datetime time2=0, // second point time
double price2=0, // second point price
const color clr=clrRed, // line color
const ENUM_LINE_STYLE style=STYLE_SOLID, // line style
const int width=1, // line width
const bool back=false, // in the background
const bool selection=true, // highlight to move
const bool ray_right=false, // line's continuation to the right
const bool hidden=true, // hidden in the object list
const long z_order=0) // priority for mouse click
{
//--- set anchor points' coordinates if they are not set
ChangeTrendEmptyPoints(time1,price1,time2,price2);
//--- reset the error value
ResetLastError();
//--- create a trend line by the given coordinates
if(!ObjectCreate(chart_ID,name,OBJ_TREND,sub_window,time1,price1,time2,price2))
{
Print(__FUNCTION__,
": failed to create a trend line! Error code = ",GetLastError());
return(false);
}
//--- set line color
ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
//--- set line display style
ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);
//--- set line width
ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);
//--- display in the foreground (false) or background (true)
ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
//--- enable (true) or disable (false) the mode of moving the line by mouse
//--- when creating a graphical object using ObjectCreate function, the object cannot be
//--- highlighted and moved by default. Inside this method, selection parameter
//--- is true by default making it possible to highlight and move the object
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
//--- enable (true) or disable (false) the mode of continuation of the line's display to the right
ObjectSetInteger(chart_ID,name,OBJPROP_RAY_RIGHT,ray_right);
//--- hide (true) or display (false) graphical object name in the object list
ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
//--- set the priority for receiving the event of a mouse click in the chart
ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
//--- successful execution
return(true);
}
//+------------------------------------------------------------------+
//| Check the values of trend line's anchor points and set default |
//| values for empty ones |
//+------------------------------------------------------------------+
void ChangeTrendEmptyPoints(datetime &time1,double &price1,
datetime &time2,double &price2)
{
//--- if the first point's time is not set, it will be on the current bar
if(!time1)
time1=TimeCurrent();
//--- if the first point's price is not set, it will have Bid value
if(!price1)
price1=SymbolInfoDouble(Symbol(),SYMBOL_BID);
//--- if the second point's time is not set, it is located 9 bars left from the second one
if(!time2)
{
//--- array for receiving the open time of the last 10 bars
datetime temp[10];
CopyTime(Symbol(),Period(),time1,10,temp);
//--- set the second point 9 bars left from the first one
time2=temp[0];
}
//--- if the second point's price is not set, it is equal to the first point's one
if(!price2)
price2=price1;
}
//+------------------------------------------------------------------+