Loading…

Bootstrap Confidence Moving Average

A moving average with a stdev-multiple envelope only measures how spread out a window's prices are - it cannot tell a window where the spread is spread evenly apart from a window where a handful of bars carry most of the move. This indicator answers that by actually resampling: on every closed bar, the trailing window of closes is resampled with replacement a bounded number of times, each resample's mean is recorded, and the two band lines are read off as empirical percentiles of that distribution of resampled means - a real bootstrap confidence interval on "where is the true average of this window", not a shortcut approximation of one. The result is a band that tightens on quiet, evenly-distributed windows and widens on lumpy ones even when the two windows' plain standard deviation is similar, because resampling is sensitive to how concentrated the dispersion is across the sample, not just its magnitude. What gets resampled is the trailing closes themselves, not the residuals from an already-fitted trend line - that keeps the band a genuine confidence interval on the moving average's own value, which is the natural reading of "moving average with a confidence band" (a residual- dispersion band around a separately-fitted trend would be a different indicator). Notes and limitations The indicator recomputes every plotted bar's bootstrap from scratch on each new closed bar (bounded by InpMaxPlotBars and InpBootstrapIterations), so it is intentionally heavier than a plain moving average - both caps exist to keep that bounded and fast rather than unbounded. MQL4's MathRand() is a simple linear generator, not cryptographically random; it is entirely adequate for bootstrap resampling but the exact band edges will vary slightly between runs because the sampling itself is random by design - this is expected, not a repaint bug. The band reflects uncertainty about the window's average, not a prediction of future price range.

Indicator · MT4 · v1.0 · Free

About Bootstrap Confidence Moving Average

Bootstrap Confidence Moving Average is an indicator for MetaTrader 4. It has 4 settings, such as Ma period, Bootstrap iterations and Confidence level. MQL source code included.

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

Settings

SettingDefaultWhat it does
Ma period20Trailing bars resampled per window (5-150)
Bootstrap iterations200Resamples per window, hard-capped at 500
Confidence level0.90Confidence level for the band (0.50-0.99)
Max plot bars300History bars kept recomputed (performance cap)

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: Moving Average · Channels & Envelopes · Trailing Stop & Break-even · MT4 Indicator · MQL4 Source Code

MetaTrader 4 & 5 indicators · PolyMaria