[pshaiCmd] FIRLTER (FIR Filter)
stableDescription
CC for Hann Windowed FIR Filtering
Usage:
local c = ClosePrices()
local rsi = RSI(c, 14)
local frsi = CC_FIRLTER(rsi, 14)
local srsi = SMA(rsi, 14)
Plot(1, 'RSI', rsi)
Plot(1, 'FIR RSI', frsi, Red)
Plot(1, 'SMA RSI', srsi, Yellow)
HaasScript
-- Author: pshai
DefineCommand('FIRLTER', 'FIR Filter')
local src = DefineParameter(ListNumberType, 'src', 'Source values', true, ClosePrices())
local length = DefineParameter(NumberType, 'length', 'Period length for calculations', true, 14)
local function getFilt(values, length, i)
local DMSum = 0
local coef = 0
for count = 1, length do
local i2 = (i + count - 1)
DMSum = DMSum + (1 - Cos((PI*2) * (count) / (length + 1))) * ArrayIndex(values, i2)
coef = coef + (1 - Cos((PI*2) * (count) / (length + 1)))
end
local _dmh = 0
if coef != 0 then
_dmh = DMSum / coef
end
return _dmh
end
local result = Load('result', {})
if Load('warmup', true) then
local len = ArrayGet(Min(Count(src) - length, 100), 1)
for i = 1, len do
result[i] = getFilt(src, length, i)
end
Save('warmup', false)
else
result = ArrayUnshift(result, getFilt(src, length, 1))
end
Save('result', Grab(result, 0, 500))
DefineOutput(ListNumberType, result, 'Filtered values')
0 Comments
Sign in to leave a comment.
No comments yet. Be the first!