MQL5 Programming Articles

icon

Study the MQL5 language for programming trading strategies in numerous published articles mostly written by you - the community members. The articles are grouped into categories to help you quicker find answers to any questions related to programming: Integration, Tester, Trading Strategies, etc.

Follow our new publications and discuss them on the Forum!

Add a new article
latest | best
preview
Drawdown Duration Analysis Indicator in MQL5

Drawdown Duration Analysis Indicator in MQL5

We build a drawdown analytics dashboard that derives the equity curve from deals and finds every episode's depth and recovery duration. Results appear on a CCanvas timeline spaced by point index with alternating bold annotations, and in a terminal table sorted by duration, allowing you to prioritize risk by time spent underwater rather than depth alone.
preview
From Delta-Space Quotes to the FX Volatility Smile: Garman-Kohlhagen and the Convention Problem

From Delta-Space Quotes to the FX Volatility Smile: Garman-Kohlhagen and the Convention Problem

FX options are quoted in delta space, not by strike. This article implements an FX-native smile tool for MetaTrader 5: it converts ATM, risk reversal and butterfly quotes into strike-space pillars, prices with the Garman–Kohlhagen model, handles spot/forward and premium-adjusted delta conventions per pair, and draws the smile with a reconstructed strike ladder and Greeks.
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
Did Your Scale Outs Actually Help? A Scale Out Value Analyzer in MQL5

Did Your Scale Outs Actually Help? A Scale Out Value Analyzer in MQL5

The article presents an MQL5 tool that tests whether scaling out improved results rather than only appearing disciplined. It reconstructs positions from closing-deal history and reprices the full volume at the first, last, and best exit rates actually achieved, producing a Value-Add Ratio, a Scale-Out Win Rate, and an Efficiency measure. A single-trade dependence check and a configurable A+ to F grade turn these into clear, decision-ready feedback.
preview
Uncertainty as a Model (Part 1): Random Variables — The Language of Uncertainty

Uncertainty as a Model (Part 1): Random Variables — The Language of Uncertainty

The article provides a systematic overview of the theory of random variables, which serves as the basis for analyzing and modeling uncertainty in financial markets. The article covers the definitions and properties of univariate random variables, cumulative distribution functions (CDFs) and probability density functions (PDFs), as well as the differences between discrete, continuous, and mixed models. The theoretical material is based on intuitive analogies with mass and density. The appendix to this article contains practical examples of using the standard MQL5 library to calculate probabilities, quantiles, and moments of distributions. It also demonstrates the graphical capabilities of the MetaTrader 5 platform for visual data analysis by plotting PDF and CDF curves and QQ plots.
preview
Did Your Scale Outs Actually Help? A Scale Out Value Analyzer in MQL5

Did Your Scale Outs Actually Help? A Scale Out Value Analyzer in MQL5

The article presents an MQL5 tool that tests whether scaling out improved results rather than only appearing disciplined. It reconstructs positions from closing-deal history and reprices the full volume at the first, last, and best exit rates actually achieved, producing a Value-Add Ratio, a Scale-Out Win Rate, and an Efficiency measure. A single-trade dependence check and a configurable A+ to F grade turn these into clear, decision-ready feedback.
preview
From Delta-Space Quotes to the FX Volatility Smile: Garman-Kohlhagen and the Convention Problem

From Delta-Space Quotes to the FX Volatility Smile: Garman-Kohlhagen and the Convention Problem

FX options are quoted in delta space, not by strike. This article implements an FX-native smile tool for MetaTrader 5: it converts ATM, risk reversal and butterfly quotes into strike-space pillars, prices with the Garman–Kohlhagen model, handles spot/forward and premium-adjusted delta conventions per pair, and draws the smile with a reconstructed strike ladder and Greeks.
preview
Neural Networks in Trading: The Adaptive Graph Diffusion Model (Conclusion)

Neural Networks in Trading: The Adaptive Graph Diffusion Model (Conclusion)

In this article, we conclude our work on building the SAGDFN framework using MQL5, summarizing the development process and presenting the results of its practical testing. Let's combine the modules we've already implemented into a single system, highlight the strengths of this approach, point out its weaknesses, and discuss possible ways to improve it.
preview
Drawdown Duration Analysis Indicator in MQL5

Drawdown Duration Analysis Indicator in MQL5

We build a drawdown analytics dashboard that derives the equity curve from deals and finds every episode's depth and recovery duration. Results appear on a CCanvas timeline spaced by point index with alternating bold annotations, and in a terminal table sorted by duration, allowing you to prioritize risk by time spent underwater rather than depth alone.
preview
Building AI-Powered Trading Systems in MQL5 (Part 11): Optimizing the UI with Frame Throttling and Partial Rendering

Building AI-Powered Trading Systems in MQL5 (Part 11): Optimizing the UI with Frame Throttling and Partial Rendering

We optimize an MQL5 canvas interface to stay responsive under rapid input without changing its appearance. The article adds a direct-buffer canvas for block region copies, caches text widths and glyph coverage, caps repaints at 60 fps (16 ms), and limits drawing to panes and regions that actually changed. As a result, hover, scroll, and popups render smoothly without full-panel redraws.
preview
Random Matrix Theory: Denoising the Correlation Matrix for Multi-Symbol EAs

Random Matrix Theory: Denoising the Correlation Matrix for Multi-Symbol EAs

Sample correlation matrices can look precise yet be mostly noise. This article implements a dependency-free RMT cleaner in MQL5: Jacobi eigendecomposition, Marchenko–Pastur eigenvalue screening, and average-noise reconstruction that preserves the matrix trace and unit diagonal. It explains integration into a basket EA so the denoised matrix improves stability of hedge ratios and weights between rebalances, while keeping the code portable and auditable.
preview
Practical Modules from Other Languages in MQL5 (Part 07): The OS Module from Python

Practical Modules from Other Languages in MQL5 (Part 07): The OS Module from Python

This article introduces a lightweight OS-like helper for MQL5 that streamlines file and path operations using a Python-inspired interface. We implement getcwd, listdir, scandir with DirEntry, remove, rmdir, rename, mkdir, stat, and an os.path subset (exists, isfile, isdir, join, split, pardir). You will learn how to work consistently within the terminal Files/common sandbox and simplify everyday filesystem tasks.
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.