MADH Oscillator Indicator

beta
By r4stl1n in Oscillators Published April 2022 👁 1,276 views 💬 0 comments

Description

This is a implementation of the MADH Indicator developed by John F. Ehlers. The MAD indicator takes the difference of two simple moving averages. The length of the shorter moving average is determined by the desired smoothness of the indicator. The longer moving average is the length of the shorter plus the half period of the dominant cycle in the data. MADH improves upon this by adding the hann windowing technique to help further smooth out the data.
HaasScript
-- [r4stl1n] MADH Oscillator Indicator
--
-- The MADH indicator offers an improvement over MAD through the use of the 
-- hahn windowing technique. MADH offers an improvment over MACD by offering
-- a rational for establishing the lengths of the moving averages
--
-- The "Thinking Mans MACD"
--
-- MADH (Moving Average Difference - Hann)
--------------------------------
-- You are on your own with this script
-------------------------------- 
-- ~Bored and programming~
    
-- Define command
DefineCommand('MADH', 'Moving Average Difference - Hann')

local shortLength = DefineParameter(NumberType, 'shortLength', 'ShortLength for moving average', false, 8, 'Number,InputShortLength')
local dominantCycle = DefineParameter(NumberType, 'dominantCycle', 'Dominant Cycle', false, 27, 'Number,InputDominantCycle')

local retVal = 0
local filt1 = 0
local filt2 = 0
local coef = 0
local longLength = ArrayGet(Round((shortLength+dominantCycle) / 2,0),1)

for i = 1, shortLength, 1
do
    local closePrice = 0
    if i == 1
    then
        closePrice =  Prices()[1]
    else
        closePrice =  Prices()[i-1]
    end

    filt1 = filt1 + (1-Cos(360*i/(shortLength+1))) * closePrice
    coef = coef + (1-Cos(360*i/(shortLength+1)))

end

if coef != 0 
then
    filt1 = filt1 / coef
end

coef = 0

for i = 1, longLength, 1
do
    local closePrice = 0
    if i == 1
    then
        closePrice =  Prices()[1]
    else
        closePrice =  Prices()[i-1]
    end

    filt2 = filt2 + (1-Cos(360*i/(longLength+1))) * closePrice
    coef = coef + (1-Cos(360*i/(longLength+1)))
end

if coef != 0 
then
    filt2 = filt2 / coef
end


if filt2 != 0 
then
    retVal = 100*(filt1-filt2)/filt2
end


DefineOutput(NumberType, retVal, 'MADH', 'TradeBotContainer, IndicatorContainer, Signal Helpers')

0 Comments

Sign in to leave a comment.

No comments yet. Be the first!