// Created by emiliolb -- Version 1.0 // Contact firstname.lastname@example.org study(title="Linear Regression Slope", shorttitle="LRS", overlay=true) src = close 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, 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)
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
Many thanks! Pete