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
Data Science and ML (Part 44): Forex OHLC Time series Forecasting using Vector Autoregression (VAR)

Data Science and ML (Part 44): Forex OHLC Time series Forecasting using Vector Autoregression (VAR)

Explore how Vector Autoregression (VAR) models can forecast Forex OHLC (Open, High, Low, and Close) time series data. This article covers VAR implementation, model training, and real-time forecasting in MetaTrader 5, helping traders analyze interdependent currency movements and improve their trading strategies.
preview
Price Action Analysis Toolkit Development (Part 28): Opening Range Breakout Tool

Price Action Analysis Toolkit Development (Part 28): Opening Range Breakout Tool

At the start of each trading session, the market’s directional bias often becomes clear only after price moves beyond the opening range. In this article, we explore how to build an MQL5 Expert Advisor that automatically detects and analyzes Opening Range Breakouts, providing you with timely, data‑driven signals for confident intraday entries.
preview
From Novice to Expert: Animated News Headline Using MQL5 (II)

From Novice to Expert: Animated News Headline Using MQL5 (II)

Today, we take another step forward by integrating an external news API as the source of headlines for our News Headline EA. In this phase, we’ll explore various news sources—both established and emerging—and learn how to access their APIs effectively. We'll also cover methods for parsing the retrieved data into a format optimized for display within our Expert Advisor. Join the discussion as we explore the benefits of accessing news headlines and the economic calendar directly on the chart, all within a compact, non-intrusive interface.
preview
MQL5 Wizard Techniques you should know (Part 71): Using Patterns of MACD and the OBV

MQL5 Wizard Techniques you should know (Part 71): Using Patterns of MACD and the OBV

The Moving-Average-Convergence-Divergence (MACD) oscillator and the On-Balance-Volume (OBV) oscillator are another pair of indicators that could be used in conjunction within an MQL5 Expert Advisor. This pairing, as is practice in these article series, is complementary with the MACD affirming trends while OBV checks volume. As usual, we use the MQL5 wizard to build and test any potential these two may possess.
preview
Training a multilayer perceptron using the Levenberg-Marquardt algorithm

Training a multilayer perceptron using the Levenberg-Marquardt algorithm

The article presents an implementation of the Levenberg-Marquardt algorithm for training feedforward neural networks. A comparative analysis of performance with algorithms from the scikit-learn Python library has been conducted. Simpler learning methods, such as gradient descent, gradient descent with momentum, and stochastic gradient descent are preliminarily discussed.
preview
Data Science and ML (Part 43): Hidden Patterns Detection in Indicators Data Using Latent Gaussian Mixture Models (LGMM)

Data Science and ML (Part 43): Hidden Patterns Detection in Indicators Data Using Latent Gaussian Mixture Models (LGMM)

Have you ever looked at the chart and felt that strange sensation… that there’s a pattern hidden just beneath the surface? A secret code that might reveal where prices are headed if only you could crack it? Meet LGMM, the Market’s Hidden Pattern Detector. A machine learning model that helps identify those hidden patterns in the market.
preview
Analyzing weather impact on currencies of agricultural countries using Python

Analyzing weather impact on currencies of agricultural countries using Python

What is the relationship between weather and Forex? Classical economic theory has long ignored the influence of such factors as weather on market behavior. But everything has changed. Let's try to find connections between the weather conditions and the position of agricultural currencies on the market.
preview
Neural Networks in Trading: Directional Diffusion Models (DDM)

Neural Networks in Trading: Directional Diffusion Models (DDM)

In this article, we discuss Directional Diffusion Models that exploit data-dependent anisotropic and directed noise in a forward diffusion process to capture meaningful graph representations.
preview
Reimagining Classic Strategies (Part 13): Taking Our Crossover Strategy to New Dimensions (Part 2)

Reimagining Classic Strategies (Part 13): Taking Our Crossover Strategy to New Dimensions (Part 2)

Join us in our discussion as we look for additional improvements to make to our moving-average cross over strategy to reduce the lag in our trading strategy to more reliable levels by leveraging our skills in data science. It is a well-studied fact that projecting your data to higher dimensions can at times improve the performance of your machine learning models. We will demonstrate what this practically means for you as a trader, and illustrate how you can weaponize this powerful principle using your MetaTrader 5 Terminal.
preview
Mastering Log Records (Part 8): Error Records That Translate Themselves

Mastering Log Records (Part 8): Error Records That Translate Themselves

In this eighth installment of the Mastering Log Records series, we explore the implementation of multilingual error messages in Logify, a powerful logging library for MQL5. You’ll learn how to structure errors with context, translate messages into multiple languages, and dynamically format logs by severity level. All of this with a clean, extensible, and production-ready design.
preview
From Novice to Expert: Animated News Headline Using MQL5 (I)

From Novice to Expert: Animated News Headline Using MQL5 (I)

News accessibility is a critical factor when trading on the MetaTrader 5 terminal. While numerous news APIs are available, many traders face challenges in accessing and integrating them effectively into their trading environment. In this discussion, we aim to develop a streamlined solution that brings news directly onto the chart—where it’s most needed. We'll accomplish this by building a News Headline Expert Advisor that monitors and displays real-time news updates from API sources.
preview
MQL5 Wizard Techniques you should know (Part 70):  Using Patterns of SAR and the RVI with a Exponential Kernel Network

MQL5 Wizard Techniques you should know (Part 70): Using Patterns of SAR and the RVI with a Exponential Kernel Network

We follow up our last article, where we introduced the indicator pair of the SAR and the RVI, by considering how this indicator pairing could be extended with Machine Learning. SAR and RVI are a trend and momentum complimentary pairing. Our machine learning approach uses a convolution neural network that engages the Exponential kernel in sizing its kernels and channels, when fine-tuning the forecasts of this indicator pairing. As always, this is done in a custom signal class file that works with the MQL5 wizard to assemble an Expert Advisor.
preview
From Basic to Intermediate: Array (IV)

From Basic to Intermediate: Array (IV)

In this article, we'll look at how you can do something very similar to what's implemented in languages like C, C++, and Java. I am talking about passing a virtually infinite number of parameters inside a function or procedure. While this may seem like a fairly advanced topic, in my opinion, what will be shown here can be easily implemented by anyone who has understood the previous concepts. Provided that they were really properly understood.
preview
Developing a Replay System (Part 72): An Unusual Communication (I)

Developing a Replay System (Part 72): An Unusual Communication (I)

What we create today will be difficult to understand. Therefore, in this article I will only talk about the initial stage. Please read this article carefully, it is an important prerequisite before we proceed to the next step. The purpose of this material is purely didactic as we will only study and master the presented concepts, without practical application.
preview
Build Self Optimizing Expert Advisors in MQL5 (Part 8): Multiple Strategy Analysis

Build Self Optimizing Expert Advisors in MQL5 (Part 8): Multiple Strategy Analysis

How best can we combine multiple strategies to create a powerful ensemble strategy? Join us in this discussion as we look to fit together three different strategies into our trading application. Traders often employ specialized strategies for opening and closing positions, and we want to know if our machines can perform this task better. For our opening discussion, we will get familiar with the faculties of the strategy tester and the principles of OOP we will need for this task.
preview
Creating a Trading Administrator Panel in MQL5 (Part XII): Integration of a Forex Values Calculator

Creating a Trading Administrator Panel in MQL5 (Part XII): Integration of a Forex Values Calculator

Accurate calculation of key trading values is an indispensable part of every trader’s workflow. In this article, we will discuss, the integration of a powerful utility—the Forex Calculator—into the Trade Management Panel, further extending the functionality of our multi-panel Trading Administrator system. Efficiently determining risk, position size, and potential profit is essential when placing trades, and this new feature is designed to make that process faster and more intuitive within the panel. Join us as we explore the practical application of MQL5 in building advanced, trading panels.
preview
Neural Networks in Trading: Node-Adaptive Graph Representation with NAFS

Neural Networks in Trading: Node-Adaptive Graph Representation with NAFS

We invite you to get acquainted with the NAFS (Node-Adaptive Feature Smoothing) method, which is a non-parametric approach to creating node representations that does not require parameter training. NAFS extracts features of each node given its neighbors and then adaptively combines these features to form a final representation.
preview
SQLite capabilities in MQL5: Example of a dashboard with trading statistics by symbols and magic numbers

SQLite capabilities in MQL5: Example of a dashboard with trading statistics by symbols and magic numbers

In this article, we will consider creating an indicator that displays trading statistics on a dashboard by account and by symbols and trading strategies. We will implement the code based on examples from the Documentation and the article on working with databases.
preview
MQL5 Wizard Techniques you should know (Part 69): Using Patterns of SAR and the RVI

MQL5 Wizard Techniques you should know (Part 69): Using Patterns of SAR and the RVI

The Parabolic-SAR (SAR) and the Relative Vigour Index (RVI) are another pair of indicators that could be used in conjunction within an MQL5 Expert Advisor. This indicator pair, like those we’ve covered in the past, is also complementary since SAR defines the trend while RVI checks momentum. As usual, we use the MQL5 wizard to build and test any potential this indicator pairing may have.
preview
Price Action Analysis Toolkit Development (Part 27): Liquidity Sweep With MA Filter Tool

Price Action Analysis Toolkit Development (Part 27): Liquidity Sweep With MA Filter Tool

Understanding the subtle dynamics behind price movements can give you a critical edge. One such phenomenon is the liquidity sweep, a deliberate strategy that large traders, especially institutions, use to push prices through key support or resistance levels. These levels often coincide with clusters of retail stop-loss orders, creating pockets of liquidity that big players can exploit to enter or exit sizeable positions with minimal slippage.
preview
Neural Networks in Trading: Contrastive Pattern Transformer (Final Part)

Neural Networks in Trading: Contrastive Pattern Transformer (Final Part)

In the previous last article within this series, we looked at the Atom-Motif Contrastive Transformer (AMCT) framework, which uses contrastive learning to discover key patterns at all levels, from basic elements to complex structures. In this article, we continue implementing AMCT approaches using MQL5.
preview
ALGLIB library optimization methods (Part II)

ALGLIB library optimization methods (Part II)

In this article, we will continue to study the remaining optimization methods from the ALGLIB library, paying special attention to their testing on complex multidimensional functions. This will allow us not only to evaluate the efficiency of each algorithm, but also to identify their strengths and weaknesses in different conditions.
preview
Price Action Analysis Toolkit Development (Part 26): Pin Bar, Engulfing Patterns and RSI Divergence (Multi-Pattern) Tool

Price Action Analysis Toolkit Development (Part 26): Pin Bar, Engulfing Patterns and RSI Divergence (Multi-Pattern) Tool

Aligned with our goal of developing practical price-action tools, this article explores the creation of an EA that detects pin bar and engulfing patterns, using RSI divergence as a confirmation trigger before generating any trading signals.
preview
Automating Trading Strategies in MQL5 (Part 19): Envelopes Trend Bounce Scalping — Trade Execution and Risk Management (Part II)

Automating Trading Strategies in MQL5 (Part 19): Envelopes Trend Bounce Scalping — Trade Execution and Risk Management (Part II)

In this article, we implement trade execution and risk management for the Envelopes Trend Bounce Scalping Strategy in MQL5. We implement order placement and risk controls like stop-loss and position sizing. We conclude with backtesting and optimization, building on Part 18’s foundation.
preview
MQL5 Wizard Techniques you should know (Part 68):  Using Patterns of TRIX and the Williams Percent Range with a Cosine Kernel Network

MQL5 Wizard Techniques you should know (Part 68): Using Patterns of TRIX and the Williams Percent Range with a Cosine Kernel Network

We follow up our last article, where we introduced the indicator pair of TRIX and Williams Percent Range, by considering how this indicator pairing could be extended with Machine Learning. TRIX and William’s Percent are a trend and support/ resistance complimentary pairing. Our machine learning approach uses a convolution neural network that engages the cosine kernel in its architecture when fine-tuning the forecasts of this indicator pairing. As always, this is done in a custom signal class file that works with the MQL5 wizard to assemble an Expert Advisor.
preview
Developing a Replay System (Part 71): Getting the Time Right (IV)

Developing a Replay System (Part 71): Getting the Time Right (IV)

In this article, we will look at how to implement what was shown in the previous article related to our replay/simulation service. As in many other things in life, problems are bound to arise. And this case was no exception. In this article, we continue to improve things. 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
Data Science and ML (Part 42): Forex Time series Forecasting using ARIMA in Python, Everything you need to Know

Data Science and ML (Part 42): Forex Time series Forecasting using ARIMA in Python, Everything you need to Know

ARIMA, short for Auto Regressive Integrated Moving Average, is a powerful traditional time series forecasting model. With the ability to detect spikes and fluctuations in a time series data, this model can make accurate predictions on the next values. In this article, we are going to understand what is it, how it operates, what you can do with it when it comes to predicting the next prices in the market with high accuracy and much more.
preview
Introduction to MQL5 (Part 17): Building Expert Advisors Using Technical Chart Patterns (II)

Introduction to MQL5 (Part 17): Building Expert Advisors Using Technical Chart Patterns (II)

This article teaches beginners how to build an Expert Advisor (EA) in MQL5 that trades based on chart pattern recognition using trend line breakouts and reversals. By learning how to retrieve trend line values dynamically and compare them with price action, readers will be able to develop EAs capable of identifying and trading chart patterns such as ascending and descending trend lines, channels, wedges, triangles, and more.
preview
MQL5 Trading Tools (Part 3): Building a Multi-Timeframe Scanner Dashboard for Strategic Trading

MQL5 Trading Tools (Part 3): Building a Multi-Timeframe Scanner Dashboard for Strategic Trading

In this article, we build a multi-timeframe scanner dashboard in MQL5 to display real-time trading signals. We plan an interactive grid interface, implement signal calculations with multiple indicators, and add a close button. The article concludes with backtesting and strategic trading benefits
preview
Neural Networks in Trading: Contrastive Pattern Transformer

Neural Networks in Trading: Contrastive Pattern Transformer

The Contrastive Transformer is designed to analyze markets both at the level of individual candlesticks and based on entire patterns. This helps improve the quality of market trend modeling. Moreover, the use of contrastive learning to align representations of candlesticks and patterns fosters self-regulation and improves the accuracy of forecasts.
preview
Price Action Analysis Toolkit Development (Part 25): Dual EMA Fractal Breaker

Price Action Analysis Toolkit Development (Part 25): Dual EMA Fractal Breaker

Price action is a fundamental approach for identifying profitable trading setups. However, manually monitoring price movements and patterns can be challenging and time-consuming. To address this, we are developing tools that analyze price action automatically, providing timely signals whenever potential opportunities are detected. This article introduces a robust tool that leverages fractal breakouts alongside EMA 14 and EMA 200 to generate reliable trading signals, helping traders make informed decisions with greater confidence.
preview
From Basic to Intermediate: Array (III)

From Basic to Intermediate: Array (III)

In this article, we will look at how to work with arrays in MQL5, including how to pass information between functions and procedures using arrays. The purpose is to prepare you for what will be demonstrated and explained in future materials in the series. Therefore, I strongly recommend that you carefully study what will be shown in this article.
preview
ALGLIB library optimization methods (Part I)

ALGLIB library optimization methods (Part I)

In this article, we will get acquainted with the ALGLIB library optimization methods for MQL5. The article includes simple and clear examples of using ALGLIB to solve optimization problems, which will make mastering the methods as accessible as possible. We will take a detailed look at the connection of such algorithms as BLEIC, L-BFGS and NS, and use them to solve a simple test problem.
preview
Automating Trading Strategies in MQL5 (Part 18): Envelopes Trend Bounce Scalping - Core Infrastructure and Signal Generation (Part I)

Automating Trading Strategies in MQL5 (Part 18): Envelopes Trend Bounce Scalping - Core Infrastructure and Signal Generation (Part I)

In this article, we build the core infrastructure for the Envelopes Trend Bounce Scalping Expert Advisor in MQL5. We initialize envelopes and other indicators for signal generation. We set up backtesting to prepare for trade execution in the next part.
preview
Neural Networks in Trading: Market Analysis Using a Pattern Transformer

Neural Networks in Trading: Market Analysis Using a Pattern Transformer

When we use models to analyze the market situation, we mainly focus on the candlestick. However, it has long been known that candlestick patterns can help in predicting future price movements. In this article, we will get acquainted with a method that allows us to integrate both of these approaches.
preview
Developing a multi-currency Expert Advisor (Part 19): Creating stages implemented in Python

Developing a multi-currency Expert Advisor (Part 19): Creating stages implemented in Python

So far we have considered the automation of launching sequential procedures for optimizing EAs exclusively in the standard strategy tester. But what if we would like to perform some handling of the obtained data using other means between such launches? We will attempt to add the ability to create new optimization stages performed by programs written in Python.
preview
Build Self Optimizing Expert Advisors in MQL5 (Part 7): Trading With Multiple Periods At Once

Build Self Optimizing Expert Advisors in MQL5 (Part 7): Trading With Multiple Periods At Once

In this series of articles, we have considered multiple different ways of identifying the best period to use our technical indicators with. Today, we shall demonstrate to the reader how they can instead perform the opposite logic, that is to say, instead of picking the single best period to use, we will demonstrate to the reader how to employ all available periods effectively. This approach reduces the amount of data discarded, and offers alternative use cases for machine learning algorithms beyond ordinary price prediction.
preview
Mastering Log Records (Part 7): How to Show Logs on Chart

Mastering Log Records (Part 7): How to Show Logs on Chart

Learn how to display logs directly on the MetaTrader chart in an organized way, with frames, titles and automatic scrolling. In this article, we show you how to create a visual log system using MQL5, ideal for monitoring what your robot is doing in real time.
preview
MQL5 Wizard Techniques you should know (Part 67): Using Patterns of TRIX and the Williams Percent Range

MQL5 Wizard Techniques you should know (Part 67): Using Patterns of TRIX and the Williams Percent Range

The Triple Exponential Moving Average Oscillator (TRIX) and the Williams Percentage Range Oscillator are another pair of indicators that could be used in conjunction within an MQL5 Expert Advisor. This indicator pair, like those we’ve covered recently, is also complementary given that TRIX defines the trend while Williams Percent Range affirms support and Resistance levels. As always, we use the MQL5 wizard to prototype any potential these two may have.
preview
Developing a Replay System (Part 70): Getting the Time Right (III)

Developing a Replay System (Part 70): Getting the Time Right (III)

In this article, we will look at how to use the CustomBookAdd function correctly and effectively. Despite its apparent simplicity, it has many nuances. For example, it allows you to tell the mouse indicator whether a custom symbol is on auction, being traded, or the market is closed. 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.