← Back to Home
Trading Signal / Indicator
📏

Linear Regression Channel

Project statistical price trends and identify deviation extremes.

Start Automating Free →

Want to automate this strategy? Try auto-Trading free — no credit card required.

Linear Regression Channel chart

Overview

What is Linear Regression Channel?

The Linear Regression Channel is a statistical tool that fits the best-fit straight line through a specified number of price bars using the least-squares method, then draws parallel channel lines at one and two standard deviations above and below the regression line. Unlike hand-drawn trend channels that rely on connecting specific highs/lows, the linear regression is mathematically objective — it is the statistically optimal trend line for the selected data.

The centre line (regression line) represents the statistical "fair value" of price during the selected period. The outer channel bands represent how far price typically deviates from this mean. Prices that reach the +2 SD upper channel are considered statistically overextended and likely to revert toward the centre; prices at −2 SD are oversold on the same basis.

The slope of the regression line quantifies the trend: a steeply positive slope indicates strong upward momentum; a near-flat slope indicates consolidation; a steep negative slope indicates a downtrend. The slope can be used as a quantitative momentum signal in algorithmic strategies.

The "R-squared" value (coefficient of determination) measures how well the regression fits the price data. A high R² (above 0.8) means price is trending cleanly along the regression line — ideal for trend-following strategies. A low R² means price is choppy and not well-described by a linear model — better suited for range-based approaches.

Linear regression is also used in the Kirshenbaum Bands, the Raff Regression Channel, and various quantitative pairs trading implementations.

How It Works in auto-Trading

Automate It

auto-Trading's linear regression tool calculates the regression line, standard deviation channels, slope, and R² value dynamically on any timeframe and lookback period. Strategy blocks include: price crossing the upper/lower channel bands (mean reversion signals), slope-based momentum filters, and R² regime classification (high R² enables trend following; low R² enables range trading).

Try Free →

Strategy Code

Pick a script below, copy it, and use it on your chart.

Pine Script (TradingView)

This is a TradingView Pine Script example for this indicator. Paste it into the TradingView Pine Editor, add it to your chart, and adjust inputs for your market and timeframe.

//@version=6
strategy("Linear Regression Channel", overlay=true)
fastLen = input.int(20, "Fast Length")
slowLen = input.int(50, "Slow Length")
fast = ta.ema(close, fastLen)

Get full strategy code access

Enter your email address and full name to unlock this strategy code.

ThinkScript (thinkorswim)

This is a thinkorswim ThinkScript example for this indicator. Open thinkorswim, create a custom study, paste the script, and apply it to your chart.

input length = 50;
def lr = Inertia(close, length);
def buySignal = close crosses above lr;
def sellSignal = close crosses below lr;
AddOrder(OrderType.BUY_AUTO, buySignal, close, 1, Color.GREEN, Color.GREEN, "LR Buy");

Get full strategy code access

Enter your email address and full name to unlock this strategy code.

Ready to automate Linear Regression Channel?

Join thousands of traders who use auto-Trading to execute this strategy automatically, 24/7.

Get Started Free →

All Strategies & Signals

Continue Learning

Trading Strategies

Trading Signals & Indicators