Skip to content
All library documents

Tick-Level CPCV Backtesting for Calibrated Machine Learning Strategies

Article MQL5 articles

Summary

The article describes a workflow for taking a calibrated machine learning model from a Python research pipeline into MetaTrader 5 for execution-aware backtesting. Python exports the ONNX model, calibrator parameters, feature specification, and combinatorial purged cross-validation path masks in formats MQL5 can read. An expert advisor reconstructs raw features, runs ONNX inference and calibration, sizes positions, and trades on the tester's tick stream. Python then gathers the path equity files and calculates a Sharpe distribution and probability of backtest overfitting audit.

The workflow separates fold construction and artifact translation in Python from market simulation in the Strategy Tester, which supplies spread, slippage, commission, and swap effects. It stresses preserving feature order and passing raw values when scaling is already embedded in the ONNX graph. The article gives a worked configuration and suggested decision statistics, but the supplied text does not show empirical results validating a particular model. CPCV and tick-level simulation improve the evaluation design; they cannot guarantee that historical performance will persist in live trading.

Key ideas

  • Python can precompute combinatorial purged cross-validation paths and export a timestamp mask for each path.
  • MetaTrader 5 can simulate each path with tick-level fills and trading costs.
  • When the scaler is embedded in the ONNX graph, MQL5 should provide raw feature values.
  • Feature order and matching feature calculations are essential because mismatches can silently corrupt predictions.
  • Evaluate the distribution of path Sharpe ratios and PBO rather than relying only on bar-level results.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.