Discussing the article: "MetaTrader 5 Machine Learning Blueprint (Part 17): CPCV Backtesting — From Python Model to Tick-Level Evidence"

 

Check out the new article: MetaTrader 5 Machine Learning Blueprint (Part 17): CPCV Backtesting — From Python Model to Tick-Level Evidence.

We bridge Python-native artifacts to MQL5 for tick-accurate CPCV backtesting. The export script converts the ONNX model, calibrator, feature spec, and path masks to flat files, while the expert advisor rebuilds features, performs ONNX inference with calibration, and trades on real ticks. The Strategy Tester runs each combinatorial path, and Python aggregates per-path equities into a path Sharpe distribution to assess robustness after spread, slippage, and commission.

The Python pipeline described in Parts 8 through 12 produces a trained model, a fitted probability calibrator, a feature specification, and an events DataFrame. These artifacts answer one question about the model: does it have edge on historical bar-level returns? They leave a second question unanswered: will that edge survive execution costs? Spread, slippage, commission, and swap are not abstract numbers; they are frictions that erode the theoretical advantage the model captured. A Sharpe ratio distribution computed from bar-by-bar P&L is a useful diagnostic. One computed from tick-level fills is the evidence base on which a deployment decision should be made.

This article builds the bridge between those two worlds. The pipeline exports its artifacts in Python-native formats (ONNX, pickle, parquet). MetaTrader 5's Strategy Tester consumes flat files (CSV, JSON). An export script translates between them. On the MQL5 side, an expert advisor loads the translated artifacts in OnInit(). It constructs features from bar data, runs ONNX inference, applies the calibration map, sizes positions using the logic from Part 10 and Part 11, and executes orders on the tick stream. The Strategy Tester's optimization mode then runs each of the φ[N, k] combinatorial paths as a separate agent, producing tick-accurate equity curves that Python collects and analyzes.

The result is a path Sharpe distribution and PBO audit computed from real tick fills. A deployment decision is based on three numbers from that distribution: the median path Sharpe (is the edge real after costs?), the path Sharpe standard deviation (is the performance stable across temporal configurations?), and the PBO (is strategy selection better than chance?).

This article is Part 17 of the MetaTrader 5 Machine Learning Blueprint series. Part 12 produced the calibrated model whose ONNX export is the primary input here. The Unified Validation Pipeline article defined the CPCV fold structure and PBO computation that this article's Strategy Tester orchestration reproduces.

Author: Patrick Murimi Njoroge