Dear All:
is there any code for the AMA indicator available?
There are several adaptive MAs. One e.g. is the KAMA and has even installed PRT since version 10.3 (called adaptive moving average). Then there are probably some more adaptive MA’s in the library.
This adaptive moving average in ProRealTime is the same as KAMA:
// parameters :
Period = 10
FastPeriod = 2
SlowPeriod = 30
Fastest = 2 / (FastPeriod + 1)
Slowest = 2 / (SlowPeriod + 1)
if barindex < Period+1 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
JanParticipant
Veteran
Good evening,
I have found an (the?) calculation of the AMA and coded it below in PRT.
AMA follows the actual price movements faster as KAMA does
I can mention the source where I found it if required.
// Variables:
Per = 10
Fast = 2
Slow = 30
//multiplier calculation
MLTP = ABS((Close - Lowest[Per](Low)) - (Highest[Per](High) - Close)) / ((Highest[Per](High) - Lowest[Per](Low)))
//smoothing multiplier
SC = SQUARE (MLTP * (Fast/(Fast+1) - Fast/(Slow+1)) + Fast/(Slow+1))
//calculation of AMA
if barindex <= Per + 1 then
AMA = close
else
//The first AMA is the close. The current AMA can be calculated using this formula:
AMA = AMA[1] + SC * (Close - AMA[1])
endif
return AMA
Hello Nicolas,
I would like to use the adaptive moving average, not on prices but on an indicator.
Is it possible to adapt the above codes by replacing “Close” with the name of the indicator?
In advance, a thousand thanks for your always precious help.
NB:
I am using V10 via IG and therefore cannot use the adaptive code [9,2,30] (close) available in V11.
Good apm
Denis
Denis – Please post only in the language of the forum that you are posting in – English only in the English speaking forums please.
I already translated your French post to English so there is no need to post it again. You also posted it in the ‘Insert PRT Code’ box for some strange reason so I have deleted your last post. Please try to be more careful when posting in the forums – we like to keep them tidy! 🙂
OK, sorry. I don’t know what is ‘Insert PRT Code’. Maybe a wrong maneuver.
Is it possible to adapt the above codes by replacing “Close” with the name of the indicator?
Yes it is possible, replace “Close” with the variable that contains the values of your indicator.
Many thanks Nicolas, I did it. I was able to validate the code but no line appears on the graph while the AMA appears well in the properties of he indicator.
Please post the code in order to fix it. It’s probably a lack of history for the indicator to compute correctly at first run.
//variable p =période de la moyenne
//smooth1=période de lissage
//smooth2=période du signal
a=average[p](customclose)
r=round(p/2) +1
b= customclose - a[r]
b1=average[smooth1](b)
// parameters :
Period = 10
FastPeriod = 2
SlowPeriod = 30
Fastest = 2 / (FastPeriod + 1)
Slowest = 2 / (SlowPeriod + 1)
if barindex < Period+1 then
Kama=b1
else
Num = abs(b1-b1[Period])
Den = summation[Period](abs(b1-b1[1]))
ER = Num / Den
Alpha = SQUARE(ER *(Fastest - Slowest )+ Slowest)
KAMA = (Alpha * b1) + ((1 -Alpha)* Kama[1])
endif
return b1 coloured by momentum[1](b1) AS "Indicateur",0 as "Zero", kama as "Signal"
////////////////////////FIN du code
Here is the code Nicolas
It works quite well for me. I just added these settings at top of the code:
p = 20
smooth1 = 3
Thanks Nicolas
“p” and “smooth1” are variables in my code so it should be the same as define them at top of the code ?
I have tried with settings at top of the code but the KAMA does not appear, I don’t understand why