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
Graph Theory: Heuristic Search Algorithm (A-Star) Applied in Trading

Graph Theory: Heuristic Search Algorithm (A-Star) Applied in Trading

The article applies the A* heuristic to market structure by modeling validated swing highs and lows as graph nodes and weighting edges with ATR‑normalized distance, spread, and noise penalties. The engine searches the most efficient route to infer trade direction and targets, then filters signals by directional ratio, total path cost, and opposing swings. It anchors TP to the final node and SL to prior structure, with on‑chart visualization and configurable inputs.
preview
From Basic to Intermediate: Struct (VII)

From Basic to Intermediate: Struct (VII)

In today's article, we will show how to approach solving problems related to structuring different elements and creating simpler and more attractive solutions. Although the content is oriented toward learning and, therefore, does not constitute production code, it is essential to thoroughly understand the concepts and knowledge that will be covered here. In this way, in the future we will be able to follow the codes we will present.
preview
From Basic to Intermediate: Indicator (III)

From Basic to Intermediate: Indicator (III)

In this article, we will explore how to declare various graphical representation indicators, such as DRAW_COLOR_LINE and DRAW_FILLING. Additionally, of course, we will learn how to plot graphs using multiple indicators in a simple, practical, and fast way. This can truly change your perspective on MetaTrader 5 and the market as a whole.
preview
From Basic to Intermediate: Struct (V)

From Basic to Intermediate: Struct (V)

In this article, we will explore how to overload structural code. I know it can be quite challenging to understand at first, especially if you're seeing it for the first time. It is very important that you grasp these concepts and understand them well before attempting to delve into more complex and elaborate topics.
preview
How to implement AutoARIMA forecasting in MQL5

How to implement AutoARIMA forecasting in MQL5

This article presents an MQL5 implementation of AutoARIMA that builds ARIMA models without manual tuning. It estimates d via a variance-based heuristic, fits ARMA(p,q) by gradient optimization with Adam, and selects p and q using AICc. The code returns a one-step-ahead price forecast by differencing, model estimation, and integration back to price level, ready to call on a Close series.
preview
From Basic to Intermediate: Struct (III)

From Basic to Intermediate: Struct (III)

In this article, we will explore what structured code is. Many people confuse structured code with organized code, but there is a difference between these two concepts. This is exactly what will be discussed in this article. Despite the apparent complexity you may feel when first encountering this type of code writing, I have tried to approach the topic as simply as possible. However, this article is just the first step toward something greater.
preview
Engineering Trading Discipline into Code (Part 5): Account-Level Risk Enforcement in MQL5

Engineering Trading Discipline into Code (Part 5): Account-Level Risk Enforcement in MQL5

We introduce an MQL5 discipline engine that enforces risk consistently at the account level. It continuously scans positions from any source, validates SL/TP, equity-based exposure, and target R:R, and automatically corrects deviations by setting levels or adjusting volume. The result is uniform risk structure across manual and EA trades, supported by on-chart feedback and mode-based control.
preview
MetaTrader 5 and the MQL5 Economic Calendar: How to Turn News into a Reproducible Trading System

MetaTrader 5 and the MQL5 Economic Calendar: How to Turn News into a Reproducible Trading System

The article presents a systematic approach to news trading in MetaTrader 5 using the built-in economic calendar: data structure, API functions, time synchronization rules, and event filtering. Methods of caching and incremental updating without overloading the server are described. The article also provides a working mechanism for exporting history to an .EX5 resource for deterministic testing using the same algorithm.