I have been working with matrixes for few weeks now and I made some test but they do not seem efficient at all.
On my test, calculating some dot products took twice the time using matrixes comparing using complete loops. I found it weird as everyone on the web says that matrix computation are supposed to be at least 10 time faster.
Could be that the way MQL5 implements matrixes is not very good?
If someone can relate and know why, I am interested!
I have been working with matrixes for few weeks now and I made some test but they do not seem efficient at all.
On my test, calculating some dot products took twice the time using matrixes comparing using complete loops. I found it weird as everyone on the web says that matrix computation are supposed to be at least 10 time faster.
Could be that the way MQL5 implements matrixes is not very good?
If someone can relate and know why, I am interested!
I have been working with matrixes for few weeks now and I made some test but they do not seem efficient at all.
On my test, calculating some dot products took twice the time using matrixes comparing using complete loops. I found it weird as everyone on the web says that matrix computation are supposed to be at least 10 time faster.
Could be that the way MQL5 implements matrixes is not very good?
If someone can relate and know why, I am interested!
i think the gains start appearing en masse .
Also if you also used loops for the matrices , i.e: did this : matrix[][]= , then yeah there is no gain
i think the gains start appearing en masse .
Also if you also used loops for the matrices , i.e: did this : matrix[][]= , then yeah there is no gain
No I didn't use this kind of loop, only the MatMul functions.
But on investigating a bit more, if you use a vector instead of a matrix that has only one column for example (what I was doing) the time is reduced quiet a bit and became about 30% faster than a complete loop for dot products on my test.
So faster to use Matrix.MatMul(Vector) than Matrix.MatMul(Matrix) even if the matrix seems to have the same size as the vector.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I have been noticing one or two months ago that "matrix" is suggested in blue letters in MetaEditor like a data type but I had not seen anybody mention it on the forum and so it didn't strike me as something inherently useful.
In the meanwhile there have been two version updates where MetaQuotes have explicitely introduced the new feature. Since I am interested in bringing MQL and Tensorflow (Python) together these Python oriented simplified matrices might be of interest and I would like to say thanks to MetaQuotes for this great opportunity.
I was hoping that this could be an ongoing thread to explore and clarify these possibilities.
The reason why it might become important is that more and more developers hop on the datascience/machinlearning train and there are ready solutions in R or Python, so after trying out strategies via matrices or machine learning operations in other languages you might either use the API to have the python program directly control the actions of MetaTrader5 OR you can rebuild Python functions inside MQL which is closer to machine language and therefore faster.
BTW his has been possible before with the AlgLib from Standard Library but the new functions are a lot less clunky.
So our goal is to perform complex calculations and yield data from the matrices. But to achieve this we must first initialise a matrix and put raw data in it.
The documentation says
void matrix.Init()
Initialize a matrix
But if we write a little test indicator and say...
... It only throws a lot of errors because we haven't declared the matrix.
So let's declare it:
You will see after successful declaration there will be methods of the matrices class popping up:
Some functions like FromBuffer are not in there yet, but it is announced that they will add this functionality step by step. For now, we are going to fill our matrix by loop:
The matrix looks like this now inside the storage:
(0 , 1 , 2 , 3,
4 , 5 , 6 , 7,
8 , 9 ,10,11,
12,13,14,15)
So now that we filled our 4X4 matrix with values from 0 to 15, we can extract single rows or columns as vectors:
So after a few initial experiments this stuff is handy to work with and we will see later how to use special functions like eigenvectors and least square procedures. Feel free to contribute.