Discussing the article: "Wasserstein Distance for Live Feature-Drift Detection in MQL5: Monitoring ONNX Model Inputs with Optimal Transport"

 

Check out the new article: Wasserstein Distance for Live Feature-Drift Detection in MQL5: Monitoring ONNX Model Inputs with Optimal Transport.

This article implements a lightweight feature-space drift guard in MQL5 using 1D Wasserstein‑1: sort-and-pair scoring on equal windows, IQR normalization per feature, and gating via both a weighted composite and a max-statistic. Configuration comes from a JSON manifest (window sizes, weights, warn/critical thresholds, actions). It runs next to an ONNX classifier and is validated with Strategy Tester results and explicit caveats.

Most drift monitors for live ONNX models track only feature means and standard deviations. That is enough for simple level or volatility shifts, but it misses changes in distribution shape that preserve the first two moments — for example, when a unimodal feature becomes bimodal while the mean remains nearly unchanged. A model trained on the old regime then keeps operating on input space it no longer recognizes.

This article builds a detector that looks at the whole distribution instead of a couple of summary statistics, using the one-dimensional Wasserstein-1 distance (Earth Mover's Distance) borrowed from optimal transport theory. Given a frozen reference sample and a live rolling sample, it measures the minimum "work" needed to reshape one into the other. With equal-size samples, W1 has a simple closed form based on sorted values, making it cheap enough to run per feature inside a live MetaTrader 5 Expert Advisor without turning OnTick into a bottleneck.

Where this fits in the series: unlike the earlier ADWIN/Page-Hinkley article, this method compares empirical distributions rather than tracking a change point in a single statistic. The two approaches are complementary.

The implementation includes an 8-feature builder, a per-feature Wasserstein detector with manifest-driven thresholds and actions, an ONNX directional model, ATR-based risk sizing, and an offline Python pipeline for training and synthetic validation.


Author: Olamide Daniel Adebayo