MQL4 and 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
Neural Networks in Practice: An Example of Implementing an XOR Gate

Neural Networks in Practice: An Example of Implementing an XOR Gate

In this article, I will try to show you, dear reader, that things are not always what they seem. We often tend to think that everything is arranged in a certain way, even though we may end up believing something that isn't necessarily true. Neural networks are undoubtedly one of the most interesting topics, whether viewed from the perspectives of mathematics, electronics, or software. Contrary to what many people believe or claim, neural networks are neither a problem nor a definitive solution. This is just one area of research where we should continue to delve deeper and explore what goes on behind the scenes.
preview
From Basic to Intermediate: Operator Overloading (VI)

From Basic to Intermediate: Operator Overloading (VI)

Here, we implement deletion using operator overloading. Without a doubt, many people will have to spend quite a bit of time studying this article to fully grasp everything that will be covered here. I want to remind you that what we're about to see is just a small and insignificant part of what we call programming.
preview
Color Harmony Algorithm (CHA)

Color Harmony Algorithm (CHA)

We take a closer look at the Color Harmony Algorithm (CHA) — a meta-heuristic optimization method based on Munsell's theory of color harmony. We explore the structure of the hue circle, harmony templates, the alternation between the concentration and dispersion phases, and the role of solution memory. From a theoretical framework to a working implementation in MQL5 and unbiased testing on a standard benchmark.
preview
Creating Custom Indicators in MQL5 (Part 12): Mapping Liquidity with a Volume Profile Heatmap

Creating Custom Indicators in MQL5 (Part 12): Mapping Liquidity with a Volume Profile Heatmap

We build a volume profile heatmap indicator in MQL5 that bins window volume into uniform price levels and paints each bar as a column of colored cells behind the candles. We cover binning, heat coloring, the side profile, the point-of-control and value-area lines, and the liquidity readouts, with every level published to buffers. The result is a map of dense bands and thin gaps, showing how much traded volume sits above and below the current price.
preview
Trading Strategy Beyond Raw Volume: Using Transformed Volume Change for Trading

Trading Strategy Beyond Raw Volume: Using Transformed Volume Change for Trading

The article develops a volume-change strategy that transforms tick or real volume with Ln(volume+1), differences it bar to bar, and applies arctan to produce a bounded, scale‑independent signal. A threshold drives entries, with selectable gates for positive, negative, or bi‑directional signals and candle‑based confirmation. An MQL5 Expert Advisor implements the logic and supports fixed TP/SL, N‑candle exits, or both, enabling straightforward testing and deployment.
preview
Neural Networks in Trading: Temporal Motion Aggregation (TMA)

Neural Networks in Trading: Temporal Motion Aggregation (TMA)

The TMA framework offers a new perspective on market dynamics, enabling models to capture not only the state of the market but also the passage of time itself. Its ability to identify patterns in a continuous stream of data makes the analysis more in-depth and accurate than with traditional approaches. Recurrent adaptation turns this method into a practical tool for working with real-world quotes.
preview
Neural Additive Models for Fully Interpretable Signal Attribution in MQL5

Neural Additive Models for Fully Interpretable Signal Attribution in MQL5

Build and deploy a Neural Additive Model natively in MQL5: one small network per feature, additive output, and no post-hoc explainability. The article provides a PyTorch trainer, two‑output ONNX export (signal and contributions), an include wrapper using OnnxCreateFromBuffer/OnnxRun, and an EA that prints real per‑feature contributions each bar. It covers identical feature math for training/export, threshold measurement, Strategy Tester results, and edge cases such as NaNs and out‑of‑distribution inputs.
preview
Crypto Exchange Integration with MQL5 (Part 1): Connecting to MEXC Futures

Crypto Exchange Integration with MQL5 (Part 1): Connecting to MEXC Futures

This article introduces the foundations of connecting MetaTrader 5 to a cryptocurrency exchange using MQL5 and the MEXC Futures API. It covers terminal configuration, JSON response processing, WebRequest() execution and validation, and conversion of API data into native MQL5 types. Practical examples demonstrate retrieving and processing exchange data. These components establish the basis for a reusable MEXC Futures client, developed progressively throughout the series. The series focuses exclusively on exchange integration; how readers use the retrieved data remains outside its scope.
preview
Trading Strategy Beyond Raw Volume: Using Transformed Volume Change for Trading

Trading Strategy Beyond Raw Volume: Using Transformed Volume Change for Trading

The article develops a volume-change strategy that transforms tick or real volume with Ln(volume+1), differences it bar to bar, and applies arctan to produce a bounded, scale‑independent signal. A threshold drives entries, with selectable gates for positive, negative, or bi‑directional signals and candle‑based confirmation. An MQL5 Expert Advisor implements the logic and supports fixed TP/SL, N‑candle exits, or both, enabling straightforward testing and deployment.
preview
Building a PDF Creation Library in MQL5 (Part 3): The Byte-Exact Writer

Building a PDF Creation Library in MQL5 (Part 3): The Byte-Exact Writer

The article presents CPdfBuffer and CPdfWriter, a minimal MQL5 pair that derives all offsets from the output buffer instead of hand-maintaining numbers. CPdfWriter records object starts, writes a fixed-width cross-reference table and trailer, and ensures structural consistency. The result passes Part 2's validator, and a ready-to-use script converts arbitrary text to a paginated PDF.
preview
From Basic to Intermediate: Technical Indicators (I)

From Basic to Intermediate: Technical Indicators (I)

In this article, we will examine the basic principles of using the technical indicators built into MetaTrader 5 and supported by this platform. Knowing and understanding these indicators can make implementing a solution much simpler, faster, and more efficient, since you won't have to worry about the necessary calculations. The platform handles them for us automatically.
preview
Neural Networks in Practice: Gradient Descent

Neural Networks in Practice: Gradient Descent

In this article, I will try to explain as simply and clearly as possible one of the most controversial issues that arises when discussing neural networks: how to find the best possible point, or the minimum of the loss function. I'll show you the difference between linear regression and gradient descent. Both methods are fairly simple and serve as examples of how the path that seems obvious isn't always the best one.
preview
Building a Trade Replay Tool in MQL5

Building a Trade Replay Tool in MQL5

This article presents a Trade Replay Tool for MetaTrader 5 implemented as an MQL5 indicator. It replays historical candles within an anchor-defined range and automatically reconstructs historical trades as paper positions with entry, SL, and TP. Users control start/end anchors and playback speed via UI buttons and hotkeys, enabling focused study of price evolution and trade lifecycle in a precise, event-driven environment.
preview
From Basic to Intermediate: Technical Indicators (II)

From Basic to Intermediate: Technical Indicators (II)

In this article, we'll show you how to create an MQL5 indicator that plots multiple moving averages on a single chart, reducing the amount of duplicate code. This uses iMA, indicator buffers, CopyBuffer, PlotIndexSetInteger/String, and a const array of structures that brings together periods, methods, and colors. The sizes of `indicatorbuffers` and `indicatorplots` are determined based on `Averange.Size()`. This approach simplifies maintenance and allows you to add or remove moving averages by modifying just one list.
preview
A Grid Expert Advisor Based on a Cellular Automaton with Online Learning in MQL5 (Part I): Continuous Adaptation of the Trading Model on Each Bar

A Grid Expert Advisor Based on a Cellular Automaton with Online Learning in MQL5 (Part I): Continuous Adaptation of the Trading Model on Each Bar

The article examines the architecture of an Expert Advisor based on a cellular automaton with 10,000 adaptive parameters and an independent binary predictor with a 10-bar prediction horizon. The article demonstrates a three-level online learning process, the evolution of strategies, and validation using a ring buffer and a confusion matrix. The input parameters are reduced to Magic Number, while trading settings are calculated from ATR and five genomes. The EURUSD H1 test yielded an approximate hit rate of 58%, compared to roughly 51% for the fixed MLP.
preview
Using the MQL5 Economic Calendar for News Filter (Part 5): The Tier the Calendar Does Not Have

Using the MQL5 Economic Calendar for News Filter (Part 5): The Tier the Calendar Does Not Have

This part extends the news filter with an ordered tier scale that adds a special tier above the broker's High, per‑event time windows, and one classifier shared by live calendar data and historical CSV. A rule table (with optional CSV overrides) promotes or demotes specific releases and can set custom windows. A diagnostic script prints your broker's calendar, event codes, and server time so your rules match what the terminal actually reports.
preview
Neural Networks in Trading: Temporal Motion Aggregation (Key Components)

Neural Networks in Trading: Temporal Motion Aggregation (Key Components)

In this article, theory meets practice. We implement the key modules of the TMA framework — MPE and MPA. Here, data takes on meaning, and cross-attention becomes a tool for precise analysis of market dynamics. Minimal unnecessary operations, maximum efficiency — a step toward next-generation intelligent trading.
preview
Neural Additive Models for Fully Interpretable Signal Attribution in MQL5

Neural Additive Models for Fully Interpretable Signal Attribution in MQL5

Build and deploy a Neural Additive Model natively in MQL5: one small network per feature, additive output, and no post-hoc explainability. The article provides a PyTorch trainer, two‑output ONNX export (signal and contributions), an include wrapper using OnnxCreateFromBuffer/OnnxRun, and an EA that prints real per‑feature contributions each bar. It covers identical feature math for training/export, threshold measurement, Strategy Tester results, and edge cases such as NaNs and out‑of‑distribution inputs.
preview
Building a PDF Creation Library in MQL5 (Part 3): The Byte-Exact Writer

Building a PDF Creation Library in MQL5 (Part 3): The Byte-Exact Writer

The article presents CPdfBuffer and CPdfWriter, a minimal MQL5 pair that derives all offsets from the output buffer instead of hand-maintaining numbers. CPdfWriter records object starts, writes a fixed-width cross-reference table and trailer, and ensures structural consistency. The result passes Part 2's validator, and a ready-to-use script converts arbitrary text to a paginated PDF.
preview
Constant Proportion Portfolio Insurance (CPPI) for MQL5: A Floor-Protected Capital Allocation Strategy

Constant Proportion Portfolio Insurance (CPPI) for MQL5: A Floor-Protected Capital Allocation Strategy

Build Constant Proportion Portfolio Insurance natively in MQL5. The article details the floor and cushion formulas, a rebalance engine that operates safely on both netting and hedging accounts, and a price‑only reference indicator that reuses the same math. A real Strategy Tester run on XAUUSD M5 demonstrates configuration, order sizing, and stability under a rebalance band.
preview
Creating Custom Indicators in MQL5 (Part 12): Mapping Liquidity with a Volume Profile Heatmap

Creating Custom Indicators in MQL5 (Part 12): Mapping Liquidity with a Volume Profile Heatmap

We build a volume profile heatmap indicator in MQL5 that bins window volume into uniform price levels and paints each bar as a column of colored cells behind the candles. We cover binning, heat coloring, the side profile, the point-of-control and value-area lines, and the liquidity readouts, with every level published to buffers. The result is a map of dense bands and thin gaps, showing how much traded volume sits above and below the current price.
preview
How to Replace a WebSocket EA with TradeMux REST in MetaTrader 5

How to Replace a WebSocket EA with TradeMux REST in MetaTrader 5

The article continues the series on AI Hedge Fund and addresses three limitations of v4: analysts' reputation scores are now stored persistently in SQLite, the EA has been removed from the critical execution path, and signals from the council of fifteen are distributed to multiple brokers via the TradeMux REST API. The logic behind the council and risk management has remained the same: Python retrieves data via the MetaTrader 5 SDK and executes orders directly. The result is resilience to restarts and scalability across multiple terminals.
preview
Crypto Exchange Integration with MQL5 (Part 1): Connecting to MEXC Futures

Crypto Exchange Integration with MQL5 (Part 1): Connecting to MEXC Futures

This article introduces the foundations of connecting MetaTrader 5 to a cryptocurrency exchange using MQL5 and the MEXC Futures API. It covers terminal configuration, JSON response processing, WebRequest() execution and validation, and conversion of API data into native MQL5 types. Practical examples demonstrate retrieving and processing exchange data. These components establish the basis for a reusable MEXC Futures client, developed progressively throughout the series. The series focuses exclusively on exchange integration; how readers use the retrieved data remains outside its scope.
preview
Constant Proportion Portfolio Insurance (CPPI) for MQL5: A Floor-Protected Capital Allocation Strategy

Constant Proportion Portfolio Insurance (CPPI) for MQL5: A Floor-Protected Capital Allocation Strategy

Build Constant Proportion Portfolio Insurance natively in MQL5. The article details the floor and cushion formulas, a rebalance engine that operates safely on both netting and hedging accounts, and a price‑only reference indicator that reuses the same math. A real Strategy Tester run on XAUUSD M5 demonstrates configuration, order sizing, and stability under a rebalance band.
preview
Confident Learning: Finding Mislabeled Trades Before They Poison Your Classifier

Confident Learning: Finding Mislabeled Trades Before They Poison Your Classifier

The article focuses on label-auditing for meta-labeling, not on a new entry signal. It presents a native MQL5 implementation of confident learning with out-of-fold scoring and calibrated pruning, plus an EA switch that trains the meta-filter on raw or cleaned datasets. A controlled Strategy Tester comparison helps you quantify noise and choose a pruning level that preserves generalization.
preview
Practical Modules from Other Languages in MQL5 (Part 09): MATPLOTLIB (II)

Practical Modules from Other Languages in MQL5 (Part 09): MATPLOTLIB (II)

Learn how to create advanced visualizations in MetaTrader 5 using a Matplotlib-like API from MQL5 while Python handles rendering. We implement key chart types—scatter, bar, horizontal bar, histogram, pie, and hexbin—and show how to control axes, legends, colorbars, and styles. The result is a consistent workflow for exploring trading and financial datasets.