SWMA - Sine Weighted Moving Average

stable
By Bunka in Trend Published July 2021 👁 1,472 views 💬 0 comments

Description

-- SWMA - Sine Weighted Moving Average -- ported to HaasScript by Bunka -- Copyright (c) 2018-present, Alex Orekhov (everget) -- Sine Weighted Moving Average script may be freely distributed under the MIT license.
HaasScript
-- SWMA - Sine Weighted Moving Average
-- ported to HaasScript by Bunka
-- Copyright (c) 2018-present, Alex Orekhov (everget)
-- Sine Weighted Moving Average script may be freely distributed under the MIT license.

DefineCommand("Bunka_SWMA_Sine_Weighted_Moving_Average","Sine Weighted Moving Average")

local length = DefineParameter(NumberType,"length","length", true, 14)
local length = Input("Length", 14)
local src = ClosePrices()
local sum = 0
local weightSum = 0

for i = 1, length -1 do
    local weight = Sin((i + 1) * PI / (length + 1))
    sum = sum + Grab(src[i+1],0,i+1) * weight
    weightSum = weightSum + weight
end

local swma = sum / weightSum

--Plot(0, "SWMA", swma, Yellow)

DefineOutput(ListNumberType, swma, "SWMA_Sine_Weighted_Moving_Average")

0 Comments

Sign in to leave a comment.

No comments yet. Be the first!