Last month in his October 2021 article in S&C, “Cycle/Trend Analytics And The MAD Indicator,” John Ehlers presented the MAD (moving average difference) indicator, an oscillator developed out of his research into understanding cycles data better. The MAD indicator effectively took the difference between two simple moving averages. While the MAD is said to offer an improvement over the classic, well-known MACD, the MADH (moving average difference with Hann) that Ehlers presents in his article in this issue, “The MADH: The MAD Indicator, Enhanced,” is said to offer an improvement over the MAD indicator. The enhancement comes from the utilization of the Hann windowing technique and takes the difference of two finite impulse response filters. Ehlers explains that excellent buy and sell indications can be seen in the indicator’s valleys and peaks, respectively.
// MADH (Moving Average Difference - Hann) Indicator
// (C) 2021 John F. Ehlers
//Parameters
ShortLength= 8
DominantCycle= 27
//Vars
once LongLength = 20
once Filt1 = 0
once Filt2 = 0
once coef = 0
once count = 0
once MADH = 0
once LongLength = floor(ShortLength + DominantCycle / 2)
Filt1 = 0
coef = 0
for count = 1 to ShortLength do
Filt1 = Filt1 + (1 - cos(360*count / (ShortLength + 1)))*Close[count - 1]
coef = coef + (1 - cos(360*count / (ShortLength + 1)))
next
If coef <> 0 Then
Filt1 = Filt1 / coef
endif
Filt2 = 0
coef = 0
For count = 1 to LongLength do
Filt2 = Filt2 + (1 - cos(360*count / (LongLength + 1)))*Close[count - 1]
coef = coef + (1 - cos(360*count / (LongLength + 1)))
next
If coef <> 0 Then
Filt2 = Filt2 / coef
endif
//Computed as percentage of price
If Filt2 <> 0 Then
MADH = 100*(Filt1 - Filt2) / Filt2
endif
return MADH as "MADH", 0 as "0"