New MetaTrader 5 build 3620: Web Terminal improvements, ONNX support and fast matrix multiplications in MQL5
Hello everyone! Thank you for ONNX!
I tried to open my ONNX model in MQL5 code. I used the example from the documentation: https://www.mql5.com/en/docs/onnx/onnxrun.
I got an error in the OnnxSetInputShape method. The error code was 4024.
I could not find the error description here: https://www.mql5.com/en/docs/constants/errorswarnings/errorcodes
I made sure, that my input/output shapes are completely fixed (without -1 dimensions). Input shape: (1, 90, 4), output shape: (1, 1).
What does the error code mean?
Hello everyone! Thank you for ONNX!
I tried to open my ONNX model in MQL5 code. I used the example from the documentation: https://www.mql5.com/en/docs/onnx/onnxrun.
I got an error in the OnnxSetInputShape method. The error code was 4024.
I could not find the error description here: https://www.mql5.com/en/docs/constants/errorswarnings/errorcodes
I made sure, that my input/output shapes are completely fixed (without -1 dimensions). Input shape: (1, 90, 4), output shape: (1, 1).
What does the error code mean?
Hi, i am a newbie want to load my onnx model to mql5 and use it to predict. i never use onnx before and get confused about its shape expression.
in your shapes, your input shape is (1,90,4), could you kindly explain what does these 3 digits meaning? i guess 90 is features count, and what else? thank you!
Hello everyone! Thank you for ONNX!
I tried to open my ONNX model in MQL5 code. I used the example from the documentation: https://www.mql5.com/en/docs/onnx/onnxrun.
I got an error in the OnnxSetInputShape method. The error code was 4024.
I could not find the error description here: https://www.mql5.com/en/docs/constants/errorswarnings/errorcodes
I made sure, that my input/output shapes are completely fixed (without -1 dimensions). Input shape: (1, 90, 4), output shape: (1, 1).
What does the error code mean?
Join ONNX.Price.Prediction projects and test it, please:
Could you please just tell what the error code 4024 mean? The developers must know, ask them. They wrote the code, but didn't document it here: https://www.mql5.com/en/docs/constants/errorswarnings/errorcodes
Hi, i am a newbie want to load my onnx model to mql5 and use it to predict. i never use onnx before and get confused about its shape expression.
in your shapes, your input shape is (1,90,4), could you kindly explain what does these 3 digits meaning? i guess 90 is features count, and what else? thank you!
The first dimension is called "batch size". It is the number of objects for which the model makes predictions. In this example I provide just 1 object.
The second dimension is called "sequence length". How many bars are used to make a prediction. In this case we take 90 bars.
The third dimension equals 4 because each bar consists of 4 numbers: Open, High, Low and Close prices.
So, it can be read like this: (1 object, 90 bars, 4 prices).
Hello, MetaQuotes moderators! Could you please contact your developers and ask them what the error code 4024 mean? Just ask them and post the answer here, please.
Hello, MetaQuotes moderators! Could you please contact your developers and ask them what the error code 4024 mean? Just ask them and post the answer here, please.
The first dimension is called "batch size". It is the number of objects for which the model makes predictions. In this example I provide just 1 object.
The second dimension is called "sequence length". How many bars are used to make a prediction. In this case we take 90 bars.
The third dimension equals 4 because each bar consists of 4 numbers: Open, High, Low and Close prices.
So, it can be read like this: (1 object, 90 bars, 4 prices).
thank you and it's totally different(2&3) from what I thought.
Could you help me to see this situation? in Mql5 , i use bar data(OHLC) and some indicators to generate 25 features in every 1-minute bar generate event by running an EA. the EA ran from 2023.01.04 01:00-11:00 (10 min) in history debug mode, so EA eventually output 10*60=600 samples(rows) and 25 features (columns) table, after training a model for this 600*25 table in Pyhton, i got a model and then convert to onnx format.
so for this model, how should set input shape and output shape in mql5? for 1 dimension i should take 1, because in realtime prediction ,every 1 minute i need model to predict ONE record.
actually what i coufused about onnx is why it has to specify the input and output data shapes for a model.
in example i posted above, for a sample, the model always receives 25 features and outputs a scalar value of prediction probability. So input shape is always (1,25,1 or 1,1,25 or 1,25) and output shape always (1,1). Since features count is unchanged, why is there a OnnxSetInputShape method? Can it work normally if I set it to 24? and in the same way , the output shape is always (1,1) ,this is not what I set, it is determined by the shape of the training set when the model is trained.
- www.mql5.com
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
The new version of the updated MetaTrader 5 platform will be released on Friday, March 10, 2023.
The update provides web terminal improvements. We have implemented a set of color templates for the web terminal interface and have enhanced the symbol specification window.
Also, the new version provides General Matrix Multiplication (GeMM) in MQL5. This algorithm speeds up calculations on most processors. The new algorithm is currently supported in the matrix::GeMM method.
We have also implemented support for operations with ONNX models in MQL5. This will greatly facilitate the use of neural networks in Expert Advisors.
The new version features the following changes:
MetaTrader 5 Client Terminal build 3620
ONNX is an open-source format for machine learning models. This format is supported by many platforms, including Chainer, Caffee2 and PyTorch. Create an ONNX model using specialized tools, integrate it into your MQL5 application and use it to make trading decisions.
Descriptions of all supported functions are available in the documentation. An example of a test ONNX model is available in public projects in MetaEditor. Find the ONNX.Price.Prediction project in "Toolbox \ Public projects" and select Join in the context menu. The project will download to your computer and will appear in the Navigator:
Compile the project and run it on EURUSD H1 to see the result.
In addition to the model and the MQL5 code which runs it, the project also includes the PricePredictionTraining.py Python script. It shows how you can create an ONNX model yourself. To run the script, install Python on your computer and the required modules from the prompt line:
python -m pip install --upgrade tensorflow
python -m pip install --upgrade pandas
python -m pip install --upgrade scikit-learn
python -m pip install --upgrade matplotlib
python -m pip install --upgrade tqdm
python -m pip install --upgrade metatrader5
python -m pip install --upgrade onnx==1.12
python -m pip install --upgrade tf2onnx
The new algorithm is currently supported in the matrix::GeMM method. If your processor supports AVX and FMA instructions (most processors released after 2013 support these instructions), the algorithm will be enabled automatically.
Matrices and vectors are passed to a DLL as a pointer to a buffer. For example, to pass a matrix of type float, the corresponding parameter of the function exported from the DLL must take a float-type buffer pointer. For example:
MQL5
C++
In addition to buffers, you should pass matrix and vector sizes for correct processing.
MQL5: Added new CopySeries function for copying synchronized timeseries from MqlRates into separate arrays.
The CopySeries function allows obtaining only the necessary timeseries into different specified arrays during one call, while all of timeseries data will be synchronized. This means that all values in the resulting arrays at a certain index N will belong to the same bar on the specified Symbol/Timeframe pair. Therefore, there is no need for the programmer to additionally synchronize the received timeseries by the bar opening time.
Unlike CopyRates, which returns the full set of timeseries as an MqlRates array, the CopySeries function allows obtaining specific required timeseries into separate arrays. This can be done by specifying a combination of flags to select the type of timeseries. The order of the arrays passed to the function must match the order of the fields in the MqlRates structure:
Thus, if you need to get the values of the 'time', 'close' and 'real_volume' timeseries for the last 100 bars of the current Symbol/Timeframe, you should use the following call:
The order of the arrays "time, close, volume" must match the order of the fields in the MqlRates structure. The order of values in the rates_mask is ignored. The mask could be as follows:
Example
MetaTrader 5 Web Terminal build 3620
The update will be available through the Live Update system.