Loading…

Statistical Bootstrap Resampler

A single number - the average return of 40 trades, the mean spread over a week of ticks - hides how much it would move if the sample had come out slightly differently. The bootstrap answers that directly: draw a new sample of the same size WITH replacement from the data you actually have, so some values repeat and others are skipped, recompute the statistic, and repeat that thousands of times. The spread of results across all those resamples is the confidence interval. The interval here is built with the percentile method rather than a normal approximation. A textbook standard-error formula assumes the statistic is normally distributed, which is a poor assumption for trade P&L - wins and losses are usually skewed, sometimes heavily. Reading the interval straight off the empirical percentiles of the resampled distribution makes no such assumption and simply reflects whatever shape the data actually has. This is the sibling of MonteCarlo.mqh, not a duplicate of it. MonteCarlo reshuffles a FIXED set of trades to isolate how much of an equity curve's shape is the order they happened to close in. Bootstrap instead draws new samples - with repeats - from the same pool, to ask how much the sample itself might have differed if history had dealt slightly different data. The two questions are related but distinct, and folding them into one function with a mode flag would have hidden that distinction rather than clarified it. Three statistics are supported out of the box - mean, median and standard deviation - selected with an enum rather than a string, so a typo is a compile error rather than a silently ignored default. Notes and limitations - The bootstrap assumes the sample values are independent draws from the population of interest. Trade returns with strong serial correlation (for example a martingale sequence) violate that assumption and need a block bootstrap, which this header does not implement. - Small samples produce wide, unreliable intervals no matter how many resamples are run - the resampling cannot manufacture information the original sample did not contain. - BootstrapStdDev divides by n, not n-1, because each resample is treated as its own complete population rather than a sample of a larger one. - Every function is pure aside from the shared MathRand() stream; nothing here reads account, symbol or market state on either platform.

Script · MT5 · v1.0 · Free

About Statistical Bootstrap Resampler

Statistical Bootstrap Resampler is a script for MetaTrader 5. It has 6 settings, such as Sample size, Sample mean and Sample spread. MQL source code included.

Files in the download: Bootstrap.mq5.mqh, Bootstrap.txt, BootstrapDemo.ex5, BootstrapDemo.mq5.

Settings

SettingDefaultWhat it does
Sample size60Number of synthetic sample values
Sample mean25.0Mean used to generate the synthetic sample
Sample spread80.0Spread used to generate the synthetic sample
Resamples3000Number of bootstrap resamples
Confidence level0.95Confidence level, e.g. 0.95 for 95%
Seed7Random seed, 0 = non-reproducible

How to install

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

Download the PDF guide

Tags: MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria