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
| Input | Default | What it changes |
|---|---|---|
| Bars in the regression | 100 | Length of the fitted window |
| Applied price | Close | Price series for the fit |
| Channel width method | Standard deviation | Statistical width or maximum excursion |
| Standard deviation multiplier | 2.0 | Width in standard deviation mode |
| Use closed bars only | true | Off refits on every tick including the live bar |
| Extend lines to the right | true | Projects the channel forward |
| Colours, width | gold / blue, 1 | Line appearance |
| Popup alert / Push notification | false | Alerts 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.

