Skip to content

Free MT5 indicator

Linear Regression Channel

Linear regression channel for MT5 over the last N bars with standard or maximum deviation bands, redrawn each bar, with breakout alerts.

Trendv1.0MetaTrader 5 (MQL5) Compiles with 0 errors Alerts

What it does

A linear regression line is the straight line that best fits a set of prices, in the least-squares sense. This indicator fits that line to the last N bars and draws a channel around it, showing both the direction of the recent trend and how far price normally strays from it. The channel is drawn with chart objects and refits itself on every new bar.

How it works

Number the bars in the window x = 0 (oldest) to N - 1 (newest), with y the applied price.

  • Slope = (N x sum(xy) - sum(x) x sum(y)) / (N x sum(x squared) - sum(x) squared).
  • Intercept = (sum(y) - slope x sum(x)) / N.
  • Fitted value at bar x = intercept + slope x x.
  • Residual = y - fitted value.
  • Channel half-width is either the multiplier x the standard deviation of the residuals, or the largest absolute residual (maximum deviation mode).
  • The middle line and the upper and lower channel lines run from the oldest bar to the newest bar in the window and can be extended to the right.

By default only closed bars are used and the channel updates once per bar. An alert is sent when a newly closed bar closes outside the channel after the previous bar closed inside it.

How to use it

  • Slope: a rising middle line indicates an uptrend over the window, a falling one a downtrend, a flat one a range.
  • Position: price near the lower line of a rising channel is at the low end of its normal deviation, which some traders treat as a pullback area within the trend.
  • Breaks: a close outside the channel shows price moving further than the window's typical deviation, which can mark acceleration or the end of the trend.

Choose the window to match the swing you care about, for example 100 bars on H1 for several days of movement. The channel is a statistical cousin of hand-drawn trendlines and pairs well with support and resistance analysis.

Settings

InputDefaultWhat it changes
Bars in the regression100Length of the fitted window
Applied priceClosePrice series for the fit
Channel width methodStandard deviationStatistical width or maximum excursion
Standard deviation multiplier2.0Width in standard deviation mode
Use closed bars onlytrueOff refits on every tick including the live bar
Extend lines to the righttrueProjects the channel forward
Colours, widthgold / blue, 1Line appearance
Popup alert / Push notificationfalseAlerts once per bar on a close outside the channel

Limitations

  • The channel repaints by design: every new bar refits the whole window, so past positions of the channel change.
  • A straight line cannot describe curved or choppy markets well.
  • The result depends heavily on the window length; different lengths can show opposite slopes.
  • Extending the channel to the right assumes the trend continues, which it may not.

Key inputs

Key inputs of Linear Regression Channel
InputDefaultDescription
Bars in the regression100Number of bars the regression line is fitted to.
Applied priceClosePrice series used for the fit.
Channel width methodStandard deviation x multiplierStandard deviation of residuals times a multiplier, or the largest distance from the line.
Standard deviation multiplier2.0Channel half-width in standard deviations (standard deviation mode).
Use closed bars only (update once per bar)trueFit the channel to closed bars and redraw once per new bar.
Extend lines to the righttrueProjects the channel beyond the last bar.

Educational tools, not advice. Indicators and Expert Advisors describe price; they do not predict it, and past behaviour does not guarantee future results. Test everything on a demo account first and never risk money you cannot afford to lose. See our disclaimer.

Keep exploring

Related mt5 indicators