Secondo voi è possibile codificare questo indicatore da trading view?
//@version=4
study(title=”Rolling Moving Average”, shorttitle=”MA_rolling”, overlay=true)
len = input(9, minval=1, title=”Length”)
src = input(close, title=”Source”)
ma_type = input(options=[“SMA”,”EMA”], defval=”SMA”, title=”type”)
roll_sma(x, y) =>
sum = 0.0
for i = 0 to y – 1
sum := sum + x[i] / y
sum
roll_ema(x, y) =>
alpha = 2 / (y + 1)
sum = 0.0
sum := alpha * x + (1 – alpha) * nz(sum[1])
var roll_sma_len = 0
roll_sma_len := roll_sma_len + 1
out1 = ma_type==”SMA” ? sma(src,len) : ema(src,len)
out2 = ma_type==”SMA” ? roll_sma(src,roll_sma_len) : roll_ema(src,roll_sma_len)
out = bar_index+1 <= len ? out2 : out1
plot(out, color=#00FF00, title="MA")