I'm trying to re-implement the rma
function from TradingView
pinescript
but I cannot make it output the same result as the original function.
Here is the code I developed, the code is basically the ema
function, but it differs greatly from the rma
function plot
result when charting:
//@version=3
study(title = "test", overlay=true)
rolling_moving_average(data, length) =>
alpha = 2 / (length + 1)
sum = 0.0
for index = length to 0
if sum == 0.0
sum := data[index]
else
sum := alpha * data[index] + (1 - alpha) * sum
atr2 = rolling_moving_average(close, 5)
plot(atr2, title="EMAUP2", color=blue)
atr = rma(close, 5)
plot(atr, title="EMAUP", color=red)
So my question is how is the rma
function works internally so I can implement a clone of it?
PS. Here is the link to the documentation https://www.tradingview.com/study-script-reference/#fun_rma It does show a possible implementation, but it does not work when running it.
rma()
as built-in one. You even post a link to it. But then the script you show is totally different! Also, please provide a screenshot of your results. (Most people are simply too lazy to copy paste and try on their own on T.V. to help out.) – Sharleensharlene