Skip to content
All library documents

Isolation Forest Monitoring for Trade Execution Anomalies

Article MQL5 articles

Summary

The article presents an unsupervised Isolation Forest monitor for execution quality, built natively in MQL5 and attached to trade transaction events. Each confirmed fill is represented by features for slippage, request-to-fill latency, spread at execution, volume deviation, and a currently unused rejection placeholder. Randomized tree partitions isolate unusual observations; their average path lengths are normalized into anomaly scores. A rolling history supplies training data, and the resulting score can trigger entry pauses, wider stops, or a trading halt.

The article explains why joint anomalies may escape separate per-feature thresholds and retains a hard slippage cap as a complementary safeguard. It describes feature-contract checks, model persistence, logging, synthetic validation, and Strategy Tester runs, but reports no measured P&L benefit because the tester did not reproduce the execution problems the breaker targets. The example threshold is calibrated from one log and is explicitly not universal; thresholds and retraining settings need calibration on a trader’s own broker data and hardware.

Key ideas

  • Isolation Forest flags observations that random partitions isolate in relatively few steps, without requiring labeled anomalies.
  • The monitor combines several execution features so it can detect unusual combinations that individual limits may miss.
  • A rolling execution history trains the model, and anomaly scores can drive configurable circuit-breaker responses.
  • The implementation checks that feature dimensions agree across code, logs, and any persisted model.
  • The article does not establish improved trading returns, and its example threshold requires calibration on local execution data.

Tags

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