- ONNX Support
- Format Conversion
- Automatic data type conversion
- Creating a Model
- Running a model
- Validation in the Strategy Tester
- OnnxCreate
- OnnxCreateFromBuffer
- OnnxRelease
- OnnxRun
- OnnxGetInputCount
- OnnxGetOutputCount
- OnnxGetInputName
- OnnxGetOutputName
- OnnxGetInputTypeInfo
- OnnxGetOutputTypeInfo
- OnnxSetInputShape
- OnnxSetOutputShape
- Data structures
Running a model
To run an ONNX model in MQL5, complete 3 steps:
- Load the model from an *.onnx file using the OnnxCreate function or from an array using OnnxCreateFromBuffer.
- Specify input and output data shapes using OnnxSetInputShape and OnnxSetOutputShape functions.
- Run the model using the OnnxRun function, passing to it the relevant input and output parameters.
- When needed, you can terminate the model operation using the OnnxRelease function.
When creating an ONNX model, you should consider the existing limits and restrictions, which are described at https://github.com/microsoft/onnxruntime/blob/rel-1.14.0/docs/OperatorKernels.md
Some of the examples of such restrictions are shown below:
Operation |
Supported data types |
---|---|
ReduceSum |
tensor(double), tensor(float), tensor(int32), tensor(int64) |
Mul |
tensor(bfloat16), tensor(double), tensor(float), tensor(float16), tensor(int32), tensor(int64), tensor(uint32), tensor(uint64) |
Below is an MQL5 code example from the public project ONNX.Price.Prediction.
const long ExtOutputShape[] = {1,1}; // model's output shape
|
Script run example:
ONNX: Creating and using per session threadpools since use_per_session_threads_ is true
|
The MetaTrader 5 terminal has selected the optimal executor for calculations — ONNX Runtime Execution Provider. In this example, the model was executed on the CPU.
Let's modify the script to calculate the percentage of successful Close price predictions made based on the values of the preceding 10 bars.
#resource "Python/model.onnx" as uchar ExtModel[]// model as a resource
|
Run the script: the prediction accuracy is about 51%
ONNX: Creating and using per session threadpools since use_per_session_threads_ is true
|