I am trying to replicate TradingView’s Relative Moving Average (RMA) in Amibroker but the plotted values of RMA differ widely with TradingView’s. Here is my AFL script:
_SECTION_BEGIN("Relative Moving Average");
function RMA(source, period)
{
alpha = 1 / period;
total = 0.0;
total += alpha * source + (1 - alpha) * Nz(Ref(total, - 1));
return total;
}
average = RMA(close, 10);
plot(average, "RMA", colorBlack, styleLine);
_SECTION_END();
rma = RMA(close, 10);
plot(rma, "RMA", colorBlack, styleLine);
The same function in the below PineScript fetches correct results:
rma(source, length) =>
alpha = 1 / length
sum = 0.0
sum := alpha * source + (1 - alpha) * nz(sum[1])
plot(Close, 10)
Amibroker’s results differ widely. With total = 0.0;
the plotted values are 1/10th of Close
. I have tried initializing total as total = EMA(source, period);
but it just plots double the values of EMA. However, when I don’t use the compound operator +=
the values are approximately equal to EMA. Where am I doing it wrong?
Formsify is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.