[pshaiCmd] Adaptive Period Length
stableDescription
This command calculates the adaptive period length based on noise in the prices.
It is recommended to use this command with: https://www.haasscripts.com/t/pshaicmd-indicator-memory/
Usage:
local o = OpenPrices()
local h = HighPrices()
local period = CC_AdaptivePeriod(o, c, 3, 20, 5, 20)
local ema = EMA(c, period)
HaasScript
-- [pshaiCmd] Adaptive Period
-- Author: pshai
DefineCommand('AdaptivePeriod', 'Returns the adaptive period based on input prices')
local open = DefineParameter(ListNumberType, 'open', 'Open Prices', true, OpenPrices(), 'OpenPrices')
local close = DefineParameter(ListNumberType, 'close', 'Close Prices', true, ClosePrices(), 'ClosePrices')
local signal_ema = DefineParameter(NumberType, 'signalEmaPeriod', 'Signal EMA Period Length', false, 3)
local signal_period = DefineParameter(NumberType, 'signalPeriod', 'Signal Period Length', false, 20)
local short_period = DefineParameter(NumberType, 'shortPeriod', 'Short Period Length', false, 5)
local long_period = DefineParameter(NumberType, 'longPeriod', 'Long Period Length', false, 30)
local signal = Abs(close - close[signal_period+1])
local noise = Sum(Grab(Abs(open - close), 0, signal_period))
local ratio = 1 - (noise == 0 and 1 or signal / noise)
local ratio_ema = EMA(ratio, signal_ema)
local result_period = (long_period - short_period) * ratio_ema + short_period
DefineOutput(NumberType, result_period, 'The Adaptive Period Length as a number', 'SMA, EMA, RSI')
0 Comments
Sign in to leave a comment.
No comments yet. Be the first!