-
Notifications
You must be signed in to change notification settings - Fork 0
/
_Advanced_ADX.mq4
73 lines (70 loc) · 4.63 KB
/
_Advanced_ADX.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
//+------------------------------------------------------------------+
//| Advanced_ADX.mq4 |
//| Copyright © 2018, Harry Gui |
//| |
//+------------------------------------------------------------------+
#property copyright "Harry Gui"
#property link " "
//----
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_color2 Red
//----
extern int ADXPeriod = 14;
extern int _histWidth = 4;
//----
double ExtBuffer1[];
double ExtBuffer2[];
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int init()
{
SetIndexBuffer(0, ExtBuffer1);
SetIndexStyle(0, DRAW_HISTOGRAM, 0, _histWidth);
//----
SetIndexBuffer(1, ExtBuffer2);
SetIndexStyle(1, DRAW_HISTOGRAM, 0, _histWidth);
//----
IndicatorShortName("Advanced_ADX (" + ADXPeriod + ")");
//--- set levels
IndicatorSetInteger(INDICATOR_LEVELS,1);
SetLevelStyle(STYLE_SOLID,2,Gold);
SetLevelValue(0,20);
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
int i, limit;
double ADX0,ADX1,ADX2;
int counted_bars = IndicatorCounted();
if(counted_bars < 0)
return(-1);
if(counted_bars > 0)
counted_bars--;
limit = Bars - counted_bars;
//----
for(i = 0; i < limit ; i++)
{
ADX0 = iADX(NULL, 0, ADXPeriod, PRICE_CLOSE, MODE_MAIN, i);
ADX1 = iADX(NULL, 0, ADXPeriod, PRICE_CLOSE, MODE_PLUSDI, i);
ADX2 = iADX(NULL, 0, ADXPeriod, PRICE_CLOSE, MODE_MINUSDI, i);
//----
if(ADX1 >= ADX2)
{
ExtBuffer1[i] = ADX0;
ExtBuffer2[i] = 0;
}
else
{
ExtBuffer1[i] = 0;
ExtBuffer2[i] = ADX0;
}
}
return(0);
}
//+------------------------------------------------------------------+