BacktestOverfitting.mqh computes the Probability of Backtest Overfitting (PBO) of an optimization: how often the pass with the best result in one part of the history ends in the lower half of all passes in the other part. A high PBO means that the best pass of the optimization was mostly picked for its luck. The method is the combinatorially symmetric cross-validation of Bailey, Borwein, Lopez de Prado and Zhu (2017).
The library also collects what the method needs from an ordinary MT5 optimization: each pass sends its daily results as a frame from OnTester(), and OnTesterDeinit() puts them in one matrix when the last pass is done.
#include <BacktestOverfitting\BacktestOverfitting.mqh>
double OnTester()
{
double days[];
CPboFrames::DailyResults(days); // closed results by day, Monday to Friday
CPboFrames::Send(days, TesterStatistics(STAT_PROFIT));
return(TesterStatistics(STAT_PROFIT));
}
void OnTesterInit() {}
void OnTesterDeinit()
{
matrix results; // one row per day, one column per pass
ulong passes[];
double values[];
CPboFrames::Collect(results, passes, values);
SPboResult r;
if(CPbo::Run(results, 16, r)) // 16 blocks: 12 870 splits
PrintFormat("PBO %.1f%%", 100.0 * r.pbo);
} PboExample.mq5 is a moving average cross. Optimize the two periods with "Slow complete algorithm"; at the end the Experts log shows the PBO, the share of losing splits, the line of out-of-sample against in-sample Sharpe, the best pass on the whole period, and the days and splits are saved to Common\Files\PBO for your own charts (picture 1).

What the method works on: the daily results of the 62 passes, sent by each pass as a frame from OnTester() and added up here. The best pass on the whole period (bold) is one of only 16 that end with a profit.

The net profit of each pass by its inputs. The profitable passes sit together, mostly with a slow average of 90 or more and a fast one of 20 or more, instead of being isolated cells. This is one reason why the PBO is low (4.8%) here: the best pass is not a lucky outlier among its neighbours.

On EURUSD H1 from January 2024 to September 2026 (62 valid passes) the PBO was 4.8%: the slow averages were chosen in most splits and stayed in the upper half out of sample. The pass chosen still lost out of sample in 26% of the splits, and the slope of -0.69 shows that a higher in-sample Sharpe came with a lower one out of sample. A low PBO says the ranking of the passes holds, not that the best pass makes money.
Against an independent Python version (itertools, numpy, scipy) on a matrix of 1 003 days and 120 columns, with duplicate columns and one column without trades: with S = 16, 10, 8 (PBO_MEAN) and 4, the chosen column was the same in every split, the logits agreed within 5e-13, and the PBO, the share of losses and the line were the same. The days saved by PboExample after the optimization gave the same 12 870 logits in Python, and the daily results of every pass add up to its net profit.
DrawdownBootstrap: Monte Carlo of the maximal drawdown
Block bootstrap of daily results: how deep the drawdown of an account or strategy can get over the next months, with percentiles and a seeded generator for repeatable runs.
PortfolioWeights: risk parity, HRP, minimum variance and maximum diversification
Portfolio weights from the returns of symbols or Expert Advisors: inverse volatility, risk parity, hierarchical risk parity, minimum variance, maximum diversification, Ledoit-Wolf covariance.
Risk Lot Panel
On-chart panel that turns a risk setting into a lot size and shows what the broker's volume step and minimum lot do to that risk. Display only - it never places, modifies or closes an order.
ICT Model Tracker - Sweep, MSS and FVG Setups with Honest Statistics
Detects the ICT model on closed bars (killzone liquidity sweep, MSS with displacement or inverted FVG, retrace entry with SL and TP) and follows every setup to its result with worst-case statistics. It never trades and never repaints; EA-ready buffers.