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
A Generic Object Pool in MQL5: Eliminating Heap Fragmentation in High-Frequency Indicators

A Generic Object Pool in MQL5: Eliminating Heap Fragmentation in High-Frequency Indicators

High-frequency MQL5 indicators that instantiate objects on every tick accumulate allocation overhead and timing jitter in OnCalculate(). This article constructs a generic templated object pool using a free-list index array, delivering O(1) Acquire() and Release() operations. The design includes double-release protection, strict separation of payload state from pool metadata in Reset(), and a fixed-capacity free list with no heap fallback. A dual-path custom indicator benchmark measures per-tick overhead difference using GetMicrosecondCount().
preview
MQL5 Trading Tools (Part 36): Adding Shape and Annotation Tools with In-Place Label Editing to the Canvas Drawing Layer

MQL5 Trading Tools (Part 36): Adding Shape and Annotation Tools with In-Place Label Editing to the Canvas Drawing Layer

We add eight shape tools and nine annotation tools to the canvas and implement a full in-place label-editing system. The article walks through geometry, AA rendering, shared word-wrap and supersampled text helpers, and the caret-driven state machine for typing, navigation, and selection. This yields a complete, consistent annotation toolkit with editable labels that plugs into the prior interaction pipeline.
preview
From Static MA to Adaptive Filtering (Part 1): Introducing SAMA with NLMS in MQL5

From Static MA to Adaptive Filtering (Part 1): Introducing SAMA with NLMS in MQL5

This article introduces the Self-Adaptive Moving Average (SAMA), an adaptive filter leveraging the Normalized Least Mean Squares (NLMS) algorithm. It explores why fixed-period averages fail, how NLMS adapts bar by bar, and the engineering protections required for production. This conceptual and mathematical foundation prepares you for the MQL5 code implementation in Part 2.
preview
Swing Extremes and Pullbacks (Part 4): Dynamic Pullback Depth Using Volatility Models

Swing Extremes and Pullbacks (Part 4): Dynamic Pullback Depth Using Volatility Models

This article replaces binary swing validation with a volatility‑normalized pullback model. Retracement depth is measured as a ratio of the prior impulse and calibrated to a rolling ATR regime, while entries require a minimum quality score and confirmation by structure or liquidity signals. The five‑layer design integrates detection, validation, liquidity mapping, regime‑aware scoring, and execution, helping you filter weak corrections and size stops dynamically to current conditions.