[pshaiScript] Arnaud Legoux Moving Average

stable
By pshai in Trend Published March 2020 👁 1,548 views 💬 0 comments

Description

The ALMA indicator function.
HaasScript
function alma(series, windowsize, offset, sigma)
    local length = windowsize
    local m = Floor(offset * (length - 1))
    local s = length / sigma
    local norm = 0.0
    local sum = 0.0
    local weight

    for i = length, 1, -1 do
        weight = Exp(-1 * Pow(i - m, 2) / (2 * Pow(s, 2)))
        norm = norm + weight
        sum = sum + series[length - (i - 1)] * weight
    end

    return sum / norm
end

-- usage
local c = ClosePrices()
Plot(0, 'ALMA', alma(c, 9, 0.5, 6))

0 Comments

Sign in to leave a comment.

No comments yet. Be the first!