Indicator · Pine Script v5 · On the chart

Lin Reg Simplified

by g-moe· code credited to goodgains

Lin Reg Simplified calculates a custom linear regression channel overlaid on the main price chart.

View on GitHub

Repaints

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code51
Settings5inputs
LicenceNone statedfile: MPL-2.0
Last update5 months ago27 May 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

51 lines of Pine Script v5 from Tradingview/lin-reg-simplified.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

lin-reg-simplified.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © goodgains


//@version=5
indicator("Lin Reg Simplified", overlay= true)

// @keywords: linear-regression, regression-channel, deviation-bands, wma-sma-blend, slope-line, upper-lower-bands, midline, hlc3-regression, channel-width, trend-slope, regression-lines, price-envelope, statistical-deviation, extended-lines, three-band, overlay-channel, length-deviation, draw-linreg, simplified-regression, band-plots

//Linear Regression Channel
linreg_length = input.int(title='Length ', defval=100, inline='2', maxval = 500, minval = 10, group='Regression Channel Settings')
linreg_deviation = input.float(title='Deviation ', defval=2, step=0.25, minval=0.5, maxval=5.00, inline='2', group='Regression Channel Settings')






linreg_bull = input.color(color.new(#27a69b, 70), title='Bull Color', inline='3', group='Regression Channel Settings')
linreg_mid = input.color(color.new(#000000, 0), title='Mid Color', inline='3', group='Regression Channel Settings')
linreg_bear = input.color(color.new(#b63632, 70), title='Bear Color', inline='3', group='Regression Channel Settings')


calculate_linreg(length, deviation) =>

    a = ta.wma(hlc3, length)
    b = ta.sma(hlc3, length)
    A = 4 * b - 3 * a
    B = 3 * a - 2 * b
    m = (A - B) / (length - 1)
    
    d = 0.00
    for i = 0 to length - 1 by 1
        l = B + m * i
        d += math.pow(hlc3[i] - l, 2)
        d

    linreg_1 = math.sqrt(d / (length - 1)) * deviation

    [A, m, B, linreg_1]
    
[tf1_A, tf1_m, tf1_B, tf1_linreg1] = calculate_linreg(linreg_length, linreg_deviation)

drawLinReg(color_input, A, m, B, k) =>
    line lr = line.new(bar_index - linreg_length + 1, A + k, bar_index + 50, -m*50 + (B + k), extend = extend.none, color = color_input, width = 1)
    line.delete(lr[1])
    
if true
    drawLinReg(linreg_mid, tf1_A, tf1_m, tf1_B, 0)
    drawLinReg(linreg_bear, tf1_A, tf1_m, tf1_B, tf1_linreg1)
    drawLinReg(linreg_bull, tf1_A, tf1_m, tf1_B, -tf1_linreg1)

Overview

Lin Reg Simplified uses a combination of weighted moving average (WMA) and simple moving average (SMA) applied to HLC3 prices to compute the trend slope, middle line, and standard deviation offset bands. Users can configure the regression length, deviation multiplier, and line colors for upper, lower, and middle bounds. Because the script dynamically draws and deletes line objects anchored to the current bar index, past channel lines shift on live bar updates, resulting in visual repainting.

Details

Published by

g-moe on GitHub

Code credit

goodgains, as written in the script's header

Draws

On the price chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Length int100linreg_length
Deviation float2linreg_deviation
Bull Colorcolorcolor.new(#27a69b, 70)linreg_bull
Mid Colorcolorcolor.new(#000000, 0)linreg_mid
Bear Colorcolorcolor.new(#b63632, 70)linreg_bear
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

575 stars

This indicator detects equal highs and lows by comparing prices within user-defined left and right bars using a tolerance percentage. It plots horizontal lines on the price chart for equal highs in one color and lows in another. A screener allows input of mult

Indicator v5 Support & resistanceTrend
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Equal Highs and Lows with Screener

Function - Linear Regression

by ricardosantos79
261 stars

This indicator fits a linear regression through stored pivot highs and lows and draws the resulting channel on the price chart. A function returns predicted values, maximum and minimum deviations, and the average absolute deviation. Confirmed two-bar pivots up

Indicator v5 TrendSupport & resistance
Updated 4 years ago · None stated GitHub repository of Function - Linear Regression

AI Trend

by dearvn
257 stars

AI Trend is an indicator that plots pivot points, trend lines, and support and resistance levels directly on the price chart. It marks high and low pivots based on user-defined length, draws trend lines that check for violations at specified points, and identi

Indicator v5 TrendSupport & resistance
Updated 7 weeks ago · None stated GitHub repository of AI Trend

Dynamic Linear Regression

by TradersPost
228 stars

Dynamic Linear Regression calculates and plots linear regression trendlines and standard deviation channels directly on the price chart over a user-selected time period. Traders can configure static channels locked at the end time, dynamic channels that contin

Indicator v6 TrendSupport & resistance
Updated 3 months ago · None stated GitHub repository of Dynamic Linear Regression

Ichimoku Cloud

by harryguiacorn
220 stars

This indicator plots Ichimoku Cloud elements on the price chart, including Tenkan-sen, Kijun-sen, Senkou Span A and B lines with optional Chikou Span. It signals trend changes via Tenkan-sen and Kijun-sen crosses and places arrows at Kijun-sen direction shifts

Indicator v5 TrendMoving averages
Updated 1 year ago · None stated GitHub repository of Ichimoku Cloud
219 stars

This indicator identifies local swing highs and swing lows to construct a Zig Zag pattern on the main price chart. It evaluates pivot points based on a customizable number of surrounding left and right bars. Using persistent variables, the script tracks previo

Indicator v4 Support & resistanceTrend Repaints
Updated 5 years ago · None stated GitHub repository of Teaching: Finding Highs and Lows 6

More Trend scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers