Prediction Interval Envelope
Most price envelopes assume a shape: a Bollinger-style band assumes returns are roughly normal and scales a standard deviation; an ATR channel assumes a fixed multiple is the right width regardless of skew. Real return distributions are rarely that tidy - they carry fat tails and asymmetric skew that a normal-distribution assumption quietly discards. This indicator instead builds an EMPIRICAL distribution directly: at each bar it gathers a trailing sample of already-REALISED k-bar-ahead returns (each one computed from bars that were fully historical at the time, so nothing here peeks at unrealised future price action), sorts them, and reads off the requested lower/upper percentile by linear interpolation between order statistics - the standard "type 7" empirical quantile estimator used by R and Excel's PERCENTILE.INC. The band around the current bar is that percentile applied to the current close. Because the quantiles come straight from the sorted sample, whatever skew or fat-tailedness the market's own k-bar returns have shown recently carries straight through into the band shape - a persistently right-skewed instrument gets a visibly asymmetric envelope, not a symmetric one forced onto it by a normal-distribution formula. Notes and limitations - This is a historical/empirical band, not a forecast model - it says "here is the range k-bar returns have actually landed in recently", not "here is where price will go". A genuine regime change can and will produce moves outside even a wide empirical band. - Requires InpSampleBars + 2 x InpHorizonBars bars of history behind every plotted bar; on a freshly opened chart with short history the indicator will not plot until enough bars have loaded. - Percentile choice is a direct trade-off: wider percentiles (e.g. 5/95) rarely get touched but say little; narrower ones (e.g. 25/75) get touched often and say more about the "normal" range, less about tail risk. - Not a repainting indicator - each bar's band depends only on returns realised at or before it.
Indicator · MT4 · v1.0 · Free
About Prediction Interval Envelope
Prediction Interval Envelope is an indicator for MetaTrader 4. It has 5 settings, such as Horizon bars, Sample bars and Lower percentile. MQL source code included.
Files in the download: PredictionIntervalEnvelope.mq4, PredictionIntervalEnvelope.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Horizon bars | 10 | k: how many bars ahead the interval is projected for |
| Sample bars | 300 | Trailing sample size of realised k-bar returns used to build the quantiles |
| Lower percentile | 10.0 | Lower band percentile (0-100) |
| Upper percentile | 90.0 | Upper band percentile (0-100) |
| Max bars to process | 500 | Cap on how many bars back to (re)compute on first load |
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: Bollinger Bands · ATR · Channels & Envelopes · MT4 Indicator · MQL4 Source Code