I trade stocks with tradingview. I started a simple Pinecode to display % rate of change between price periods; but only those that are greater than zero. I got that far but I want now to create an AVERAGE or median value of them. How can I do this?
//@version=5
indicator(title="only+ROC", shorttitle="+ROC", format=format.price, precision=2, timeframe="",
timeframe_gaps=true)
length = input.int(1, minval=1)
source = input(close, "Source")
roc = 100 * (source - source[length])/source[length]
hline(0, color=#787B86, title="Zero Line")
plot(series=roc > 0 ? roc : na)