Loading…

Linear Regression Channel

Most regression channels band the fitted line with a statistical measure such as standard deviation, which is useful for probability but does not guarantee the channel actually contains every price in the window. This version instead finds, at every bar, the largest positive residual and the largest negative residual between price and the fitted line across the trailing InpPeriod bars, and offsets the upper and lower rails by exactly those two values. The result is a channel whose edges pass through the most extreme high and low deviation in the window, parallel to the trend line through the middle - the classic "draw a channel that contains everything" construction, done arithmetically instead of by eye. The fit itself is an ordinary least-squares regression recomputed from scratch at every bar over the trailing window, so the midline is the actual best-fit trend line, not an approximation. Because both the fit and the envelope are rebuilt from raw price every time, with no dependency on the indicator's own previous output, the channel cannot drift and a closed bar's channel never repaints. Its statistical sibling, StdDevChannel, uses a standard deviation multiple for the bands instead of the extreme envelope - published separately so either construction can be chosen without carrying inputs the other does not need. Notes and limitations - Needs InpPeriod bars of history before the first value appears; earlier bars are intentionally left empty rather than guessed. - A single outlier bar inside the window sets the rail on its side for as long as that bar stays in the trailing window - this channel does not smooth away extremes, it is built from them by design. - Recomputed completely at every bar from raw price, so there is nothing here that can repaint once a bar closes; the whole channel including older bars shifts only as the trailing window itself moves forward. - The regression pass is O(InpPeriod) per bar, run twice (fit, then envelope search), so a very large InpPeriod on very deep history can be slower to build initially than a simple moving average.

Indicator · MT4 · v1.0 · Free

About Linear Regression Channel

Linear Regression Channel is an indicator for MetaTrader 4. It has 2 settings, such as Period and Applied price. MQL source code included.

Files in the download: LinRegChannel.ex4, LinRegChannel.mq4, LinRegChannel.txt.

Settings

SettingDefaultWhat it does
Period100Regression window, in bars
Applied pricePRICE_CLOSEApplied price

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Indicators.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the indicator from the Navigator onto a chart and adjust the settings.

Download the PDF guide

Tags: Channels & Envelopes · Trailing Stop & Break-even · MT4 Indicator · MQL4 Source Code

MetaTrader 4 & 5 indicators · PolyMaria