MarketInOut Stock Screener Log In | Sign Up

Linear Regression and Time Series Forecast

By MarketInOut · Updated November 9, 2026

Linear regression fits the straight line that best describes a set of prices. In technical analysis it is used in two ways: as a regression line or channel drawn through a block of recent bars, and as a Time Series Forecast (also called the moving linear regression), an indicator that plots the end point of a new regression line on every bar. Both treat the line as a fair-value trend and look at how far, and for how long, price strays from it.

How it is calculated

The line is found with the least squares method: of all possible straight lines through the last N closes, it is the one that minimizes the sum of the squared vertical distances between the closes and the line.

x = bar number 1 ... N,  y = close
slope b     = (N × Σxy − Σx × Σy) / (N × Σx² − (Σx)²)
intercept a = (Σy − b × Σx) / N
line value  = a + b × x

The slope is the trend’s average gain or loss per bar. The value of the line on the last bar (x = N) is the current regression value, and that is what the Time Series Forecast plots. Many charting packages add one more bar of slope (x = N + 1) so the indicator projects the next bar instead; the difference is small, but worth knowing when you compare platforms.

A regression channel adds two lines parallel to the regression line. In the original version, often credited to Gilbert Raff, they pass through the close farthest from the line. The more common modern version places them a set number of standard deviations (usually 2) above and below it, which is how our channel is built.

How traders use it

  • Trend direction and strength. A rising slope means an uptrend, a falling one a downtrend. A steep slope with closes hugging the line is a strong, orderly trend; a flat slope with wide swings is a range.
  • Distance from fair value. The regression line is the “equilibrium” of the period. Price far above it is stretched to the upside, far below it stretched to the downside. Traders in an uptrend look for pullbacks to the lower channel line.
  • Channel breaks. Price briefly poking outside the channel is normal. Closing outside it for several bars, especially against the slope, suggests the trend that defined the channel is ending.
  • A faster moving average. The Time Series Forecast is read like a moving average (price above it is bullish, below it bearish), but it fits the data rather than averaging it, so it lags less and turns sooner after a change in direction.

Settings and common mistakes

  • Period. 100 bars is a common channel length for daily charts; 20 to 50 bars suits swing trading. The Time Series Forecast is typically used with 14 to 50 bars.
  • Forgetting that the line moves. A regression channel is recalculated as each new bar arrives. Its slope and boundaries shift, so a touch of yesterday’s lower line is not quite a touch of today’s.
  • Fitting a line to a curve. A straight line describes a steady trend. After a sharp reversal inside the window, the line sits in the middle of two opposite moves and says little. Look at the chart before trusting the slope.
  • Reading the forecast literally. The Time Series Forecast only extends the recent trend; it does not predict the next price. Overshoot is common when a trend ends.

SPY (S&P 500 ETF), daily, with a 100-day linear regression channel.

Live chart: SPY (S&P 500 ETF), daily, with a 100-day linear regression channel two standard deviations wide. The chart updates every trading day.

Screen for it on MarketInOut

Our formula language has the regression channel as mlr(period, stddev) (the regression line), ulr and llr (the upper and lower lines) and slr (the slope). Stocks in a rising 100-day channel that just bounced up from its lower line:

exch(nyse,nasdaq) and type(stock) and price > 1 and advol(21) > 1
and slr(100,2) > 0 and price bon_up llr(100,2)

Stocks breaking above the upper channel line on above-average volume:

exch(nyse,nasdaq) and type(stock) and price > 1 and advol(21) > 1
and price ca ulr(100,2) and rvol(21) > 1.5

Related: Trend lines, Moving averages, Standard deviation.




Disclaimer - Privacy Policy - Terms of Service - Cookies - FAQ - Affiliates - Blog