Matrices and vectors

The MQL5 language provides special object data types: matrices and vectors. They can be used to solve a large class of mathematical problems. These types provide methods for writing concise and understandable code close to the mathematical notation of linear or differential equations.

All programming languages support the concept of an array, which is a collection of multiple elements. Most algorithms, especially in algorithmic trading, are constructed on the bases of numeric type arrays (int, double) or structures. Array elements can be accessed by index, which enables the implementation of operations inside loops. As we know, arrays can have one, two, or more dimensions.

Relatively simple data storing and processing tasks can usually be implemented by using arrays. But when it comes to complex mathematical problems, the large number of nested loops makes working with arrays difficult in terms of both programming and reading code. Even the simplest linear algebra operations require a lot of code and a good understanding of mathematics. This task can be simplified by the functional paradigm of programming, embodied in the form of matrix and vector method functions. These actions perform a lot of routine actions "behind the scenes".

Modern technologies such as machine learning, neural networks, and 3D graphics make extensive use of linear algebra problem solving, which uses operations with vectors and matrices. The new data types have been added to MQL5 for quick and convenient work with such objects.

At the time of writing the book, the set of functions for working with matrices and vectors was actively developed, so many interesting new items may not be mentioned here. Follow the release notes and articles section on the mql5.com site.

In this chapter, we will consider a brief description. For further details about matrices and vectors, please see the corresponding help section Matrix and vector methods.

It is also assumed that the reader is familiar with the Linear Algebra theory. If necessary, you can always turn to reference literature and manuals on the web.