Skip to content
All library documents

Building a Reliable ONNX Inference Pipeline in MQL5

Article MQL5 articles

Summary

The article describes an object-oriented MQL5 wrapper for running a model exported in ONNX format inside MetaTrader 5. It outlines the inference lifecycle: load the model, define input and output tensor shapes, pass a fixed-size feature vector to the runtime, and release the session handle when finished. The example uses five input features and one output value, with checks for initialization and input length.

It also covers min-max normalization and recommends matching the live preprocessing parameters to those used during training. The surrounding Expert Advisor is described as requesting predictions once per new bar to limit CPU load, then comparing the output with a configurable threshold before placing an order. The article provides implementation examples but no performance measurements or evidence that the resulting predictions are profitable. Its sample normalization bounds and model dimensions are illustrative and must be replaced to match a specific trained model; the author also recommends monitoring prediction drift and considering retraining.

Key ideas

  • Define tensor dimensions in MQL5 to match the model exported to ONNX.
  • Wrap session creation, inference, and release in a class to manage the model lifecycle.
  • Validate input feature count before running inference.
  • Apply the same normalization to live features as was used during training.
  • Limit inference frequency to reduce CPU load during live operation and backtesting.

Tags

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