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
From Basic to Intermediate: FileSave and FileLoad

From Basic to Intermediate: FileSave and FileLoad

In today’s article, we will look at several ways to work with the FileSave and FileLoad library functions. Although many people consider them of limited use because of certain limitations or difficulties they create in specific scenarios, properly understanding how these two functions work can save us a great deal of effort at certain points. They are also an excellent way to work with log files.
preview
Real-Time Trade Event Logger to SQLite via MQL5 DLL Bridge

Real-Time Trade Event Logger to SQLite via MQL5 DLL Bridge

The article shows how to build an MQL5 EA that writes every deal to an SQLite database the moment it appears, using the built-in Database API as the SQLite bridge. It implements an event data model, a prepared INSERT workflow reused across calls, session-safe recovery after restarts, and deal detection via OnTrade(). You can open the resulting file with any SQLite client to run queries for analysis and reporting.
preview
Automated Trade Statement Exporter to Excel-Compatible XLSX in MQL5

Automated Trade Statement Exporter to Excel-Compatible XLSX in MQL5

An MQL5 script reconstructs closed trades from deal history using a two-pass SL/TP lookup and exports them to an Excel-compatible XLSX file without third-party libraries. Four cooperating classes handle trade data, history reconstruction, SpreadsheetML XML generation, and ZIP assembly via .NET's ZipFile class through a direct ShellExecuteW call with marker-file polling. The output opens in Excel and Google Sheets with correct numeric types, formatted date columns, and a bold header row.
preview
Exporting Symbol Tick Data to Binary Files in MQL5 for Offline Analysis

Exporting Symbol Tick Data to Binary Files in MQL5 for Offline Analysis

The article delivers a complete, verifiable tick export path from MQL5 to a binary file and into Python. It defines a 64‑byte header, 48‑byte records with millisecond time and flags, an export pipeline using CopyTicksRange(), and a single‑call NumPy loader. Users obtain compact, precision‑preserving files and a reproducible workflow for vectorized analysis.
preview
Implementing and Benchmarking Bag-of-SFA-Symbols (BOSS) Against Dynamic Time Warping (DTW)

Implementing and Benchmarking Bag-of-SFA-Symbols (BOSS) Against Dynamic Time Warping (DTW)

This article implements BOSS from scratch in MQL5 and applies it to regime classification: SFA turns windows into words, bags record word frequencies, and an ensemble over window lengths votes on labels. We cover the encoding steps, the BOSS distance, training with auto-generated regime labels, and practical parameters. A BTCUSD benchmark versus DTW shows higher macro accuracy on clean data and markedly faster inference.
preview
Exporting Custom Indicator Buffers to CSV for Python Backtesting Pipelines

Exporting Custom Indicator Buffers to CSV for Python Backtesting Pipelines

We build a CSV exporter for MQL5 custom indicators that preserves the exact values seen on the chart. The script creates the indicator handle with iCustom, waits for BarsCalculated, aligns buffers to CopyRates, and writes a locale-safe CSV that pandas loads with parsed dates and NaN for warm-up bars. It addresses compile-time argument limits, jagged-array workarounds, and EMPTY_VALUE handling, enabling reliable Python backtests without re-coding the indicator.
preview
MCMC Sampling Methods: The Slice Sampling Algorithm

MCMC Sampling Methods: The Slice Sampling Algorithm

The article examines slice sampling — an adaptive MCMC algorithm that automatically adjusts its sampling parameters. Its effectiveness is demonstrated using Bayesian linear and logistic regression models, and the results are compared with classical frequentist methods.
preview
Measuring broker execution quality in MQL5: Why your live account doesn't match the backtest

Measuring broker execution quality in MQL5: Why your live account doesn't match the backtest

Live performance often drifts from backtests because of execution friction. We introduce an MQL5 diagnostic EA that records entry and exit slippage, asymmetry, observed spread, requotes, and per-leg latency, using a precise probe mode and an approximate passive mode, and writes every sample to CSV. Use the results to distinguish strategy issues from execution effects across your terminal, network, broker, and liquidity.
preview
Path Signatures for Lead-Lag Detection

Path Signatures for Lead-Lag Detection

Build a level-2 path-signature engine in pure MQL5 to read the lead-lag ordering between two data streams without choosing a lag and without a linear model. The article delivers a reusable library, an indicator that plots the Levy‑area oscillator, and a simple rule‑based Expert Advisor. Code is cross‑checked against closed‑form cases, and the components are ready to plug into your projects.
preview
Generating a Per-Symbol Trade Analytics PDF Report from MQL5

Generating a Per-Symbol Trade Analytics PDF Report from MQL5

This article shows how to generate a dependency-free, single-page PDF report in MQL5 using only string assembly and the FILE_BIN API. The script computes per-symbol trade statistics, then renders a labeled table and an equity curve with explicit PDF color and drawing operators. Statistics are calculated in a standalone module, so every value can be verified against synthetic data without relying on a live trading account.
preview
Neural Networks in Trading: A Cross-Domain Time Series Forecasting Framework (Conclusion)

Neural Networks in Trading: A Cross-Domain Time Series Forecasting Framework (Conclusion)

The article focuses on the practical implementation of the TimeFound model for time series forecasting. The key stages of implementing the framework's main approaches using MQL5 are examined.
preview
Implementing Anchored VWAP Indicator in MQL5: A Step-by-Step Guide

Implementing Anchored VWAP Indicator in MQL5: A Step-by-Step Guide

A step-by-step guide to building an anchored VWAP indicator with an interactive draggable anchor line in MQL5. The article covers the complete implementation, including calculation methodology, session resets, standard deviation bands, and custom visualization. Learn the architectural design decisions behind stateless boundary detection, multi-instance support, and cross-asset volume handling to build a versatile indicator with benchmarking, technical, and analytical capabilities.
preview
Integrating MQL5 with Data Processing Packages (Part 10): Deploying Python AutoML Pipelines for Strategy Testing

Integrating MQL5 with Data Processing Packages (Part 10): Deploying Python AutoML Pipelines for Strategy Testing

This article presents a reproducible MetaTrader 5 workflow: collect history, engineer nine context features, label simulated EMA crossover trades, train with FLAML, and export to ONNX with fixed opset and plain probabilities. The Expert Advisor loads the model natively, mirrors the Python feature contract, and uses a tunable confidence threshold as a trade filter. Readers can swap signals and features to reuse the same pipeline.
preview
Feature Engineering for ML (Part 11): Fractal Features in Python

Feature Engineering for ML (Part 11): Fractal Features in Python

The article examines a Williams five‑bar fractal feature pipeline and shows how a centered rolling window creates a true look‑ahead leak. It identifies two additional silent bugs—a hardcoded shift tied to the default n and a volatility threshold that ignores its input—and consolidates fixes under a single leak_safe flag. Readers get leak‑free fractal, level, trend, and signal features, plus guidance on when unshifted columns remain valid for labeling.
preview
A Team of AI Agents with Profit-Based Rotation: The Evolution of a Living Trading System in MQL5

A Team of AI Agents with Profit-Based Rotation: The Evolution of a Living Trading System in MQL5

Financial management as an ecosystem: Seven AI traders with different personalities and strategies instead of a single algorithm. They compete for capital, learn from their mistakes, and make decisions collectively. The article explains the principles behind the Modern RL Trader system, in which the code possesses consciousness and emotions, creating a living, evolving trading mind.