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
Foundation Models for Trading (Part II): Decoding, Autoregression, and an Exact KV-Cache

Foundation Models for Trading (Part II): Decoding, Autoregression, and an Exact KV-Cache

We complete the native MQL5 port of Kronos: the decoder, the predictor's decode_s1 and decode_s2 stages with their cross-attention traps, and the autoregressive loop that produces a multi-bar forecast. Then we profile and make it roughly 4.5x faster with an exact KV-cache and pre-transposed weights, verifying every stage against PyTorch.
preview
CSV Data Analysis (Part 8): Building an SQLite Strategy Registry from Accumulated CSV Exports

CSV Data Analysis (Part 8): Building an SQLite Strategy Registry from Accumulated CSV Exports

Flat files work well at the start of an MQL5 research pipeline, but they hinder cross-run queries and provenance once the archive grows. We build a Python-based SQLite registry that ingests CSV exports with SHA-1 deduplication, records EA version and run timestamps, applies forward-only schema migrations, and indexes common filters. You get a structured query layer for fast lookups, robustness checks, and version comparisons across all campaigns.
preview
How To Debug MQL5 Code in MetaEditor

How To Debug MQL5 Code in MetaEditor

This article is a practical walk-through of the MetaEditor debugger using a rolling z‑score indicator with two planted bugs: an off‑by‑one array access and a silent wrong‑denominator variance. We show how to set breakpoints, step through code, read the call stack, and inspect values in the Watch window. You will learn a repeatable method to catch both crashing index errors and tiny numerical biases that charts cannot reveal.
preview
Designing a Partial Close Engine in MQL5 with Configurable Profit Ladders

Designing a Partial Close Engine in MQL5 with Configurable Profit Ladders

This MQL5 engine applies configurable profit ladders in R‑multiples to manage partial closes reliably. It prevents stranded remainders by rounding to lot step, computes close percentages from the original entry volume, and moves the stop to breakeven when configured. A supported filling mode is chosen automatically, and the download includes seven include files, a demo EA, and a verification script.
preview
Online Machine Learning for Trade Signal Filtering in MQL5 (Part 1)

Online Machine Learning for Trade Signal Filtering in MQL5 (Part 1)

This article implements an online logistic‑regression trade filter in native MQL5 and integrates it into an EMA‑crossover EA with a closed‑trade feedback loop. It details the shared class, features, SGD update, persistence, and a read‑only probability view. Synthetic experiments cover multi‑seed separation, calibration, feature ablation, regime‑shift baselines, and hyperparameter sweeps. You get reproducible scripts and a walk‑forward protocol to validate the filter on your own instrument.
preview
Feature Engineering for ML (Part 14): Trend-Scanning Features in MQL5

Feature Engineering for ML (Part 14): Trend-Scanning Features in MQL5

A naive MQL5 port of trend-scanning features recomputes each candidate window per bar at O(H·L) cost. This article introduces CTrendScanningFeatures.mqh, which maintains three running sums per horizon and updates them in O(1) per bar, verified against a Python reference. The indicator exposes four causal buffers - window, slope, t_value, rsquared - at the confirmation bar and corrects a sign inversion present in the original backward labeling mode.
preview
Measuring Market Efficiency with Lempel-Ziv Complexity

Measuring Market Efficiency with Lempel-Ziv Complexity

This article presents a compact MQL5 library for market-complexity analysis: LZ76 complexity and Normalized Compression Distance built on a SAX symbolizer, exposed through a simple facade and an efficiency indicator. It explains the discretization choices, normalization, and distance formulation, and validates the code with unit checks and an independent cross-check. You get a ready-to-use library and indicator, plus a disciplined way to interpret readings with a shuffle null and a direction check.
preview
Automating Chart Patterns in MQL5 (Part 1): The Multi-Timeframe Swing Structure Engine

Automating Chart Patterns in MQL5 (Part 1): The Multi-Timeframe Swing Structure Engine

This article presents CSwingEngine, a reusable MQL5 class that detects H4 swing highs and lows, labels them HH, LH, HL, or LL, and classifies market structure as trend or range. Swings are always computed on H4, regardless of the attached chart, and each point draws correctly on lower timeframes via native datetime anchoring. The engine exposes a clean interface to query the current trend and retrieve the swing array for context-aware pattern logic.
preview
Does This Entry Filter Really Add Edge? A Block-Permutation Test in MQL5

Does This Entry Filter Really Add Edge? A Block-Permutation Test in MQL5

An MQL5 analyzer reconstructs completed trades, records acceptance labels, and measures the accepted-minus-rejected mean net-profit difference. It benchmarks that statistic against individual permutations, equal-block permutations, and circular shifts while preserving the accepted count. Block-size sensitivity, CSV exports, and coordinated base/filtered passes separate statistical selection evidence from operational effects on profit, drawdown, and efficiency metrics.
preview
Larry Williams Market Secrets (Part 16): Detecting and Trading the Oops Gap Reversal Pattern

Larry Williams Market Secrets (Part 16): Detecting and Trading the Oops Gap Reversal Pattern

Learn how to build an MQL5 Expert Advisor that detects and trades Larry Williams’ Oops Gap Reversal pattern using objective gap rules and later-bar confirmation. The EA tracks setup expiration, prepares stop-loss and take-profit levels, supports manual or risk-based position sizing, executes market orders, and is evaluated through historical testing.