first of all, I am writing Kaufman's Adaptive Moving Average (KAMA), and I am struggling with the calculation of Efficiency Ratio (ER).
First of all, let me explain the calculation of efficiency ratio.
ER = Change/Volatility
Change = ABS(Close - Close (10 periods ago))
Volatility = Sum10(ABS(Close - Prior Close))
Volatility is the sum of the absolute value of the last ten price changes (Close - Prior Close).
Here's what I did
indicator('KAMA', shorttitle='KAMA', overlay=true)
length = input(title='Length', defval=10)
fastLength = input(title='Fast EMA constant', defval=2) //smoothing constant
slowLength = input(title='Fast EMA length', defval=30) //smoothing constant
source = input(title='Source', defval=close)
change = math.abs(ta.change(source, length))
volatility = math.sum(math.abs(ta.change(source)), length)
ER = change/volatility
Since, I cannot see the return value of above calculation, so I am not sure whether my coding is correct. My question:
change = math.abs(ta.change(source, length))
- Will this return the absolute value of the different between close price and price 10 bars ago?
volatility = math.sum(math.abs(ta.change(source)), length)
- What will this return between:
2.1 The sum of abs different between current close - prior close doing this 10 bars back?
2.2 The sum of abs different between current close - close of 10 bars earlier.
Here's the image of calculation
Here's the reference of KAMA Calculation including spreadsheet