RicardoSantos

[RS]Linear Regression Bands V1

experiment with linear regression, the purpose was to catch break outs early, but it creates to much visual noise

same as version 0 but with added margin filter and signal to mark entrys
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 Regression Bands V1", shorttitle="[RS]LRB.V1", overlay=true)
tf1 = input(0.125)
smooth = input(4)
prehh1 = nz(hh1[1], high)
prell1 = nz(ll1[1], low)

hh1 = close >= prehh1 ? high : prehh1 - sma(abs(change(high, 1)*tf1), smooth)
ll1 = close <= prell1 ? low : prell1 + sma(abs(change(low, 1)*tf1), smooth)
midline = avg(hh1, ll1)
plot(midline, style=cross, color=black, linewidth=1)
ph1 = plot(hh1, style=line, color=black, linewidth=1)
pl1 = plot(ll1, style=line, color=black, linewidth=1)

margin = input(30) * syminfo.mintick
signalcolor = high-margin > hh1 ? maroon : low+margin < ll1 ? green : gray
signal = high-margin > hh1 ? high+margin : low+margin < ll1 ? low-margin : na
plot(signal, style=circles, color=signalcolor, linewidth=4)