Articles with MQL5 programming examples

icon

Access a huge collection of articles with code examples showing how to create indicators and trading robots for the MetaTrader platform in the MQL5 language. Source codes are attached to the articles, so you can open them in MetaEditor and run them to see how the applications work.

These articles will be useful both for those who have just started exploring automated trading and for professional traders with programming experience. They feature not only examples, but also contain new ideas.

Add a new article
latest | best
preview
From Basic to Intermediate: Queues, Lists, and Trees (IV)

From Basic to Intermediate: Queues, Lists, and Trees (IV)

In this article, we will conclude the section on the implementation and explanation of the linked list. However, the implementation presented here omits one detail that can be implemented in a linked list. We will discuss this later, in another article.
preview
From Basic to Intermediate: Queues, Lists, and Trees (V)

From Basic to Intermediate: Queues, Lists, and Trees (V)

In this article, we implemented the first components of a tree structure. Since I realize that this structure can be very complex at the beginning of the learning process, we will introduce it gradually, step by step. This way, everyone will be able to understand how a tree works and when it is best to use one.
preview
From Basic to Intermediate: Queues, Lists, and Trees (III)

From Basic to Intermediate: Queues, Lists, and Trees (III)

In this article, we will take the next step in understanding what a linked list is and how it works. Although the content of this article may seem rather complex and confusing to beginners, I will try to explain it in the simplest terms possible. This will help you understand why and when to use linked lists.
preview
From Basic to Intermediate: Queues, Lists, and Trees (II)

From Basic to Intermediate: Queues, Lists, and Trees (II)

This is an article that you, dear reader, should study carefully. That is due to the nature of the material presented here. Although we have tried to present the material as simply and informatively as possible, the information provided here can certainly seem quite complex to those who are just beginning to learn programming. Nevertheless, this is no reason to lose heart or ignore what is explained here, as this article will establish a link between two completely different, though closely related, topics.
preview
From Basic to Intermediate: Classes (I)

From Basic to Intermediate: Classes (I)

In this article, we explain what a class is and why this concept came about. Although the topic is interesting, we will focus here on the principles underlying MQL5 programming. This article is just an introduction.
preview
The ZeroMQ Message Transfer Protocol in MQL5: Implementing the REQ/REP pattern

The ZeroMQ Message Transfer Protocol in MQL5: Implementing the REQ/REP pattern

This article presents a native MQL5 implementation of the ZeroMQ Message Transfer Protocol (ZMTP) built on raw MQL5 sockets. It explains the REQ/REP pattern via the CZmqReqSocket class, including framing, handshake, and strict send/receive alternation. A practical pipeline shows an MQL5 script streaming returns to a Python/R server running MS‑GARCH and receiving regime probabilities, enabling integration without DLLs.
preview
Measuring What Matters (Part 4): Reading the Spectrum — What Eigenvalues Tell You About Risk

Measuring What Matters (Part 4): Reading the Spectrum — What Eigenvalues Tell You About Risk

We turn eigenvalues from a covariance matrix into a normalized spectral‑entropy score that measures how evenly variance is spread across factors. SpectralEntropyCalculator.mq5 compares two portfolios in one run, using native vector summation, ArraySort()-based ordering, element‑wise division, and the Shannon entropy formula. The report makes dominant factors visible and enables quick, repeatable checks of diversification quality.
preview
From Basic to Intermediate: Classes (III)

From Basic to Intermediate: Classes (III)

In this article, we will explore the best ways to manage code when working with object-oriented programming. Although we are just beginning to learn about object-oriented programming, what we will cover here will help you understand its various aspects. This will also help dispel any doubts that may arise later.
preview
From Basic to Intermediate: Operator Overloading (II)

From Basic to Intermediate: Operator Overloading (II)

At first, this article may seem rather confusing because of the material I'm going to cover in it. Nevertheless, I've tried to explain everything as simply and clearly as possible. I hope you'll understand what I'm about to show you here, and that it will come in handy someday.
preview
From Basic to Intermediate: Queues, Lists, and Trees (VII)

From Basic to Intermediate: Queues, Lists, and Trees (VII)

In this article, we will clearly and simply demonstrate and explain how to remove a node from a tree. This process usually confuses beginners rather than helping them understand how it's done and why it needs to be done that way.
preview
From Basic to Intermediate: Operator Overloading (IV)

From Basic to Intermediate: Operator Overloading (IV)

In this article, we will take a first step toward showing how to implement operator overloading for the index operator and the assignment operator, while striving to offer a practical and interesting approach for everyone. What we will see here is only part of what I still intend to show, and it is directly related to the overloading of these operators.
preview
From Basic to Intermediate: Queues, Lists, and Trees (VIII)

From Basic to Intermediate: Queues, Lists, and Trees (VIII)

In this article, we will examine how to implement a tree balancing algorithm. Here, I will present my own version of an implementation of this algorithm. There are many other algorithms that serve the same purpose. Nevertheless, each of them has its own advantages and disadvantages. You, my dear reader, will need to explore them and find the one that best suits your needs.
preview
From Basic to Intermediate: Operator Overloading (III)

From Basic to Intermediate: Operator Overloading (III)

In this article, we will examine how to implement overloading for both logical operators and comparison operators. This requires a certain amount of caution and a fair amount of attention. Even a minor oversight when implementing the overloading of these operators can render the entire code completely unusable. If any problems arise in the overloading, the entire database created from the results generated by the code will have to be either discarded completely or, at the very least, reviewed in full.
preview
From Basic to Intermediate: Operator Overloading (V)

From Basic to Intermediate: Operator Overloading (V)

In this article, we will look at how to modify the code to implement a solution entirely unlike what many consider possible in MQL5. Important note: To fully understand this material, you must have a solid grasp of the concepts covered in the previous articles.
preview
Building a Dynamic and Customizable Table in MQL5

Building a Dynamic and Customizable Table in MQL5

This article presents a reusable CTable class for building chart-based tables in MQL5. It covers table architecture, creation and destruction of objects, coordinates and sizing, cell properties, horizontal/vertical headers, dynamic row/column edits, object naming, index conversion, and efficient refreshing. You will be able to assemble consistent, aligned on-chart dashboards for market data, indicators, and signals with minimal boilerplate.
preview
Testing for Residual Autocorrelation with the Ljung-Box Portmanteau Test in MQL5

Testing for Residual Autocorrelation with the Ljung-Box Portmanteau Test in MQL5

A complete MQL5 implementation of the Ljung-Box test helps verify independence in trading data and fitted-model residuals. It computes sample autocorrelations, the Q statistic over selected horizons, degrees of freedom with user-controlled adjustments, and right-tail p-values via the regularized incomplete gamma function. Run it on returns, deal outcomes, or external residuals and review decisions directly in the Experts tab.