Metric Uncertainty Kit
"Sharpe 1.4 over 40 trades" and "Sharpe 1.4 over 4,000 trades" are not the same claim, but a bare point estimate makes them look identical. The percentile bootstrap answers the natural follow-up question - how much would this number plausibly move if the same underlying edge had produced a slightly different run of trades - directly from the data itself, with no assumption that returns are normally distributed (a poor fit for most small live trade samples, which is exactly where a parametric confidence interval is least trustworthy). The method: draw many resamples of the same size as the original trade array, each one built by sampling WITH replacement (so the same trade can appear zero, one, or several times in a single resample), compute the target statistic on every resample, sort the resulting distribution, and read off the percentile bounds for the requested confidence level. Sharpe, profit factor and win rate all share this one bootstrap driver internally, so the three public methods are thin wrappers rather than three separately-written resampling loops that could quietly drift apart. The demo runs the bootstrap on a 120-trade sample and again on a 15- trade sample built the same way, and shows the smaller sample's interval come out visibly wider - proof the kit actually reports MORE uncertainty when there is genuinely less data behind the headline number, rather than a fixed-width interval regardless of sample size. Notes and limitations - Sharpe here is the plain per-period ratio (mean divided by population standard deviation of the input array) - no annualisation factor is applied. Annualise the point estimate and both bounds afterward with the same scalar multiplier if a caller needs an annualised figure. - The bootstrap resamples INDEPENDENTLY draw each of the `count` positions with replacement - this assumes trade outcomes are reasonably independent of each other. If a strategy has strong serial correlation between consecutive trades (e.g. martingale-style sizing after a loss), the plain bootstrap used here understates the true uncertainty; a block bootstrap would be needed to capture that, and is out of scope for this library. - MathRand() is seeded once per terminal session from the local time and tick count, not from a cryptographic source - fine for statistical resampling, not suitable for anything security-sensitive. - Larger InpBootstrapIters values take proportionally longer to run; 2000 iterations over a few hundred trades completes quickly, but very large trade counts combined with very large iteration counts will visibly slow the script.
Script · MT5 · v1.0 · Free
About Metric Uncertainty Kit
Metric Uncertainty Kit is a script for MetaTrader 5. It has 4 settings, such as Trade count, Small trade count and Bootstrap iters. MQL source code included.
Files in the download: MetricUncertaintyKit.mq5.mqh, MetricUncertaintyKit.txt, MetricUncertaintyKitDemo.ex5, MetricUncertaintyKitDemo.mq5.
Settings
| Setting | Default | What it does |
|---|---|---|
| Trade count | 120 | Synthetic trades in the larger sample |
| Small trade count | 15 | Synthetic trades in the smaller sample (shows a wider CI) |
| Bootstrap iters | 2000 | Bootstrap resamples drawn |
| Confidence level | 0.95 | Confidence level, e.g. 0.95 = 95% |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: MT5 Script · MQL5 Source Code