Linear Regression Slope

15833 lượt xem
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.
Mã nguồn mở

Với tinh thần của TradingView, tác giả đã xuất bản tập lệnh theo mã nguồn mở, vì thế trader có thể dễ dàng hiểu và tùy chỉnh được. Bạn có thể sử dụng miễn phí, hoặc tùy chỉnh lại mã đã được cấp phép bởi Quy tắc Chung. Bạn có thể sử dụng nó trên biểu đồ.

Bạn muốn sử dụng tập lệnh này trên biểu đồ?
// 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)

Bình luận

hi there
great script!
is there any chance to set alerts when arrows go from green to red and vice versa?
would be a great feature
keep up the great work
+4 Phản hồi
This rocks! I like using it in the 1 minute set to 50 - works perfectly!! Thanks!
+3 Phản hồi
Hi Emelio,
do you know how to code this LRS indicator in javascript?
I don't need the highlight bars or anything else, I just need the lines and to be able change the colour of the line.
+2 Phản hồi
Nice Tool Emilio!
+2 Phản hồi
in line 11 what is the interval set by?
+1 Phản hồi
emiliolb JoshuaMcGowan
@JoshuaMcGowan, interval is a reserved word that gets the value from the popup to set the timeframe, colors amd arrows
+1 Phản hồi
@emiliolb, thank you :) figured it was an artifact not available in v4 now. Much appreciated.
Phản hồi

I'm trying to code a Linear Regression Band indicator that has the same standard deviations as the built in Linear Regression indicator/drawing tool.

The mean of my indicator (code below) is correct but the standard deviation bands are always in the wrong place when I compare them to the same length LR indicator or drawing tool.

Does anyone know how to fix this issue so that the bands match the built in drawing tool/indicator?

Here is my code ...

study(shorttitle="LRB", title="Linear Regression Bands", overlay=true)
source = close
length = input(50, minval=1)
offset = 0
mult = input(2, title="StDev", minval=0.001, maxval=5)
basis = linreg(source, length, offset)
dev = mult * stdev(source, length)
upper = basis + dev
lower = basis - dev
plot(basis, color=red)
plot(upper, color=blue)
plot(lower, color=blue)

Many thanks! Pete
Phản hồi
emiliolb peterlondon
@peterlondon, I'm sorry I just saw this now. Had you fixed this?
Phản hồi
peterlondon emiliolb
@emiliolb, yes, many thanks :)
Phản hồi