Linear Regression Channel Node

The Linear Regression Channel fits a straight line through the last N bars and draws bands a set number of standard deviations either side. Its live and completed lines, slope, width, fit, touches and breakouts, and how traders use them.

NodeBy AlgoLiftUpdated 7 min read
On this page 10How it worksLive lines and completed linesSlope, width and fitTouches and breakoutsExample: buy dips in a clean uptrendSettingsOutputsUse something else whenWhen it doesn't behaveGoing further

Is the market trending, how steeply, and how far from that trend is price right now? The Linear Regression Channel answers all three from one fit. It runs the straight line that best fits recent prices, puts a band above and below it at a set number of standard deviations, and reports the slope, how neatly price follows the line, and when price touches or breaks the edges.

Takes
Nothing. It reads its series' candles
Gives
The channel's lines, its slope, width and fit, and touch and breakout signals
Reach for it
Buying dips in a trend, fading stretches, or catching a break out of the channel

How it works

Each time a bar closes, the node takes the last Lookback Bars of price (the close, unless you pick another source) and fits the least-squares line through them, the same line a spreadsheet trendline would draw. That's the midline. Then it measures how widely prices scatter around the line, as a standard deviation, and sets the upper and lower bands that many deviations away (Deviation Mult., 2 by default). The fit is redone on every bar, so the channel slides and tilts as bars arrive and leave the window. It isn't a line drawn once and left on the chart.

Live lines and completed lines

Each line comes twice, and picking the right one matters. The Completed lines (midline, upper band, lower band) are the channel's values at the last completed bar, where the fit ends. The Projected lines, marked (Live), extend the same fit one bar further, into the bar that's forming now. Neither moves inside a bar: both are set when a bar closes.

When you compare Current Price with the channel, use the Projected lines. They're where the channel is now. A Completed line is one bar behind, off by one bar's worth of slope. The chart draws the three Projected lines by default.

Slope, width and fit

Trend Slope is how far the line rises per bar, in points (dollars on stocks). Positive is up, negative down, and a slope of 0.5 on ES means the line climbs half a point every bar. Because it's per bar and in price units, the same trend reads differently on 5m and 1h bars, and on ES and NQ.

Channel Width is the distance from the lower band to the upper, in points. It grows when price scatters around the line and shrinks when price hugs it, which makes it a volatility reading in its own right.

R-Squared (Fit) runs from 0 to 1 and says how much of the price movement in the window the line explains. Near 1, price has been moving in an orderly line. Near 0, the line is a guess drawn through chop. (The Linear Regression indicator reports its R-squared from 0 to 100, so a threshold copied from one doesn't fit the other.)

Touches and breakouts

Touched Upper Band is true for the bar after a candle whose high reached the upper band, even if it closed back inside. Touched Lower Band is the same for a low reaching the lower band. Touch Tolerance widens the target: at 5%, coming within 5% of the channel's width counts. The bands are fitted to closes by default while touches use highs and lows, so wicks reach a 2-deviation band more often than the number suggests.

Breakout Above is true for the bar after the first close above the upper band, when the close before it was still at or below the band. Breakout Below mirrors it. It marks the moment price leaves, not every bar it stays outside.

Top Touch Count and Bottom Touch Count look back over the whole window and count how often price touched the current lines, carried back across it. With Touch Logic on Retrace Required, the default, a touch counts once and then waits until price pulls back Retrace to Reset of the channel's width (50% is all the way to the midline), so a run of bars riding the band counts as one touch. Raw (Every Bar) counts every bar that touches.

Example: buy dips in a clean uptrend

Say you trade ES 15m and want to buy pullbacks, but only while the market is trending up in an orderly way.

Add a Linear Regression Channel with its defaults (50 bars, 2 deviations). Wire Trend Slope into a Comparison, Greater Than a Constant of 0, so the line points up. Wire R-Squared (Fit) into another, Greater Than 0.6, so price has been following the line rather than chopping around it. Then compare Current Price, Less Than or Equal, with Projected Lower Band (Live): price is down at the bottom of the channel. AND the three through a Logic node set to three inputs, into a long Entry.

For the stop, measure the Bracket Order's stop from a level: wire Projected Lower Band (Live) into the stop's level input and set the distance to 3 points. The level is read once, when the trade fills, so the stop stays put while the channel keeps sliding.

Settings

Load Preset has four starting points: Standard Mean Reversion (the defaults), Fast Channel (Fuzzy Touches) with 20 bars and a 5% tolerance, Macro Trend Channel with 100 bars, 2.5 deviations and the OHLC/4 average, and Extreme Reversion (3σ) with 3 deviations and an 80% reset.

Lookback Bars
Default 50
How many completed bars the line is fitted to. The editor's slider runs from 5 to 999.
Deviation Mult.
Default 2
How many standard deviations the bands sit from the line.
Price Source
Default Close Price
The price the line is fitted to: Close Price, Typical (HL/2), Typical (HLC/3) or Average (OHLC/4).
Touch Logic
Default Retrace Required
Retrace Required counts a touch, then waits for a pullback before counting another. Raw (Every Bar) counts every bar that touches.
Retrace to Reset
Default 50%
How far price must pull back into the channel, as a share of its width, before another touch counts. 50% is the midline. Unused on Raw.
Touch Tolerance
Default 0%
How close to a band still counts as a touch, as a share of the channel's width.

Outputs

Projected Midline (Live)
Number
The midline extended into the forming bar. The one to compare with Current Price.
Projected Upper / Lower Band (Live)
Number
The bands extended into the forming bar.
Completed Midline
Number
The midline at the last completed bar.
Completed Upper / Lower Band
Number
The bands at the last completed bar.
Breakout Above / Below
True or false
True for the bar after the first close beyond a band.
Touched Upper / Lower Band
True or false
True for the bar after a candle's high (or low) reached the band.
Trend Slope
Number
The line's rise per bar, in points. Positive is up.
Channel Width
Number
Upper band minus lower band, in points.
R-Squared (Fit)
Number
From 0 to 1, how well the line fits the window's prices.
Top / Bottom Touch Count
Number
How many touches of each band across the window.

Use something else when

Only the line, its slope or its fit
The indicator gives the regression line, slope and R-squared without the bands and touch logic.
Bands around an average, not a trend line
Standard deviation bands around a moving average, which bend with price instead of running straight.
A channel that holds every candle
Same line, but its edges sit at the farthest price in the window instead of a number of standard deviations.
The highest high or lowest low of N bars
A level from past bars belongs in Price History. Donchian Channels draws the same thing as a channel.

When it doesn't behave

Breakout Above fires once, then goes quiet while price keeps going

That's what it's for: it marks the bar after price first closes outside, not every bar it stays there. For "while price is above the channel", compare Current Price with Projected Upper Band (Live) instead.

My entries trigger a few ticks away from the band on the chart

You're probably comparing with a Completed line, which is one bar behind the channel the chart draws. Switch the Comparison to the Projected (Live) line.

A slope threshold that worked on ES does nothing on NQ

Slope is in points per bar, so it scales with the instrument's price and volatility and with the timeframe. To use one threshold everywhere, divide Trend Slope by an ATR on the same series with a Math node, and compare the result: slope in ATRs per bar.

The touch counts look far too high

Check Touch Logic. On Raw, every bar that tags a band counts, so a slow grind along the upper band racks up a dozen. Retrace Required counts that grind once. A large Touch Tolerance inflates counts too.

Going further

For the moment price trades through a band, rather than a close beyond it, use a Crossover on the Intrabar clock with Current Price on a and Projected Upper Band (Live) on b. The projected band holds still for the whole bar, which is what an intrabar crossover needs, and the entry fills on the trade that breaks it. Unlike the structure nodes, the channel is rebuilt from its window on every bar and carries nothing across the engine's monthly chunks, so a Crossover can read it.

Slope and R-squared also make a regime filter on their own: a rising line with a high R-squared is a trend worth following, and a low R-squared is chop that a mean-reversion idea may prefer. Lookback and deviation change everything, and channels sweep through presets, so save each variant you mean to test as one and keep the list short. A channel tuned until every past dip touched its lower band has learned the past, not the market.

Or ask the copilot