VALYNOX
VALYNOXSTRATEGY RESEARCH TECHNOLOGY
AlphaPrimeAlphaPrime
ACADEMY / Indicators and signals

Linear regression channel strategy: rules, repainting, timeframes

A linear regression channel is traded either by fading a band touch back toward the centre line or by following a close outside a band. The drawn channel repaints because every new bar refits the whole line, so a testable rule uses only the band value known at each bar's close. Test both rules, net of costs, across neighbouring lengths.

By · Published · updated · Editorial policy

Contents
  1. How do you trade a linear regression channel, and does it repaint?
  2. How are the regression line and the standard deviation bands calculated?
  3. How is a linear regression channel different from Bollinger Bands?
  4. Does repainting affect backtests?
  5. Reversion or breakout: which rule should you test?
  6. Which timeframes and lengths suit a linear regression channel?
  7. What does a finished test of a channel-type rule look like?
  8. Frequently asked questions
  9. References

How do you trade a linear regression channel, and does it repaint?

A linear regression channel is traded in one of two ways: fade a touch of the upper or lower band back toward the centre line, or follow a close outside a band. The drawn channel repaints, because each new bar refits the whole line, so a testable rule uses only the band value known at each bar's close.

A linear regression channel is a straight line fitted through the last N closing prices, with one band above and one band below it at a fixed distance. The line is the "fair" path of price over that window; the bands mark how far price has usually strayed from it. Think of a ruler laid along a hillside: the ruler shows the slope, and the bands are two fence lines running parallel to the ruler. The linear regression indicator page defines the line itself, so this article spends its words on how to trade and test it. For where channel tools sit among the other tools you can test, see the guide to technical analysis tools and indicators.

Both trading rules read the same two bands. A reversion rule treats the bands as rubber walls: price at the upper band is stretched, so you sell and aim for the line. A breakout rule treats the bands as doors: a close beyond the upper band means the move is stronger than the window expected, so you buy and stay until price closes back inside. The repaint question has a short answer. The picture on your chart redraws its entire length every bar, so the band that appears to have sat under a low ten bars ago was not there at the time. The value of the band at that bar's close, computed from the bars up to that close, is the only number a rule can act on, and that number never changes afterwards.

How are the regression line and the standard deviation bands calculated?

The channel is a straight best-fit line through the last N closes, with two parallel bands a chosen number of standard deviations above and below it. Best-fit means the line that makes the total of the squared vertical distances from each close to the line as small as possible; this is the least-squares line you may know from a spreadsheet trend line. Each close has a distance from the line, positive if the close is above it and negative if below. The standard deviation is the typical size of those distances, so it measures how tightly or loosely the closes hug the line.

The one formula to know is:

band = line value ± k × standard deviation of the distances from the line

Here line value is the height of the fitted line at a given bar, k is the multiplier you choose (2 is the most common setting), and the standard deviation of the distances is the scatter of the closes around the line over the window. Because the scatter is one number for the whole window, both bands run parallel to the line at a constant distance. The standard deviation indicator computes the same scatter measure around a moving average instead of a sloped line.

A standard error channel is the same construction with the band distance taken from the standard error of the regression, which is the same scatter measure with a small adjustment for the number of points fitted. On a window of 100 bars the two widths are nearly equal, so a rule written for one transfers to the other with little change. The linear regression indicator that many platforms plot as a single line is simply the end value of this fitted line at each bar, which is why it looks like a fast moving average.

A linear regression channel: a straight best-fit line through the last 100 closes, with dashed bands two standard deviations above and below it at equal distance, and short ticks showing each close's distance from the line One line, two parallel bands Least-squares line, bands at ±2 SD Distance +2 SD Line −2 SD 100 bars Bands sit 2 SD from the line. So: k sets the width, 2 is usual.
The channel is a straight best-fit line through a fixed window of closes, with two parallel bands at a fixed multiple of the scatter around that line.

How is a linear regression channel different from Bollinger Bands?

Bollinger Bands bend with a moving average and change width bar by bar, while a regression channel is one straight sloped line with bands of constant width over its window, so the two give different signals on the same prices even at the same length and multiplier. Bollinger Bands measure scatter around a moving average, which curves as price curves; the regression channel measures scatter around a straight line, which only tilts. In a steady trend the regression line sits close to price and its bands are narrow, while a moving average lags behind price and the Bollinger Bands sit off-centre. In a sideways market the opposite happens: the moving average follows the wobble and the regression line cuts straight through it.

FeatureLinear regression channelBollinger Bands
Centre lineStraight least-squares line over the windowSimple moving average, curves with price
Band widthOne value for the whole window, bands parallelRecomputed every bar, bands widen and narrow
Behaviour in a trendLine tracks the slope; bands stay narrowAverage lags; price rides one band
Behaviour in a rangeLine nearly flat; touches at both bandsBands pinch, then flare on the next move
Redraws past valuesYes, whole line refits each barNo, each bar's value is final

The last row matters most for testing. A Bollinger Band value printed under a bar stays there forever; the regression channel over that same bar will move the next day. A third channel type, the Donchian channel breakout, uses the highest high and lowest low of the window with no statistics at all, and like Bollinger Bands it does not redraw.

The same prices drawn with Bollinger Bands, whose midline curves and whose bands pinch then flare, and with a regression channel, one straight line with parallel bands; at one bar price is outside the Bollinger Bands but inside the channel Same prices, different bands Bollinger (20, 2) vs channel (100, 2) Bollinger Regression Outside Inside Same bar, different signal. So: never swap one for the other.
Bollinger Bands bend with the moving average and change width with volatility; the regression channel is straight and keeps one width across the window.

Does repainting affect backtests?

Repainting only ruins a backtest when the test uses the current drawn channel to judge past bars; a backtest that stores the band value computed at each bar's close and never revises it is free of the leak. Repainting is the redrawing of an indicator's past values after new bars arrive. For a regression channel it is built in: adding bar 101 to a 100-bar window drops bar 1, refits the line, and shifts every point of the channel, including the points over bars that already closed. A rule that reads the channel as it is drawn today therefore knows where the bands "will end up", which is information from the future.

The fix is the same one used against every look-ahead leak: compute the band at bar t from bars t−N+1 to t only, record it, and act on the next bar. A one-bar check tells you which kind of test you have:

  1. Run the backtest and note the upper band value the rule saw at one chosen bar.
  2. Load ten more bars of data and read the drawn upper band over that same bar.
  3. If the two numbers differ and your test used the drawn one, the test is leaking. If your test stored the first number and ignores the redraw, it is clean.

Doing this by hand once is enough to know how your platform behaves. AlphaPrime (Valynox) freezes an indicator value at the bar close that produced it and fills on the following bar, so a channel band inside its backtesting is never read from a line that a later bar has moved, and commission and slippage are charged on every one of those fills.

The channel drawn at bar 100 and again at bar 110 covers the same bars at different heights, while the band value recorded at each bar's close stays frozen and is the only value a backtest may use Test the frozen value Bar 100 vs bar 110, hypothetical Drawn channel Close values Bar 100 Bar 110 Frozen The drawing shifts; close values don't. So: store each band at its close.
The drawn channel redraws its whole length on every new bar; the end-point value known at each bar's close never changes afterwards.

Reversion or breakout: which rule should you test?

The same two bands support two opposite rules, and the honest approach is to write both as exact rules with long and short sides, test both, and expect only one to survive costs on a given market and bar size. A band touch is a sell signal to the reversion trader and a hold-or-buy signal to the breakout trader. The indicator does not decide which is right; the market's behaviour over the window does. Park and Irwin (2007) review decades of tests of technical rules and find that results depend heavily on the costs charged and the period tested, which is exactly why both rules need a test rather than a belief.

Rule partReversion ruleBreakout rule
Long entryClose at or below the lower band; buy at the next openFirst close above the upper band; buy at the next open
Short entryClose at or above the upper band; sell at the next openFirst close below the lower band; sell at the next open
ExitClose crosses the regression line, or opposite bandClose back inside the channel
Markets it needsSideways, scatter steadyTrending, moves that keep going
Typical failureFading a trend that keeps runningPaying costs on false breaks in a range

Write the rules to the letter before the first run. A reversion entry at the lower band often looks like the second low of a double bottom pattern; the method there, turning a chart shape into exact conditions, applies to channel touches too. A common refinement is to allow reversion trades only against a stretched oscillator, for example a short at the upper band only when the RSI indicator is above 70. Add such a filter as a separate test so you can see what it changed.

Price touches the upper band of the same channel: the reversion rule sells and targets the regression line, the breakout rule buys on the first close above the band and exits when price closes back inside Same touch, opposite trades Price reaches the upper band Reversion Breakout Sell, exit at line Buy, exit inside The rule, not the band, picks the side. So: test both rules, long and short.
The same band touch is a sell for the reversion rule and a buy for the breakout rule, so the rule choice, not the indicator, decides the trade.

Which timeframes and lengths suit a linear regression channel?

Length matters more than the clock: a short window turns the channel into a noisy trend-follower, a long window makes it a slow mean-reversion frame, and the bar size only sets how much one round-trip cost takes out of each trade. A 30-bar channel on daily bars and a 30-bar channel on 5-minute bars behave alike in shape; what differs is the band width in money against the cost of a trade.

Window lengthWhat the channel doesRule it tends to suit
Around 20 to 50 barsTilts quickly, bands narrow, many touchesBreakout, with a cost check
Around 50 to 100 barsModerate slope, fewer touchesEither; test both
100 bars or moreSlow slope, wide bands, rare touchesReversion

A parameter plateau is a stretch of neighbouring settings that all give a similar result. Pardo (2008) makes this the central test of an optimization: a setting worth keeping sits in the middle of a plateau, because a small change in the market will shift the best setting a little, and a plateau survives that shift while a single spike does not. Run lengths from about 20 to 200 in steps and look at the whole row, not the top value.

Hypothetical example

Suppose a 2-standard-deviation band sits on average 10 points from the line on one bar size, and commission plus slippage for a round trip costs the equivalent of 1 point. A reversion trade from band to line targets 10 points and pays 1, so cost is a tenth of the target. On a faster bar size the same channel's band might sit 2 points from the line while the round trip still costs 1 point; now cost is half the target, and the rule has almost no room. Choose bar sizes where the first case holds.

Hypothetical net result after costs for channel lengths 20 to 200: lengths 80 to 150 form a flat plateau worth keeping, while length 30 is a single tall spike with low neighbours that is likely luck Pick a plateau, not a spike Net after costs by length, hypothetical Spike: luck Plateau: keep 20 30 40 50 60 80 100 120 150 200 One tall bar is luck; a flat row holds. So: pick from the middle of a plateau.
A setting worth keeping sits on a plateau of neighbouring lengths that behave alike, not on a single spike.

What does a finished test of a channel-type rule look like?

A channel rule is judged like any other candidate: net of commission and slippage, with its drawdown next to its profit, and with the selection it came from stated. The run below shows that shape. The data was ES daily bars from 2019-01-02 to 2025-06-30, traded long and short with one contract, charging $20 commission and $25 slippage on each trade. The rule is a stand-in built from standard indicators, not a regression channel, so the numbers illustrate how to read a report rather than how a channel performs. The candidate shown is the one the search kept out of 1,024 it tried, chosen for its return against its drawdown; keeping the best of many after the fact flatters the result, and it is not something a reader can expect to repeat.

Source: AlphaPrime product engine (CPU), run 2026-10-31. ES daily bars, 2019-01-02 to 2025-06-30, long and short, 1 contract, $20 commission and $25 slippage per trade.

NumberResult
Net profit (closed trades)$75,845
Max drawdown$34,512.5
Trades129
Win rate60.47%
Profit factor1.588
Average trade$587.95
Time in market31.61%

Read it in this order. The max drawdown of $34,512.5 against the net profit of $75,845 says the worst stretch cost close to half of everything the run made. The 129 trades over six and a half years is a thin sample for a per-trade figure, so the average trade of $587.95 carries wide uncertainty. And the count of 1,024 candidates is the number Bailey, Borwein, López de Prado and Zhu (2014) warn about: the best of that many tries is inflated by selection, and only data the search never touched can say by how much. A channel rule you build yourself deserves the same three readings.

Five steps in order: write the exact rule, set costs first, test lengths and both rules, read profit next to drawdown, run once on unseen data; going back from step four to step one is crossed out as no re-tuning Keep the test honest In this order, before trusting it 1 2 3 4 5 Exact rule Costs first Lengths, both rules Profit + drawdown One unseen run No re-tuning Look once, then stop tuning. So: hold back recent months.
The order of steps that keeps a channel rule honest, from frozen band values to a single reading of the untouched period.
Look at how the equity curve climbs and where the drawdown stretch sits, and whether the out-of-sample part keeps the same slope as the part before it. The shape tells you more than the headline number.
Look at how the equity curve climbs and where the drawdown stretch sits, and whether the out-of-sample part keeps the same slope as the part before it. The shape tells you more than the headline number. ES · daily · 2019-01-02 to 2025-06-30 · CPU engine backtest

Your next step: pick one market and one bar size, write the reversion rule and the breakout rule with band values frozen at each bar's close, run lengths from 20 to 200 with your real commission and slippage, and keep a candidate only if it sits on a plateau. Then set aside the most recent months of your data and run the kept rule on them once.

Frequently asked questions

Does a linear regression channel repaint?

Yes. Every new bar refits the line through the whole window, so the channel drawn over past bars moves. The value of the band at each bar's close, computed from the bars up to that close, does not move. A backtest or a live rule must use that frozen value and act on the next bar.

What is a standard error channel?

A standard error channel is a linear regression channel whose band distance is a multiple of the standard error of the regression instead of the standard deviation of the distances from the line. The two measures differ only by a small adjustment for the number of points fitted. On a window of 100 bars the band widths are nearly the same, so rules transfer between them with little change.

What length should I use for a linear regression channel?

Run a range of lengths, for example 20 to 200, on your market and bar size and keep a length from the middle of a plateau where neighbouring settings give similar results. Short windows around 20 to 50 bars tilt fast and suit breakout rules; windows of 100 bars or more are slow and suit reversion rules. A single length that stands out from its neighbours is more likely luck than edge.

Is the linear regression indicator the same as the channel?

The linear regression indicator plots the end value of the fitted line at each bar, which makes it look like a fast moving average. The channel adds the two bands and, on a chart, draws the full line across the window. The indicator's value at each bar is frozen; the channel's drawing over past bars is not.

References

  • Bailey, D. H., Borwein, J., López de Prado, M., & Zhu, Q. J. (2014). Pseudo-Mathematics and Financial Charlatanism: The Effects of Backtest Overfitting on Out-of-Sample Performance. Notices of the American Mathematical Society, 61(5), 458–471.
  • Pardo, R. (2008). The Evaluation and Optimization of Trading Strategies (2nd ed.). John Wiley & Sons.
  • Park, C.-H., & Irwin, S. H. (2007). What Do We Know About the Profitability of Technical Analysis? Journal of Economic Surveys, 21(4), 786–826.