Standard Deviation Channel
A moving average channel bands price around a simple average, which reacts slowly to a sloped trend and drifts the bands away from price as the trend develops. A regression channel instead fits the actual trend line through the trailing window with least squares, so the midline tracks the slope of the move rather than lagging behind it, and the bands are set by how far price actually scattered away from that fitted line, not from an arbitrary average. At every bar this refits the least-squares line over the trailing InpPeriod prices from scratch, computes the population standard deviation of the residuals in that same window, and plots the midline plus and minus InpDeviations times that value. Nothing is carried over from the previous bar's fit, so there is no accumulated drift and no way for history to repaint once a bar closes - only the trailing window moves. This is the statistical sibling of LinRegChannel, published separately. Where this indicator bands with a standard deviation multiple, LinRegChannel bands with the single widest deviation actually seen in the window, so its rails touch the most extreme point exactly instead of a statistical measure. Use whichever matches how you think about the channel - a probability-style band, or a hard envelope. Notes and limitations - Needs InpPeriod bars of history before the first value appears; earlier bars are intentionally left empty rather than guessed. - Recomputed completely at every bar from raw price, with no dependency on its own previous output, so there is nothing here that can repaint. - The refit runs an O(InpPeriod) least-squares pass per bar, twice (once for the fit, once for the deviation), so a very large InpPeriod on a very deep history can be noticeably slower to build than a simple moving average - normal use is unaffected. - A regression channel describes the recent trend, not a forecast; a sharp change in direction shows up as the midline catching up over several bars, not instantly.
Indicator · MT4 · v1.0 · Free
About Standard Deviation Channel
Standard Deviation Channel is an indicator for MetaTrader 4. It has 3 settings, such as Period, Deviations and Applied price. MQL source code included.
Files in the download: StdDevChannel.ex4, StdDevChannel.mq4, StdDevChannel.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Period | 50 | Regression window, in bars |
| Deviations | 2.0 | Band width, in standard deviations |
| Applied price | PRICE_CLOSE | Applied price |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Indicators.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the indicator from the Navigator onto a chart and adjust the settings.
Tags: Moving Average · Channels & Envelopes · Trend · Trailing Stop & Break-even · MT4 Indicator · MQL4 Source Code