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:

Function

Action

OnnxCreate

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

OnnxCreateFromBuffer

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

OnnxRelease

Close an ONNX session

OnnxRun

Run an ONNX model

OnnxGetInputCount

Get the number of inputs in an ONNX model

OnnxGetOutputCount

Get the number of outputs in an ONNX model

OnnxGetInputName

Get the name of a model's input by index

OnnxGetOutputName

Get the name of a model's output by index

OnnxGetInputTypeInfo

Get the description of the input type from the model

OnnxGetOutputTypeInfo

Get the description of the output type from the model

OnnxSetInputShape

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

OnnxSetOutputShape

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