RicardoSantos

[RS]Linear Decay Oscilator V0

EXPERIMENTAL: binary oscillator based on linear regression.
the master line has 1/4 of the decay.
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?
study(title="[RS]Linear Decay Oscilator V0")
src = input(title='Source:', type=source, defval=hl2)
smoothing = input(title='Source Smoothing:', type=integer, defval=4)
decay = input(title='Decay:', type=float, defval=0.001)

smooth_src = sma(src, smoothing)

previous_lr = nz(lr[1], smooth_src)
lr = smooth_src > previous_lr ? previous_lr+decay : smooth_src < previous_lr ? previous_lr-decay : previous_lr

previous_master_lr = nz(master_lr[1], smooth_src)
master_lr = smooth_src > previous_master_lr ? previous_master_lr+decay/4 : smooth_src < previous_master_lr ? previous_master_lr-decay/4 : previous_master_lr

macd = sma(smooth_src-lr, smoothing)
signal = macd > 0 ? 1 : macd < 0 ? -1 : 0

master_macd = sma(smooth_src-master_lr, smoothing)
master_signal = master_macd > 0 ? 1 : master_macd < 0 ? -1 : 0

plot(title='Follower', series=signal, style=columns, color=signal > 0 and master_signal > 0 ? green : signal < 0 and master_signal < 0 ? maroon : gray, transp=75)
plot(title='Master', series=master_signal, color=master_signal > 0 ? green : master_signal < 0 ? maroon : gray, linewidth=4)
hline(title='0', price=0, color=black)