Linear Regression Slope

Script which calculates the linear regression slope, giving an idea where enter or exit in a market position.
Please if anybody have suggestions, let me know.
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.


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?
// Created by emiliolb -- Version 1.0
// Contact emiliolb@outlook.com 
study(title="Linear Regression Slope", shorttitle="LRS", overlay=true)

src = close[0]
len = input(defval=150, minval=1, title="Linear Regression Length")
lrc = linreg(src, len, 0)
plot(lrc, color = red, title = "Linear Regression Curve", style = line, linewidth = 2)

lrprev = linreg(close[1], len, 0)
slope = ((lrc - lrprev) / interval)

//Please if somebody have suggestions how show this better, let me know
codiff = slope
plotarrow(codiff, colorup=teal, colordown=orange, transp=40)