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
{ Search Tag: MA-MACD }
{ Moving average convergence-divergence indicator }
inputs:
double FastLength( 12 )
[DisplayName = "FastLength",
ToolTip = "Number of bars for the fast moving average."],
double SlowLength( 26 )
[DisplayName = "SlowLength",
ToolTip = "Number of bars for the slow moving average."],
double MACDLength( 9 )
[DisplayName = "MACDLength",
ToolTip = "Number of bars for the MACD moving average."],
int ColorNormLength( 14 )
[DisplayName = "ColorNormLength",
ToolTip = "Number of bars for normalizing MACD Diff for coloring."];
variables:
intrabarpersist bool InChart( false ),
double MyMACD( 0 ),
double MACDAvg( 0 ),
double MACDDiff( 0 ),
double NormDiff( 0 ),
int BarCount( 0 );
{ Calculate MACD and Signal }
MyMACD = MACD( Close, FastLength, SlowLength );
MACDAvg = XAverage( MyMACD, MACDLength );
MACDDiff = MyMACD - MACDAvg;
{ Normalize the histogram for coloring }
if CurrentBar >= ColorNormLength then
NormDiff = MACDDiff / Highest( AbsValue( MACDDiff ), ColorNormLength );
{ Plot MACD, Signal, and Histogram }
Plot1( MyMACD, "MACD" );
Plot2( MACDAvg, "Signal" );
