I am trying to code a variation of Perry Kaufmans Adaptive Moving Average
The Equation is AMA= (ER*Close) + (1-ER)*AMA[1]
It Returns ‘Blank’
Can anyone help?
// parameter
// n = 10
Change = ABS(close - close[n])
calc = ABS(close-close[1])
volat = summation[n](calc)
ER = Change / volat
once AMA=Average[n]
AMA=(ER*Close)+(1-ER)*AMA[1]
//or
//V1=(1-ER)
//V2=AMA[1]
//V3=(V1*V2)
//AMA=(ER*Close)+V3
Return AMA
JSParticipant
Senior
Hi,
This is how I know the Kaufman filter…
Period = MAX(10, 4)
FastPeriod = 7
SlowPeriod = 28
Fastest = 2 / (FastPeriod + 1)
Slowest = 2 / (SlowPeriod + 1)
IF BarIndex < Period THEN
KAMA = Close
ELSE
Num = ABS(Close - Close[Period])
Den = summation[Period](ABS(Close - Close[1]))
ER = Num / Den
Alpha = SQUARE(ER * (Fastest - Slowest) + Slowest)
KAMA = (Alpha * Close) + ((1 - Alpha) * KAMA[1])
ENDIF
Return KAMA
JS
Thanks for the quick reply. However I was trying to code the following equation
The Equation is AMA= (ER*Close) + (1-ER)*AMA[1]
Where ER is the smoothing constantent dirived from Perry Kaufman
I think the problem lies in the second part of the equation!
Regards
Needs at least n data in order to calculate, so embed your code into a barindex count condition:
// parameter
n = 10
if barindex>n then
Change = ABS(close - close[n])
calc = ABS(close-close[1])
volat = summation[n](calc)
ER = Change / volat
once AMA=Average[n]
AMA=(ER*Close)+(1-ER)*AMA[1]
endif
Return AMA
Thank You Nicolas
That seems to work
I have been learning prorealcode for sometime now. Could you recommend any text that may help me
I have studied the online manuels plus the Vivian Schmitt ebook but still need more help.
Regards
Mark