Return Moving Average [SpiritualHealer117]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © spiritualhealer117

//@version=5
indicator("RMA")
src = input(close,"Source")
len = input(14, "Length")
off = input(1, "Offset")
smo = input(5, "Smoothing")
osmode = input(false, "Use Oscillator Mode")

ret = src/src[1]
avg = osmode ? ta.sma(ret,len) : ta.sma(ret,len)*src
max = osmode ? ta.highest(ret,len) : ta.highest(ret,len)*src
min = osmode ? ta.lowest(ret,len) : ta.lowest(ret,len)*src

smo_avg = ta.sma(avg, smo)
smo_max = ta.sma(max, smo)
smo_min = ta.sma(min, smo)
a = smo_max-smo_avg
b = smo_avg-smo_min

plot(smo_avg, offset=off, color=color.white, style=plot.style_line)
plot(osmode?(a > b?na:smo_max):smo_max, offset=off, color=color.red, style=plot.style_linebr)
plot(osmode?(b > a?na:smo_min):smo_min, offset=off, color=color.green, style=plot.style_linebr)
plot(osmode?ret:na, color=color.gray)
