Linear Regression Channel Script Conversion
Budget: $10 – $30 USD
How do I make a script compatible and transferable from Tradingview to Webull Script Editor. It's called a Linear Regression Channel indicator for the chart. Here is the code:
//@version=5
indicator('Linear Regression ++ [Dev Lucem]', 'Lin Reg ++ [DL]', overlay=true)
mtf_val = input.timeframe('', 'Resolution', inline="config", group="Algorithm Config")
source = input.source(close, inline="config", group="Algorithm Config")
length = input.int(100, minval=1, inline="config1", group="Algorithm Config")
dev = input(2.0, 'Deviation', inline="config1", group="Algorithm Config")
offset = input.int(0, minval=0, inline="config2", group="Algorithm Config")
smoothing = input.int(1, minval=1, inline="config2", group="Algorithm Config")
line_thick = input.int(4, 'S&R Size', minval=1, maxval=4, inline="levels", group="Display Config")
show_last = input.bool(true, "Hide Old Signals", group="Display Config")
p = input.color(color.lime, "Up", inline="colors", group="Display Config")
q = input.color(color.red, "Down", inline="colors", group="Display Config")
displacement = input.bool(false, "Show Displacement")
goto = input.time(timestamp("20 Jul 2050 00:00 +0300"), "End Of Calculating")
data(x) =>
ta.sma(request.security(syminfo.tickerid, mtf_val != '' ? mtf_val : timeframe.period, x), smoothing)
linreg = data(ta.linreg(source, length, offset))
linreg_p = data(ta.linreg(source, length, offset + 1))
plot(linreg, 'Regression Line', linreg > linreg[1] ? p : q, editable=true)
x = bar_index
slope = linreg - linreg_p
intercept = linreg - x * slope
deviationSum = 0.0
for i = 0 to length - 1 by 1
deviationSum += math.pow(source[i] - (slope * (x - i) + intercept), 2)
deviationSum
deviation = math.sqrt(deviationSum / length)
x1 = x - length
x2 = x
y1 = slope * (x - length) + intercept
y2 = linreg
var line b = na
var line dp = na
var line dm = na
updating = goto >= time
if updating
b := line.new(x1, y1, x2, y2, xloc.bar_index, extend.right, color.aqua, width=line_thick)
if not displacement
line.delete(b[1])
dp := line.new(x1, deviation * dev + y1, x2, deviation * dev + y2, xloc.bar_index, extend.right, q, width=line_thick)
if not displacement
line.delete(dp[1])
dm := line.new(x1, -deviation * dev + y1, x2, -deviation * dev + y2, xloc.bar_index, extend.right, p, width=line_thick)
if not displacement
line.delete(dm[1])
dm_current = -deviation * dev + y2
dp_current = deviation * dev + y2
buy = ta.crossunder(close, dm_current)
sell = ta.crossover(close, dp_current)
alertcondition(buy, 'Buy Lin Reg', 'Crossing On the Lower Regression Channel')
alertcondition(sell, 'Sell Lin Reg', 'Crossing On the Higher Regression Channel')
plotshape(buy, 'BUY', shape.labelup, location.belowbar, color.new(color.lime, 0), text='BUY', textcolor=color.new(color.black, 0), show_last=not show_last? 99999999 : length)
plotshape(sell, 'SELL', shape.labeldown, location.abovebar, color.new(color.red, 0), text='SELL', textcolor=color.new(color.white, 0), show_last=not show_last ? 99999999 : length)
//@version=5
indicator('Linear Regression ++ [Dev Lucem]', 'Lin Reg ++ [DL]', overlay=true)
mtf_val = input.timeframe('', 'Resolution', inline="config", group="Algorithm Config")
source = input.source(close, inline="config", group="Algorithm Config")
length = input.int(100, minval=1, inline="config1", group="Algorithm Config")
dev = input(2.0, 'Deviation', inline="config1", group="Algorithm Config")
offset = input.int(0, minval=0, inline="config2", group="Algorithm Config")
smoothing = input.int(1, minval=1, inline="config2", group="Algorithm Config")
line_thick = input.int(4, 'S&R Size', minval=1, maxval=4, inline="levels", group="Display Config")
show_last = input.bool(true, "Hide Old Signals", group="Display Config")
p = input.color(color.lime, "Up", inline="colors", group="Display Config")
q = input.color(color.red, "Down", inline="colors", group="Display Config")
displacement = input.bool(false, "Show Displacement")
goto = input.time(timestamp("20 Jul 2050 00:00 +0300"), "End Of Calculating")
data(x) =>
ta.sma(request.security(syminfo.tickerid, mtf_val != '' ? mtf_val : timeframe.period, x), smoothing)
linreg = data(ta.linreg(source, length, offset))
linreg_p = data(ta.linreg(source, length, offset + 1))
plot(linreg, 'Regression Line', linreg > linreg[1] ? p : q, editable=true)
x = bar_index
slope = linreg - linreg_p
intercept = linreg - x * slope
deviationSum = 0.0
for i = 0 to length - 1 by 1
deviationSum += math.pow(source[i] - (slope * (x - i) + intercept), 2)
deviationSum
deviation = math.sqrt(deviationSum / length)
x1 = x - length
x2 = x
y1 = slope * (x - length) + intercept
y2 = linreg
var line b = na
var line dp = na
var line dm = na
updating = goto >= time
if updating
b := line.new(x1, y1, x2, y2, xloc.bar_index, extend.right, color.aqua, width=line_thick)
if not displacement
line.delete(b[1])
dp := line.new(x1, deviation * dev + y1, x2, deviation * dev + y2, xloc.bar_index, extend.right, q, width=line_thick)
if not displacement
line.delete(dp[1])
dm := line.new(x1, -deviation * dev + y1, x2, -deviation * dev + y2, xloc.bar_index, extend.right, p, width=line_thick)
if not displacement
line.delete(dm[1])
dm_current = -deviation * dev + y2
dp_current = deviation * dev + y2
buy = ta.crossunder(close, dm_current)
sell = ta.crossover(close, dp_current)
alertcondition(buy, 'Buy Lin Reg', 'Crossing On the Lower Regression Channel')
alertcondition(sell, 'Sell Lin Reg', 'Crossing On the Higher Regression Channel')
plotshape(buy, 'BUY', shape.labelup, location.belowbar, color.new(color.lime, 0), text='BUY', textcolor=color.new(color.black, 0), show_last=not show_last? 99999999 : length)
plotshape(sell, 'SELL', shape.labeldown, location.abovebar, color.new(color.red, 0), text='SELL', textcolor=color.new(color.white, 0), show_last=not show_last ? 99999999 : length)