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
Distribution-Free Price Channels in MQL5: Quantile Regression by Iteratively Reweighted Least Squares

Distribution-Free Price Channels in MQL5: Quantile Regression by Iteratively Reweighted Least Squares

We build a rolling price channel by fitting the 0.1, 0.5 and 0.9 conditional quantile lines via IRLS with pinball loss, packaged as a reusable class and two MetaTrader 5 indicators. We verify in-sample coverage, examine quantile crossing, and compare the channel width with ATR, Bollinger and regression widths on matched horizons. Tests in the Strategy Tester show the edges are descriptive, while the normalized width works as a volatility/regime feature.
preview
Implementing a Daily Loss Limit and Drawdown Circuit Breaker in MQL5

Implementing a Daily Loss Limit and Drawdown Circuit Breaker in MQL5

This article presents a circuit breaker for MQL5 that monitors combined daily P&L (realized plus floating) on every tick and compares it to a configured loss limit. On breach, it closes positions, cancels pending orders, and activates a HALTED state that blocks further order submission in the EA until server‑time midnight. The package provides a chart dashboard, a demo Expert Advisor, a verification script, and notes on extending the halt signal across EAs.
preview
Meta-Labeling the Classics (Part 3): Filtering and Sizing Bollinger Band Trades

Meta-Labeling the Classics (Part 3): Filtering and Sizing Bollinger Band Trades

Bollinger Band mean reversion degrades in trending regimes when ADX is high and bandwidth expands. We separate direction from trade selection with a two‑stage meta‑labeling pipeline: a gradient‑boosted secondary classifier trained with PurgedKFold on band‑specific features (BBP, BBB, bandwidth regime) outputs action probabilities that drive probability‑based bet sizing. The MQL5 implementation loads the ONNX model and applies position sizing within a two‑EA architecture to filter low‑quality band touches.
preview
From Novice to Expert: Candlestick Momentum Confirmation for Classic Crossover Strategies

From Novice to Expert: Candlestick Momentum Confirmation for Classic Crossover Strategies

In this article, we refine a moving average crossover strategy with a momentum candle filter and an immediate retracement bar confirmation. When both conditions are met, a pending stop order is placed using a pivot-based stop loss and a 2R take profit. The complete MQL5 Expert Advisor code, finite-state-machine logic, and chart annotations are detailed.
preview
Distribution-Free Price Channels in MQL5: Quantile Regression by Iteratively Reweighted Least Squares

Distribution-Free Price Channels in MQL5: Quantile Regression by Iteratively Reweighted Least Squares

We build a rolling price channel by fitting the 0.1, 0.5 and 0.9 conditional quantile lines via IRLS with pinball loss, packaged as a reusable class and two MetaTrader 5 indicators. We verify in-sample coverage, examine quantile crossing, and compare the channel width with ATR, Bollinger and regression widths on matched horizons. Tests in the Strategy Tester show the edges are descriptive, while the normalized width works as a volatility/regime feature.
preview
Implementing a Daily Loss Limit and Drawdown Circuit Breaker in MQL5

Implementing a Daily Loss Limit and Drawdown Circuit Breaker in MQL5

This article presents a circuit breaker for MQL5 that monitors combined daily P&L (realized plus floating) on every tick and compares it to a configured loss limit. On breach, it closes positions, cancels pending orders, and activates a HALTED state that blocks further order submission in the EA until server‑time midnight. The package provides a chart dashboard, a demo Expert Advisor, a verification script, and notes on extending the halt signal across EAs.
preview
Neural Networks in Trading: Probabilistic Time Series Forecasting (Conclusion)

Neural Networks in Trading: Probabilistic Time Series Forecasting (Conclusion)

We invite you to learn about the K²VAE framework and how the proposed approaches can be integrated into a trading system. You will learn how the hybrid Koopman–Kalman–VAE approach helps build adaptive and interpretable models. The article concludes with practical results from using the implemented solutions.
preview
Price Action Analysis Toolkit Development (Part 79): Extending the Indicator Search Panel with Dynamic Input Parameter Configuration

Price Action Analysis Toolkit Development (Part 79): Extending the Indicator Search Panel with Dynamic Input Parameter Configuration

We integrate parameter configuration into the indicator search workflow in MQL5. A central repository describes each indicator's inputs, a dynamic dialog renders controls from those definitions, and the dialog validates entries and converts them to MqlParam. The chart launcher then creates the indicator with IndicatorCreate using the provided values. This streamlines attaching indicators with custom settings on the chosen symbol.
preview
Building a Compile-Time Unit Testing Framework in MQL5 Using Preprocessor Assertions

Building a Compile-Time Unit Testing Framework in MQL5 Using Preprocessor Assertions

MQL5 lacks native unit testing, so utility bugs in lot sizing, pip value, and normalization often slip into production. This article presents a zero‑dependency framework built from preprocessor assertion macros, interface‑based suites, and a central runner/formatter. It runs as a script in OnStart, executes deterministic tests, and prints pass/fail summaries to the Experts tab to catch rounding, boundary, and error-handling defects before deployment.
preview
Building a Gold Volatility Regime Monitor from Options Data in MQL5

Building a Gold Volatility Regime Monitor from Options Data in MQL5

A practical bridge from the options market into MetaTrader 5 for gold. We compute near-the-money implied volatility by solving Black-Scholes from quoted prices, compare it with 30-day realized volatility, and use the ratio as a regime proxy. A Python feed publishes the value, an MQL5 script consumes it with WebRequest, and a background service keeps a panel current and alerts on changes. Source code for all parts is provided.
preview
Larry Williams Market Secrets (Part 17) : Detecting Oops Signals Using a Custom Indicator

Larry Williams Market Secrets (Part 17) : Detecting Oops Signals Using a Custom Indicator

This article implements an MQL5 custom indicator that detects Larry Williams Oops gap reversals and marks bullish and bearish arrows on the chart. It details configurable gap and validity thresholds, same-bar or later confirmation, first-fill-only logic, historical backfilling, and incremental updates so signals remain consistent on both history and newly completed bars.
preview
Price Action Analysis Toolkit Development (Part 79): Extending the Indicator Search Panel with Dynamic Input Parameter Configuration

Price Action Analysis Toolkit Development (Part 79): Extending the Indicator Search Panel with Dynamic Input Parameter Configuration

We integrate parameter configuration into the indicator search workflow in MQL5. A central repository describes each indicator's inputs, a dynamic dialog renders controls from those definitions, and the dialog validates entries and converts them to MqlParam. The chart launcher then creates the indicator with IndicatorCreate using the provided values. This streamlines attaching indicators with custom settings on the chosen symbol.
preview
Implementing a Trade Throttle and Rate Limiter in MQL5

Implementing a Trade Throttle and Rate Limiter in MQL5

We build a trade throttle for MQL5 EAs using a token bucket with a priority queue to control order submission rate. Tokens refill at a configurable per‑second rate, allowing short bursts up to capacity and then enforcing sustained throughput. When the bucket is empty, requests are queued and later released by priority with FIFO tiebreaks. This keeps execution within safe limits without discarding valid signals under load.
preview
Controller Objects for Everything: Draggable Slider Control

Controller Objects for Everything: Draggable Slider Control

The article details a complete MQL5 implementation of a draggable slider for controlling ranges on the chart. It introduces the CDragHandle class, private state, public APIs for dimensions, colors, range, and value, plus Refresh* and UpdateHandlePosition logic and event processing. A working example changes CHART_SCALE, demonstrating how to connect the control to platform properties.
preview
Hypothesis Testing for Trading Strategies — Proving Whether Your Edge is Real

Hypothesis Testing for Trading Strategies — Proving Whether Your Edge is Real

Net profit and win rate do not tell you if a strategy's edge is statistically real. This MQL5 toolkit analyzes return series built from price data or deal history and reports t‑statistics, p‑values, and confidence intervals using one-sample and Welch t‑tests, the Mann–Whitney U test, and volatility‑regime analysis to support evidence‑based trading decisions.
preview
Motifs and Discords: Building a Matrix Profile from Scratch

Motifs and Discords: Building a Matrix Profile from Scratch

We build the Matrix Profile for MQL5 from the ground up and keep it numerically stable on real prices. The library includes rolling statistics, a radix-2 FFT powering MASS, and a STOMP self-join, with results matched to stumpy. A compact facade, an indicator that draws the profile and flags discords, and a demonstration Expert Advisor show how to read and use the signal in practice.
preview
Quantum Computing and Gradient Boosting in EURUSD Trading

Quantum Computing and Gradient Boosting in EURUSD Trading

The article describes the practical implementation of a hybrid algorithmic trading system that combines quantum computing (IBM Qiskit) and gradient boosting (CatBoost) to predict movements in the EURUSD pair on the hourly time frame. The system extracts four unique quantum features from a probability distribution across 256 states using eight qubits and, in combination with classical indicators and delta encoding of time categories, achieves 62% accuracy on 15,000 candlesticks.
preview
A Reusable Breakeven Manager in MQL5 with Spread Compensation

A Reusable Breakeven Manager in MQL5 with Spread Compensation

A robust breakeven implementation for MQL5 is built around live spread sampling and correct pip-to-price conversion by symbol digits. CBreakevenManager moves SL to open_price ± spread ± buffer once a real‑pip activation threshold is reached and prevents duplicate modifications. A demo EA shows the behavioral difference versus a naive breakeven, and a script verifies core calculations.
preview
Network Momentum for MetaTrader5: Trading the Lead-Lag Graph Between Markets

Network Momentum for MetaTrader5: Trading the Lead-Lag Graph Between Markets

This article builds a trend-following Expert Advisor that trades momentum spillover across markets, implemented fully in MQL5 without external solvers. It detects leaders with Derivative Dynamic Time Warping, learns a sparse weighted network by convex optimization, and propagates momentum through it with a reverting response. Readers get a step-by-step, reproducible pipeline and a working EA ready to run in the Strategy Tester.
preview
Neural Networks in Trading: An End-to-End Multivariate Time Series Forecasting Model (GinAR)

Neural Networks in Trading: An End-to-End Multivariate Time Series Forecasting Model (GinAR)

We invite you to explore an innovative approach to forecasting time series with missing data using the GinAR framework. The article demonstrates the implementation of key components using OpenCL, which ensures high performance. In our next publication, we will take a detailed look at how to integrate these solutions into MQL5. This will help understand how to apply the method in practice in trading.