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
Price Action Analysis Toolkit Development (Part 38): Tick Buffer VWAP and Short-Window Imbalance Engine

Price Action Analysis Toolkit Development (Part 38): Tick Buffer VWAP and Short-Window Imbalance Engine

In Part 38, we build a production-grade MT5 monitoring panel that converts raw ticks into actionable signals. The EA buffers tick data to compute tick-level VWAP, a short-window imbalance (flow) metric, and ATR-based position sizing. It then visualizes spread, ATR, and flow with low-flicker bars. The system calculates a suggested lot size and a 1R stop, and issues configurable alerts for tight spreads, strong flow, and edge conditions. Auto-trading is intentionally disabled; the focus remains on robust signal generation and a clean user experience.
preview
Black Hole Algorithm (BHA)

Black Hole Algorithm (BHA)

The Black Hole Algorithm (BHA) uses the principles of black hole gravity to optimize solutions. In this article, we will look at how BHA attracts the best solutions while avoiding local extremes, and why this algorithm has become a powerful tool for solving complex problems. Learn how simple ideas can lead to impressive results in the world of optimization.
preview
Developing a Replay System (Part 78): New Chart Trade (V)

Developing a Replay System (Part 78): New Chart Trade (V)

In this article, we will look at how to implement part of the receiver code. Here we will implement an Expert Advisor to test and learn how the protocol interaction works. The content presented here is intended solely for educational purposes. Under no circumstances should the application be viewed for any purpose other than to learn and master the concepts presented.
preview
Neural Networks in Trading: A Multi-Agent Self-Adaptive Model (Final Part)

Neural Networks in Trading: A Multi-Agent Self-Adaptive Model (Final Part)

In the previous article, we introduced the multi-agent adaptive framework MASA, which combines reinforcement learning approaches and self-adaptive strategies, providing a harmonious balance between profitability and risk in turbulent market conditions. We have built the functionality of individual agents within this framework. In this article, we will continue the work we started, bringing it to its logical conclusion.
preview
Automating Trading Strategies in MQL5 (Part 29): Creating a price action Gartley Harmonic Pattern system

Automating Trading Strategies in MQL5 (Part 29): Creating a price action Gartley Harmonic Pattern system

In this article, we develop a Gartley Pattern system in MQL5 that identifies bullish and bearish Gartley harmonic patterns using pivot points and Fibonacci ratios, executing trades with precise entry, stop loss, and take-profit levels. We enhance trader insight with visual feedback through chart objects like triangles, trendlines, and labels to clearly display the XABCD pattern structure.
preview
Building a Trading System (Part 3): Determining Minimum Risk Levels for Realistic Profit Targets

Building a Trading System (Part 3): Determining Minimum Risk Levels for Realistic Profit Targets

Every trader's ultimate goal is profitability, which is why many set specific profit targets to achieve within a defined trading period. In this article, we will use Monte Carlo simulations to determine the optimal risk percentage per trade needed to meet trading objectives. The results will help traders assess whether their profit targets are realistic or overly ambitious. Finally, we will discuss which parameters can be adjusted to establish a practical risk percentage per trade that aligns with trading goals.
preview
Multi-module trading robot in Python and MQL5 (Part I): Creating basic architecture and first modules

Multi-module trading robot in Python and MQL5 (Part I): Creating basic architecture and first modules

We are going to develop a modular trading system that combines Python for data analysis with MQL5 for trade execution. Four independent modules monitor different market aspects in parallel: volumes, arbitrage, economics and risks, and use RandomForest with 400 trees for analysis. Particular emphasis is placed on risk management, since even the most advanced trading algorithms are useless without proper risk management.
preview
MetaTrader Meets Google Sheets with Pythonanywhere: A Guide to Secure Data Flow

MetaTrader Meets Google Sheets with Pythonanywhere: A Guide to Secure Data Flow

This article demonstrates a secure way to export MetaTrader data to Google Sheets. Google Sheet is the most valuable solution as it is cloud based and the data saved in there can be accessed anytime and from anywhere. So traders can access trading and related data exported to google sheet and do further analysis for future trading anytime and wherever they are at the moment.
preview
From Novice to Expert: Mastering Detailed Trading Reports with Reporting EA

From Novice to Expert: Mastering Detailed Trading Reports with Reporting EA

In this article, we delve into enhancing the details of trading reports and delivering the final document via email in PDF format. This marks a progression from our previous work, as we continue exploring how to harness the power of MQL5 and Python to generate and schedule trading reports in the most convenient and professional formats. Join us in this discussion to learn more about optimizing trading report generation within the MQL5 ecosystem.
preview
Chart Synchronization for Easier Technical Analysis

Chart Synchronization for Easier Technical Analysis

Chart Synchronization for Easier Technical Analysis is a tool that ensures all chart timeframes display consistent graphical objects like trendlines, rectangles, or indicators across different timeframes for a single symbol. Actions such as panning, zooming, or symbol changes are mirrored across all synced charts, allowing traders to seamlessly view and compare the same price action context in multiple timeframes.
preview
Developing a Replay System (Part 77): New Chart Trade (IV)

Developing a Replay System (Part 77): New Chart Trade (IV)

In this article, we will cover some of the measures and precautions to consider when creating a communication protocol. These are pretty simple and straightforward things, so we won't go into too much detail in this article. But to understand what will happen, you need to understand the content of the article.
preview
Simplifying Databases in MQL5 (Part 1): Introduction to Databases and SQL

Simplifying Databases in MQL5 (Part 1): Introduction to Databases and SQL

We explore how to manipulate databases in MQL5 using the language's native functions. We cover everything from table creation, insertion, updating, and deletion to data import and export, all with sample code. The content serves as a solid foundation for understanding the internal mechanics of data access, paving the way for the discussion of ORM, where we'll build one in MQL5.
preview
Trend criteria in trading

Trend criteria in trading

Trends are an important part of many trading strategies. In this article, we will look at some of the tools used to identify trends and their characteristics. Understanding and correctly interpreting trends can significantly improve trading efficiency and minimize risks.
preview
Getting Started with MQL5 Algo Forge

Getting Started with MQL5 Algo Forge

We are introducing MQL5 Algo Forge — a dedicated portal for algorithmic trading developers. It combines the power of Git with an intuitive interface for managing and organizing projects within the MQL5 ecosystem. Here, you can follow interesting authors, form teams, and collaborate on algorithmic trading projects.
preview
Automating Trading Strategies in MQL5 (Part 28): Creating a Price Action Bat Harmonic Pattern with Visual Feedback

Automating Trading Strategies in MQL5 (Part 28): Creating a Price Action Bat Harmonic Pattern with Visual Feedback

In this article, we develop a Bat Pattern system in MQL5 that identifies bullish and bearish Bat harmonic patterns using pivot points and Fibonacci ratios, triggering trades with precise entry, stop loss, and take-profit levels, enhanced with visual feedback through chart objects
preview
Analyzing binary code of prices on the exchange (Part II): Converting to BIP39 and writing GPT model

Analyzing binary code of prices on the exchange (Part II): Converting to BIP39 and writing GPT model

Continuing tries to decipher price movements... What about linguistic analysis of the "market dictionary" that we get by converting the binary price code to BIP39? In this article, we will delve into an innovative approach to exchange data analysis and consider how modern natural language processing techniques can be applied to the market language.
preview
Neural Networks in Trading: A Multi-Agent Self-Adaptive Model (MASA)

Neural Networks in Trading: A Multi-Agent Self-Adaptive Model (MASA)

I invite you to get acquainted with the Multi-Agent Self-Adaptive (MASA) framework, which combines reinforcement learning and adaptive strategies, providing a harmonious balance between profitability and risk management in turbulent market conditions.
preview
Artificial Tribe Algorithm (ATA)

Artificial Tribe Algorithm (ATA)

The article provides a detailed discussion of the key components and innovations of the ATA optimization algorithm, which is an evolutionary method with a unique dual behavior system that adapts depending on the situation. ATA combines individual and social learning while using crossover for explorations and migration to find solutions when stuck in local optima.
preview
Analyzing binary code of prices on the exchange (Part I): A new look at technical analysis

Analyzing binary code of prices on the exchange (Part I): A new look at technical analysis

This article presents an innovative approach to technical analysis based on converting price movements into binary code. The author demonstrates how various aspects of market behavior — from simple price movements to complex patterns — can be encoded in a sequence of zeros and ones.
preview
Self Optimizing Expert Advisors in MQL5 (Part 13): A Gentle Introduction To Control Theory Using Matrix Factorization

Self Optimizing Expert Advisors in MQL5 (Part 13): A Gentle Introduction To Control Theory Using Matrix Factorization

Financial markets are unpredictable, and trading strategies that look profitable in the past often collapse in real market conditions. This happens because most strategies are fixed once deployed and cannot adapt or learn from their mistakes. By borrowing ideas from control theory, we can use feedback controllers to observe how our strategies interact with markets and adjust their behavior toward profitability. Our results show that adding a feedback controller to a simple moving average strategy improved profits, reduced risk, and increased efficiency, proving that this approach has strong potential for trading applications.
preview
Introduction to MQL5 (Part 20): Introduction to Harmonic Patterns

Introduction to MQL5 (Part 20): Introduction to Harmonic Patterns

In this article, we explore the fundamentals of harmonic patterns, their structures, and how they are applied in trading. You’ll learn about Fibonacci retracements, extensions, and how to implement harmonic pattern detection in MQL5, setting the foundation for building advanced trading tools and Expert Advisors.
preview
Statistical Arbitrage Through Cointegrated Stocks (Part 3): Database Setup

Statistical Arbitrage Through Cointegrated Stocks (Part 3): Database Setup

This article presents a sample MQL5 Service implementation for updating a newly created database used as source for data analysis and for trading a basket of cointegrated stocks. The rationale behind the database design is explained in detail and the data dictionary is documented for reference. MQL5 and Python scripts are provided for the database creation, schema initialization, and market data insertion.
preview
From Novice to Expert: Animated News Headline Using MQL5 (IX) — Multiple Symbol Management on a single chart for News Trading

From Novice to Expert: Animated News Headline Using MQL5 (IX) — Multiple Symbol Management on a single chart for News Trading

News trading often requires managing multiple positions and symbols within a very short time due to heightened volatility. In today’s discussion, we address the challenges of multi-symbol trading by integrating this feature into our News Headline EA. Join us as we explore how algorithmic trading with MQL5 makes multi-symbol trading more efficient and powerful.
preview
Reimagining Classic Strategies (Part 15): Daily Breakout Trading Strategy

Reimagining Classic Strategies (Part 15): Daily Breakout Trading Strategy

Human traders had long participated in financial markets before the rise of computers, developing rules of thumb that guided their decisions. In this article, we revisit a well-known breakout strategy to test whether such market logic, learned through experience, can hold its own against systematic methods. Our findings show that while the original strategy produced high accuracy, it suffered from instability and poor risk control. By refining the approach, we demonstrate how discretionary insights can be adapted into more robust, algorithmic trading strategies.
preview
From Basic to Intermediate: Template and Typename (IV)

From Basic to Intermediate: Template and Typename (IV)

In this article, we will take a very close look at how to solve the problem posed at the end of the previous article. There was an attempt to create a template of such type so that to be able to create a template for data union.
preview
MetaTrader 5 Machine Learning Blueprint (Part 2): Labeling Financial Data for Machine Learning

MetaTrader 5 Machine Learning Blueprint (Part 2): Labeling Financial Data for Machine Learning

In this second installment of the MetaTrader 5 Machine Learning Blueprint series, you’ll discover why simple labels can lead your models astray—and how to apply advanced techniques like the Triple-Barrier and Trend-Scanning methods to define robust, risk-aware targets. Packed with practical Python examples that optimize these computationally intensive techniques, this hands-on guide shows you how to transform noisy market data into reliable labels that mirror real-world trading conditions.
preview
MQL5 Wizard Techniques you should know (Part 79): Using Gator Oscillator and Accumulation/Distribution Oscillator with Supervised Learning

MQL5 Wizard Techniques you should know (Part 79): Using Gator Oscillator and Accumulation/Distribution Oscillator with Supervised Learning

In the last piece, we concluded our look at the pairing of the gator oscillator and the accumulation/distribution oscillator when used in their typical setting of the raw signals they generate. These two indicators are complimentary as trend and volume indicators, respectively. We now follow up that piece, by examining the effect that supervised learning can have on enhancing some of the feature patterns we had reviewed. Our supervised learning approach is a CNN that engages with kernel regression and dot product similarity to size its kernels and channels. As always, we do this in a custom signal class file that works with the MQL5 wizard to assemble an Expert Advisor.
preview
Price Action Analysis Toolkit Development (Part 37): Sentiment Tilt Meter

Price Action Analysis Toolkit Development (Part 37): Sentiment Tilt Meter

Market sentiment is one of the most overlooked yet powerful forces influencing price movement. While most traders rely on lagging indicators or guesswork, the Sentiment Tilt Meter (STM) EA transforms raw market data into clear, visual guidance, showing whether the market is leaning bullish, bearish, or staying neutral in real-time. This makes it easier to confirm trades, avoid false entries, and time market participation more effectively.
preview
CRUD Operations in Firebase using MQL

CRUD Operations in Firebase using MQL

This article offers a step-by-step guide to mastering CRUD (Create, Read, Update, Delete) operations in Firebase, focusing on its Realtime Database and Firestore. Discover how to use Firebase SDK methods to efficiently manage data in web and mobile apps, from adding new records to querying, modifying, and deleting entries. Explore practical code examples and best practices for structuring and handling data in real-time, empowering developers to build dynamic, scalable applications with Firebase’s flexible NoSQL architecture.
preview
From Basic to Intermediate: Template and Typename (III)

From Basic to Intermediate: Template and Typename (III)

In this article, we will discuss the first part of the topic, which is not so easy for beginners to understand. In order not to get even more confused and to explain this topic correctly, we will divide the explanation into stages. We will devote this article to the first stage. However, although at the end of the article it may seem that we have reached the deadlock, in fact we will take a step towards another situation, which will be better understood in the next article.
preview
Automating Trading Strategies in MQL5 (Part 27): Creating a Price Action Crab Harmonic Pattern with Visual Feedback

Automating Trading Strategies in MQL5 (Part 27): Creating a Price Action Crab Harmonic Pattern with Visual Feedback

In this article, we develop a Crab Harmonic Pattern system in MQL5 that identifies bullish and bearish Crab harmonic patterns using pivot points and Fibonacci ratios, triggering trades with precise entry, stop loss, and take-profit levels. We incorporate visual feedback through chart objects like triangles and trendlines to display the XABCD pattern structure and trade levels.
preview
From Basic to Intermediate: Template and Typename (II)

From Basic to Intermediate: Template and Typename (II)

This article explains how to deal with one of the most difficult programming situations you can encounter: using different types in the same function or procedure template. Although we have spent most of our time focusing only on functions, everything covered here is useful and can be applied to procedures.
preview
Self Optimizing Expert Advisors in MQL5 (Part 12): Building Linear Classifiers Using Matrix Factorization

Self Optimizing Expert Advisors in MQL5 (Part 12): Building Linear Classifiers Using Matrix Factorization

This article explores the powerful role of matrix factorization in algorithmic trading, specifically within MQL5 applications. From regression models to multi-target classifiers, we walk through practical examples that demonstrate how easily these techniques can be integrated using built-in MQL5 functions. Whether you're predicting price direction or modeling indicator behavior, this guide lays a strong foundation for building intelligent trading systems using matrix methods.
preview
Automating Trading Strategies in MQL5 (Part 26): Building a Pin Bar Averaging System for Multi-Position Trading

Automating Trading Strategies in MQL5 (Part 26): Building a Pin Bar Averaging System for Multi-Position Trading

In this article, we develop a Pin Bar Averaging system in MQL5 that detects pin bar patterns to initiate trades and employs an averaging strategy for multi-position management, enhanced by trailing stops and breakeven adjustments. We incorporate customizable parameters with a dashboard for real-time monitoring of positions and profits.
preview
From Basic to Intermediate: Template and Typename (I)

From Basic to Intermediate: Template and Typename (I)

In this article, we start considering one of the concepts that many beginners avoid. This is related to the fact that templates are not an easy topic, as many do not understand the basic principle underlying the template: overload of functions and procedures.
preview
From Basic to Intermediate: Floating point

From Basic to Intermediate: Floating point

This article is a brief introduction to the concept of floating-point numbers. Since this text is very complex please, read it attentively and carefully. Do not expect to quickly master the floating-point system. It only becomes clear over time, as you gain experience using it. But this article will help you understand why your application sometimes produces results different from what you expect.
preview
From Basic to Intermediate: Overload

From Basic to Intermediate: Overload

Perhaps this article will be the most confusing for novice programmers. As a matter of fact, here I will show that it is not always that all functions and procedures have unique names in the same code. Yes, we can easily use functions and procedures with the same name — and this is called overload.
preview
From Basic to Intermediate: Definitions (II)

From Basic to Intermediate: Definitions (II)

In this article, we will continue our awareness of #define directive, but this time we will focus on its second form of use, that is, creating macros. Since this subject can be a bit complicated, we decided to use an application that we have been studying for some time. I hope you enjoy today's article.
preview
Parafrac Oscillator: Combination of Parabolic and Fractal Indicator

Parafrac Oscillator: Combination of Parabolic and Fractal Indicator

We will explore how the Parabolic SAR and the Fractal indicator can be combined to create a new oscillator-based indicator. By integrating the unique strengths of both tools, traders can aim at developing a more refined and effective trading strategy.
preview
Neural Networks in Trading: Parameter-Efficient Transformer with Segmented Attention (Final Part)

Neural Networks in Trading: Parameter-Efficient Transformer with Segmented Attention (Final Part)

In the previous work, we discussed the theoretical aspects of the PSformer framework, which includes two major innovations in the classical Transformer architecture: the Parameter Shared (PS) mechanism and attention to spatio-temporal segments (SegAtt). In this article, we continue the work we started on implementing the proposed approaches using MQL5.