ONNX Models in Machine Learning

ONNX (Open Neural Network Exchange) is an open-source format for machine learning models. This project has several major advantages:

  • ONNX is supported by large companies such as Microsoft, Facebook, Amazon and other partners.
  • Its open format enables format conversions between different machine learning toolkits, while Microsoft's ONNXMLTools allows converting models to the ONNX format.
  • MQL5 provides automatic data type conversion for model inputs and outputs if the passed parameter type does not match the model.
  • ONNX models can be created using various machine learning tools. They are currently supported in Caffe2, Microsoft Cognitive Toolkit, MXNet, PyTorch and OpenCV. Interfaces for other popular frameworks and libraries are also available.
  • With the MQL5 language, you can implement an ONNX model in a trading strategy and use it along with all the advantages of the MetaTrader 5 platform for efficient operations in the financial markets.
  • Before tunning a model for live trading, you can test the model behavior on historical data in the Strategy Tester, without using third-party tools.

MQL5 provides the following functions for working with ONNX:




Create an ONNX session, loading a model from an *.onnx file


Create an ONNX session, loading a model from a data array


Close an ONNX session


Run an ONNX model


Get the number of inputs in an ONNX model


Get the number of outputs in an ONNX model


Get the name of a model's input by index


Get the name of a model's output by index


Get the description of the input type from the model


Get the description of the output type from the model


Set the shape of a model's input data by index


Set the shape of a model's output data by index