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
The case for using Hospital-Performance Data with Perceptrons, this Q4, in weighing SPDR XLV's next Performance

The case for using Hospital-Performance Data with Perceptrons, this Q4, in weighing SPDR XLV's next Performance

XLV is SPDR healthcare ETF and in an age where it is common to be bombarded by a wide array of traditional news items plus social media feeds, it can be pressing to select a data set for use with a model. We try to tackle this problem for this ETF by sizing up some of its critical data sets in MQL5.
preview
Developing a Replay System (Part 65): Playing the service (VI)

Developing a Replay System (Part 65): Playing the service (VI)

In this article, we will look at how to implement and solve the mouse pointer issue when using it in conjunction with a replay/simulation application. 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
From Novice to Expert: Programming Candlesticks

From Novice to Expert: Programming Candlesticks

In this article, we take the first step in MQL5 programming, even for complete beginners. We'll show you how to transform familiar candlestick patterns into a fully functional custom indicator. Candlestick patterns are valuable as they reflect real price action and signal market shifts. Instead of manually scanning charts—an approach prone to errors and inefficiencies—we'll discuss how to automate the process with an indicator that identifies and labels patterns for you. Along the way, we’ll explore key concepts like indexing, time series, Average True Range (for accuracy in varying market volatility), and the development of a custom reusable Candlestick Pattern library for use in future projects.
preview
Client in Connexus (Part 7): Adding the Client Layer

Client in Connexus (Part 7): Adding the Client Layer

In this article we continue the development of the connexus library. In this chapter we build the CHttpClient class responsible for sending a request and receiving an order. We also cover the concept of mocks, leaving the library decoupled from the WebRequest function, which allows greater flexibility for users.
preview
Neural Networks in Trading: Reducing Memory Consumption with Adam-mini Optimization

Neural Networks in Trading: Reducing Memory Consumption with Adam-mini Optimization

One of the directions for increasing the efficiency of the model training and convergence process is the improvement of optimization methods. Adam-mini is an adaptive optimization method designed to improve on the basic Adam algorithm.
preview
Neural networks made easy (Part 77): Cross-Covariance Transformer (XCiT)

Neural networks made easy (Part 77): Cross-Covariance Transformer (XCiT)

In our models, we often use various attention algorithms. And, probably, most often we use Transformers. Their main disadvantage is the resource requirement. In this article, we will consider a new algorithm that can help reduce computing costs without losing quality.
preview
Non-stationary processes and spurious regression

Non-stationary processes and spurious regression

The article demonstrates spurious regression occurring when attempting to apply regression analysis to non-stationary processes using Monte Carlo simulation.
preview
Example of Causality Network Analysis (CNA) and Vector Auto-Regression Model for Market Event Prediction

Example of Causality Network Analysis (CNA) and Vector Auto-Regression Model for Market Event Prediction

This article presents a comprehensive guide to implementing a sophisticated trading system using Causality Network Analysis (CNA) and Vector Autoregression (VAR) in MQL5. It covers the theoretical background of these methods, provides detailed explanations of key functions in the trading algorithm, and includes example code for implementation.
preview
A feature selection algorithm using energy based learning in pure MQL5

A feature selection algorithm using energy based learning in pure MQL5

In this article we present the implementation of a feature selection algorithm described in an academic paper titled,"FREL: A stable feature selection algorithm", called Feature weighting as regularized energy based learning.
preview
Building a Custom Market Regime Detection System in MQL5 (Part 1): Indicator

Building a Custom Market Regime Detection System in MQL5 (Part 1): Indicator

This article details creating an MQL5 Market Regime Detection System using statistical methods like autocorrelation and volatility. It provides code for classes to classify trending, ranging, and volatile conditions and a custom indicator.
preview
Multiple Symbol Analysis With Python And MQL5 (Part II): Principal Components Analysis For Portfolio Optimization

Multiple Symbol Analysis With Python And MQL5 (Part II): Principal Components Analysis For Portfolio Optimization

Managing trading account risk is a challenge for all traders. How can we develop trading applications that dynamically learn high, medium, and low-risk modes for various symbols in MetaTrader 5? By using PCA, we gain better control over portfolio variance. I’ll demonstrate how to create applications that learn these three risk modes from market data fetched from MetaTrader 5.
preview
Developing a Replay System (Part 35): Making Adjustments (I)

Developing a Replay System (Part 35): Making Adjustments (I)

Before we can move forward, we need to fix a few things. These are not actually the necessary fixes but rather improvements to the way the class is managed and used. The reason is that failures occurred due to some interaction within the system. Despite attempts to find out the cause of such failures in order to eliminate them, all these attempts were unsuccessful. Some of these cases make no sense, for example, when we use pointers or recursion in C/C++, the program crashes.
preview
Integrating MQL5 with data processing packages (Part 3): Enhanced Data Visualization

Integrating MQL5 with data processing packages (Part 3): Enhanced Data Visualization

In this article, we will perform Enhanced Data Visualization by going beyond basic charts by incorporating features like interactivity, layered data, and dynamic elements, enabling traders to explore trends, patterns, and correlations more effectively.
preview
Developing a Replay System (Part 45): Chart Trade Project (IV)

Developing a Replay System (Part 45): Chart Trade Project (IV)

The main purpose of this article is to introduce and explain the C_ChartFloatingRAD class. We have a Chart Trade indicator that works in a rather interesting way. As you may have noticed, we still have a fairly small number of objects on the chart, and yet we get the expected functionality. The values present in the indicator can be edited. The question is, how is this possible? This article will start to make things clearer.
preview
Reimagining Classic Strategies in MQL5 (Part II): FTSE100 and UK Gilts

Reimagining Classic Strategies in MQL5 (Part II): FTSE100 and UK Gilts

In this series of articles, we explore popular trading strategies and try to improve them using AI. In today's article, we revisit the classical trading strategy built on the relationship between the stock market and the bond market.
preview
Two-sample Kolmogorov-Smirnov test as an indicator of time series non-stationarity

Two-sample Kolmogorov-Smirnov test as an indicator of time series non-stationarity

The article considers one of the most famous non-parametric homogeneity tests – the two-sample Kolmogorov-Smirnov test. Both model data and real quotes are analyzed. The article also provides an example of constructing a non-stationarity indicator (iSmirnovDistance).
preview
MQL5 Wizard Techniques you should know (Part 45): Reinforcement Learning with Monte-Carlo

MQL5 Wizard Techniques you should know (Part 45): Reinforcement Learning with Monte-Carlo

Monte-Carlo is the fourth different algorithm in reinforcement learning that we are considering with the aim of exploring its implementation in wizard assembled Expert Advisors. Though anchored in random sampling, it does present vast ways of simulation which we can look to exploit.
preview
Developing a Replay System (Part 57): Understanding a Test Service

Developing a Replay System (Part 57): Understanding a Test Service

One point to note: although the service code is not included in this article and will only be provided in the next one, I'll explain it since we'll be using that same code as a springboard for what we're actually developing. So, be attentive and patient. Wait for the next article, because every day everything becomes more interesting.
preview
Neural networks made easy (Part 69): Density-based support constraint for the behavioral policy (SPOT)

Neural networks made easy (Part 69): Density-based support constraint for the behavioral policy (SPOT)

In offline learning, we use a fixed dataset, which limits the coverage of environmental diversity. During the learning process, our Agent can generate actions beyond this dataset. If there is no feedback from the environment, how can we be sure that the assessments of such actions are correct? Maintaining the Agent's policy within the training dataset becomes an important aspect to ensure the reliability of training. This is what we will talk about in this article.
preview
MQL5 Wizard Techniques you should know (Part 23): CNNs

MQL5 Wizard Techniques you should know (Part 23): CNNs

Convolutional Neural Networks are another machine learning algorithm that tend to specialize in decomposing multi-dimensioned data sets into key constituent parts. We look at how this is typically achieved and explore a possible application for traders in another MQL5 wizard signal class.
preview
Redefining MQL5 and MetaTrader 5 Indicators

Redefining MQL5 and MetaTrader 5 Indicators

An innovative approach to collecting indicator information in MQL5 enables more flexible and streamlined data analysis by allowing developers to pass custom inputs to indicators for immediate calculations. This approach is particularly useful for algorithmic trading, as it provides enhanced control over the information processed by indicators, moving beyond traditional constraints.
preview
Developing a Replay System (Part 64): Playing the service (V)

Developing a Replay System (Part 64): Playing the service (V)

In this article, we will look at how to fix two errors in the code. However, I will try to explain them in a way that will help you, beginner programmers, understand that things don't always go as you expect. Anyway, this is an opportunity to learn. The content presented here is intended solely for educational purposes. In no way should this application be considered as a final document with any purpose other than to explore the concepts presented.
preview
Adaptive Social Behavior Optimization (ASBO): Two-phase evolution

Adaptive Social Behavior Optimization (ASBO): Two-phase evolution

We continue dwelling on the topic of social behavior of living organisms and its impact on the development of a new mathematical model - ASBO (Adaptive Social Behavior Optimization). We will dive into the two-phase evolution, test the algorithm and draw conclusions. Just as in nature a group of living organisms join their efforts to survive, ASBO uses principles of collective behavior to solve complex optimization problems.
preview
Statistical Arbitrage Through Mean Reversion in Pairs Trading: Beating the Market by Math

Statistical Arbitrage Through Mean Reversion in Pairs Trading: Beating the Market by Math

This article describes the fundamentals of portfolio-level statistical arbitrage. Its goal is to facilitate the understanding of the principles of statistical arbitrage to readers without deep math knowledge and propose a starting point conceptual framework. The article includes a working Expert Advisor, some notes about its one-year backtest, and the respective backtest configuration settings (.ini file) for the reproduction of the experiment.
preview
MQL5 Wizard Techniques you should know (Part 52): Accelerator Oscillator

MQL5 Wizard Techniques you should know (Part 52): Accelerator Oscillator

The Accelerator Oscillator is another Bill Williams Indicator that tracks price momentum's acceleration and not just its pace. Although much like the Awesome oscillator we reviewed in a recent article, it seeks to avoid the lagging effects by focusing more on acceleration as opposed to just speed. We examine as always what patterns we can get from this and also what significance each could have in trading via a wizard assembled Expert Advisor.
preview
Eigenvectors and eigenvalues: Exploratory data analysis in MetaTrader 5

Eigenvectors and eigenvalues: Exploratory data analysis in MetaTrader 5

In this article we explore different ways in which the eigenvectors and eigenvalues can be applied in exploratory data analysis to reveal unique relationships in data.
preview
Developing a Replay System (Part 55): Control Module

Developing a Replay System (Part 55): Control Module

In this article, we will implement a control indicator so that it can be integrated into the message system we are developing. Although it is not very difficult, there are some details that need to be understood about the initialization of this module. The material presented here is for educational purposes only. In no way should it be considered as an application for any purpose other than learning and mastering the concepts shown.
preview
Creating a Trading Administrator Panel in MQL5 (Part VII): Trusted User, Recovery and Cryptography

Creating a Trading Administrator Panel in MQL5 (Part VII): Trusted User, Recovery and Cryptography

Security prompts, such as those triggered every time you refresh the chart, add a new pair to the chat with the Admin Panel EA, or restart the terminal, can become tedious. In this discussion, we will explore and implement a feature that tracks the number of login attempts to identify a trusted user. After a set number of failed attempts, the application will transition to an advanced login procedure, which also facilitates passcode recovery for users who may have forgotten it. Additionally, we will cover how cryptography can be effectively integrated into the Admin Panel to enhance security.
preview
Developing a Replay System (Part 34): Order System (III)

Developing a Replay System (Part 34): Order System (III)

In this article, we will complete the first phase of construction. Although this part is fairly quick to complete, I will cover details that were not discussed previously. I will explain some points that many do not understand. Do you know why you have to press the Shift or Ctrl key?
preview
Developing a Replay System (Part 39): Paving the Path (III)

Developing a Replay System (Part 39): Paving the Path (III)

Before we proceed to the second stage of development, we need to revise some ideas. Do you know how to make MQL5 do what you need? Have you ever tried to go beyond what is contained in the documentation? If not, then get ready. Because we will be doing something that most people don't normally do.
preview
Developing a Replay System (Part 60): Playing the Service (I)

Developing a Replay System (Part 60): Playing the Service (I)

We have been working on just the indicators for a long time now, but now it's time to get the service working again and see how the chart is built based on the data provided. However, since the whole thing is not that simple, we will have to be attentive to understand what awaits us ahead.
preview
Reimagining Classic Strategies (Part VII) : Forex Markets And Sovereign Debt Analysis on the USDJPY

Reimagining Classic Strategies (Part VII) : Forex Markets And Sovereign Debt Analysis on the USDJPY

In today's article, we will analyze the relationship between future exchange rates and government bonds. Bonds are among the most popular forms of fixed income securities and will be the focus of our discussion.Join us as we explore whether we can improve a classic strategy using AI.
preview
MQL5 Wizard Techniques you should know (Part 54): Reinforcement Learning with hybrid SAC and Tensors

MQL5 Wizard Techniques you should know (Part 54): Reinforcement Learning with hybrid SAC and Tensors

Soft Actor Critic is a Reinforcement Learning algorithm that we looked at in a previous article, where we also introduced python and ONNX to these series as efficient approaches to training networks. We revisit the algorithm with the aim of exploiting tensors, computational graphs that are often exploited in Python.
preview
Reimagining Classic Strategies (Part VIII): Currency Markets And Precious Metals on the USDCAD

Reimagining Classic Strategies (Part VIII): Currency Markets And Precious Metals on the USDCAD

In this series of articles, we revisit well-known trading strategies to see if we can improve them using AI. In today's discussion, join us as we test whether there is a reliable relationship between precious metals and currencies.
preview
Ensemble methods to enhance classification tasks in MQL5

Ensemble methods to enhance classification tasks in MQL5

In this article, we present the implementation of several ensemble classifiers in MQL5 and discuss their efficacy in varying situations.
preview
Developing a Replay System (Part 41): Starting the second phase (II)

Developing a Replay System (Part 41): Starting the second phase (II)

If everything seemed right to you up to this point, it means you're not really thinking about the long term, when you start developing applications. Over time you will no longer need to program new applications, you will just have to make them work together. So let's see how to finish assembling the mouse indicator.
preview
Gating mechanisms in ensemble learning

Gating mechanisms in ensemble learning

In this article, we continue our exploration of ensemble models by discussing the concept of gates, specifically how they may be useful in combining model outputs to enhance either prediction accuracy or model generalization.
preview
Exploring Cryptography in MQL5: A Step-by-Step Approach

Exploring Cryptography in MQL5: A Step-by-Step Approach

This article explores the integration of cryptography within MQL5, enhancing the security and functionality of trading algorithms. We’ll cover key cryptographic methods and their practical implementation in automated trading.
preview
Price Action Analysis Toolkit Development (Part 21): Market Structure Flip Detector Tool

Price Action Analysis Toolkit Development (Part 21): Market Structure Flip Detector Tool

The Market Structure Flip Detector Expert Advisor (EA) acts as your vigilant partner, constantly observing shifts in market sentiment. By utilizing Average True Range (ATR)-based thresholds, it effectively detects structure flips and labels each Higher Low and Lower High with clear indicators. Thanks to MQL5’s swift execution and flexible API, this tool offers real-time analysis that adjusts the display for optimal readability and provides a live dashboard to monitor flip counts and timings. Furthermore, customizable sound and push notifications guarantee that you stay informed of critical signals, allowing you to see how straightforward inputs and helper routines can transform price movements into actionable strategies.
preview
Advanced Memory Management and Optimization Techniques in MQL5

Advanced Memory Management and Optimization Techniques in MQL5

Discover practical techniques to optimize memory usage in MQL5 trading systems. Learn to build efficient, stable, and fast-performing Expert Advisors and indicators. We’ll explore how memory really works in MQL5, the common traps that slow your systems down or cause them to fail, and — most importantly — how to fix them.