◆ New — Strategy Validator, Code Fixer & Prop Compliance Checker are live. Try one free →
Home / Indicators / Linear Regression Channel
Trend indicator

Linear Regression Channel

A best-fit straight line through recent price with parallel deviation bands — a legitimate statistical summary that refits, and therefore repaints, on every bar.

Illustrative diagram — not live market data.

What it is

A linear regression channel fits a straight line through the last N bars of price using least squares — the standard statistical method that minimizes the sum of squared distances between price and the line — then draws parallel bands above and below it, usually at a multiple of the standard deviation of the residuals. It answers 'what direction and how fast has price trended over this window, and how tightly?' And to answer the question directly: yes, it repaints, by design. Every new bar drops the oldest point from the window and refits the entire line, so the channel's historical position changes as new data arrives. That is not a bug or a scam — it is simply what a rolling best fit is. The honest distinction is between uses: describing the current window's trend and dispersion is legitimate statistics; backtesting rules against where the channel appears on historical bars is invalid, because that picture shows the final fit, not what anyone saw live. The channel describes the past window; it predicts nothing. Educational content only, not financial advice — trading involves risk of loss.

How it works

Least squares finds the slope b and intercept a that minimize Σ(price − (a + b·t))² across the window, using closed-form formulas from the window's sums of price and time. The midline is that fitted line; the channel edges sit at ± multiplier × the standard deviation of the residuals (some variants use the maximum deviation instead). On each new bar the whole fit recomputes — the line can pivot, its historical portion shifting up or down — so the straight channel you see drawn across the last 100 bars is the fit as of now, not a record of past fits. The only value that is fixed once its bar closes is the current endpoint of each bar's fit, and the series of those endpoints is exactly the Least Squares Moving Average (LSMA). Plot that endpoint history, as the code below does, and you get a curve that looks nothing like the straight channel — which is the visual proof of the repainting: the straight line and the endpoint trail are the honest and the hindsight views of the same calculation.

How traders read it

Common settings

Length 100 is a common default, with 50 for shorter reads and 200 for longer ones; deviation multiplier 2.0 applied to the standard deviation of residuals (some tools instead offer separate upper/lower deviation inputs or a max-deviation mode); source is usually the close. As with any windowed fit, changing the length changes the slope, the bands, and every reading — the number is a lens choice, not a discovered truth.

Strengths

Pitfalls to watch

Pine v6 example

//@version=6
indicator("Rolling Linear Regression Channel (Endpoint)", overlay = true)

len  = input.int(100, "Regression Length", minval = 2)
mult = input.float(2.0, "Band Multiplier", step = 0.25)
src  = input.source(close, "Source")

// ta.linreg returns the ENDPOINT of the least-squares line refit on each bar.
// The plotted history is a trail of endpoints (the LSMA) — deliberately NOT
// the straight channel a drawing tool shows, because that picture repaints.
mid = ta.linreg(src, len, 0)
dev = ta.stdev(src - mid, len)

plot(mid,             "Regression Endpoint (LSMA)", color = color.blue)
plot(mid + mult * dev, "Upper Band",                color = color.gray)
plot(mid - mult * dev, "Lower Band",                color = color.gray)

Pro tip: Keep two mental objects separate: the drawn channel (a hindsight fit, useful for describing the window, unusable for signals) and the endpoint series (fixed once each bar closes, the only honest input to a rule). If you build anything on this tool, build it on ta.linreg endpoints evaluated on confirmed bars, then run it through a repaint check before trusting a single backtest number. Educational information only, not financial advice — a fitted line describes the past, predicts nothing, and all trading carries risk of loss.

Built an indicator from this? Run it through the Validator to catch look-ahead bias and repainting, or convert a strategy to Pine Script.

Educational only — not financial advice, not a recommendation to trade. No indicator is predictive; trading involves substantial risk of loss.

Catch the bug that compiles.Run auditGet Pro