Information about ONNX model inputs and outputs - MetaTrader 5 Scripts - MT4/MT5 Resources





The ONNX model running function needs to define the input and output sizes of the model. Dimensions are specified by the OnnxSetInputShape and OnnxSet output shape functions, respectively.
Not all models have fixed input and output data sizes. In these cases, the script will return -1.
OnnxTypeInfo type_info; long inputCount = Onnx getInputCount (sessionHandle); print ("model has", input_count, " input (s)"); for ( long i = 0 ; i < input count; i++) { string inputName = Onnx getInputName (sessionHandle, i); print (i, " The input name is", the input name); if ( OnnxGetInputTypeInfo (session handle, i, type information)) Print type information (i, " input ", type information); } long outputCount = Onnx getOutputCount (sessionHandle); print ("model has",output_count,"output"); for ( long i = 0 ; i < output count; i++) { StringOutputName = OnnxGetOutputName (sessionHandle, i); Print (i,"The output name is",output_name); if ( OnnxGetOutputTypeInfo (session handle, i, type information)) PrintTypeInfo(i,"output",type_info); }
Function for selecting models from the MQL5\Files folder using the file selection dialog

An example of how the script works is shown below:
Create model from mnist.onnx with debug logs ONNX: Create and use per-session thread pool since use_per_session_threads_ is true ONNX: Dynamic block according to put to 0 ONNX: Initializing session. ONNX: Add default CPU execution provider. ONNX: Removed initializer 'parameter 6' . It is no longer used by any node. ONNX: Removed initializer 'parameter 88' . It is no longer used by any node. ONNX: Total number of shared scalar initializers: 0 ONNX: Removed initializer 'parameter 193_reshape1_shape' . It is no longer used by any node. ONNX: Removed initializer 'parameter 193' . It is no longer used by any node. ONNX: Total number of fusion-reshape nodes: 0 ONNX: Total number of shared scalar initializers: 0 ONNX: Total number of fusion-reshape nodes: 0 ONNX: Delete initializer 'parameter 5' . It is no longer used by any node. ONNX: Removed initializer 'parameter 87' . It is no longer used by any node. ONNX: Use DeviceBasedPartition as default ONNX: Save initialized tensors. ONNX: Finished saving initialized tensor ONNX: Session initialized successfully. If the model number is 1, enter 0, and if the name is entered, enter 3. Type ONNX_TYPE_TENSOR Data typeONNX_DATA_TYPE_FLOAT shape[ 1 , 1 , 28 , 28 ] The shape of the input data can be simplified to [ 28 , 28 ] The model has 1 output 0 and the output name is Plus214_Output_0 Type ONNX_TYPE_TENSOR Data typeONNX_DATA_TYPE_FLOAT shape [1,10 ] The shape of the output data can be simplified to [ 10 ]
Update: Since the OnnxTypeInfo structure changed in build 3700, the source code of the script has been modified.
Attachment download
📎onnxmodelinfo.mq5 (5.97 KB)
Source: MQL5 #43452
Information about ONNX model inputs and outputs - MetaTrader 5 script usage and filtering recommendations
Information about ONNX model inputs and outputs - MetaTrader 5 Scripts is a resource related to trading scripts. Before downloading or referencing, it is recommended to confirm the platform version, transaction type, time period, whether DLL is required, whether source code is included, parameter description and historical update records.
Both automated trading tools and foreign exchange indicators should first undergo backtesting, simulated account observation, and small capital verification. Pay special attention to spreads, slippages, maximum drawdowns, position opening frequency, stop loss methods, trading periods and broker rules, and avoid direct real-time execution based only on titles or short-term profit descriptions.
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •