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
Structures in MQL5 and methods for printing their data

Structures in MQL5 and methods for printing their data

In this article we will look at the MqlDateTime, MqlTick, MqlRates and MqlBookInfo strutures, as well as methods for printing data from them. In order to print all the fields of a structure, there is a standard ArrayPrint() function, which displays the data contained in the array with the type of the handled structure in a convenient tabular format.
preview
DoEasy. Controls (Part 10): WinForms objects — Animating the interface

DoEasy. Controls (Part 10): WinForms objects — Animating the interface

It is time to animate the graphical interface by implementing the functionality for object interaction with users and objects. The new functionality will also be necessary to let more complex objects work correctly.
preview
Neural networks made easy (Part 33): Quantile regression in distributed Q-learning

Neural networks made easy (Part 33): Quantile regression in distributed Q-learning

We continue studying distributed Q-learning. Today we will look at this approach from the other side. We will consider the possibility of using quantile regression to solve price prediction tasks.
preview
Ready-made templates for including indicators to Expert Advisors (Part 2): Volume and Bill Williams indicators

Ready-made templates for including indicators to Expert Advisors (Part 2): Volume and Bill Williams indicators

In this article, we will look at standard indicators of the Volume and Bill Williams' indicators category. We will create ready-to-use templates for indicator use in EAs - declaring and setting parameters, indicator initialization and deinitialization, as well as receiving data and signals from indicator buffers in EAs.
preview
Modified Grid-Hedge EA in MQL5 (Part I): Making a Simple Hedge EA

Modified Grid-Hedge EA in MQL5 (Part I): Making a Simple Hedge EA

We will be creating a simple hedge EA as a base for our more advanced Grid-Hedge EA, which will be a mixture of classic grid and classic hedge strategies. By the end of this article, you will know how to create a simple hedge strategy, and you will also get to know what people say about whether this strategy is truly 100% profitable.
preview
Population optimization algorithms: Fish School Search (FSS)

Population optimization algorithms: Fish School Search (FSS)

Fish School Search (FSS) is a new optimization algorithm inspired by the behavior of fish in a school, most of which (up to 80%) swim in an organized community of relatives. It has been proven that fish aggregations play an important role in the efficiency of foraging and protection from predators.
preview
How to connect MetaTrader 5 to PostgreSQL

How to connect MetaTrader 5 to PostgreSQL

This article describes four methods for connecting MQL5 code to a Postgres database and provides a step-by-step tutorial for setting up a development environment for one of them, a REST API, using the Windows Subsystem For Linux (WSL). A demo app for the API is provided along with the corresponding MQL5 code to insert data and query the respective tables, as well as a demo Expert Advisor to consume this data.
preview
Matrices and vectors in MQL5: Activation functions

Matrices and vectors in MQL5: Activation functions

Here we will describe only one of the aspects of machine learning - activation functions. In artificial neural networks, a neuron activation function calculates an output signal value based on the values of an input signal or a set of input signals. We will delve into the inner workings of the process.
preview
Understanding Programming Paradigms (Part 1): A Procedural Approach to Developing a Price Action Expert Advisor

Understanding Programming Paradigms (Part 1): A Procedural Approach to Developing a Price Action Expert Advisor

Learn about programming paradigms and their application in MQL5 code. This article explores the specifics of procedural programming, offering hands-on experience through a practical example. You'll learn how to develop a price action expert advisor using the EMA indicator and candlestick price data. Additionally, the article introduces you to the functional programming paradigm.
preview
Canvas based indicators: Filling channels with transparency

Canvas based indicators: Filling channels with transparency

In this article I'll introduce a method for creating custom indicators whose drawings are made using the class CCanvas from standard library and see charts properties for coordinates conversion. I'll approach specially indicators which need to fill the area between two lines using transparency.
preview
How to create a simple Multi-Currency Expert Advisor using MQL5 (Part 4): Triangular moving average — Indicator Signals

How to create a simple Multi-Currency Expert Advisor using MQL5 (Part 4): Triangular moving average — Indicator Signals

The Multi-Currency Expert Advisor in this article is Expert Advisor or trading robot that can trade (open orders, close orders and manage orders for example: Trailing Stop Loss and Trailing Profit) for more than one symbol pair only from one symbol chart. This time we will use only 1 indicator, namely Triangular moving average in multi-timeframes or single timeframe.
preview
Developing a Replay System — Market simulation (Part 15): Birth of the SIMULATOR (V) - RANDOM WALK

Developing a Replay System — Market simulation (Part 15): Birth of the SIMULATOR (V) - RANDOM WALK

In this article we will complete the development of a simulator for our system. The main goal here will be to configure the algorithm discussed in the previous article. This algorithm aims to create a RANDOM WALK movement. Therefore, to understand today's material, it is necessary to understand the content of previous articles. If you have not followed the development of the simulator, I advise you to read this sequence from the very beginning. Otherwise, you may get confused about what will be explained here.
preview
How to create a simple Multi-Currency Expert Advisor using MQL5 (Part 3): Added symbols prefixes and/or suffixes and Trading Time Session

How to create a simple Multi-Currency Expert Advisor using MQL5 (Part 3): Added symbols prefixes and/or suffixes and Trading Time Session

Several fellow traders sent emails or commented about how to use this Multi-Currency EA on brokers with symbol names that have prefixes and/or suffixes, and also how to implement trading time zones or trading time sessions on this Multi-Currency EA.
preview
DoEasy. Controls (Part 18): Functionality for scrolling tabs in TabControl

DoEasy. Controls (Part 18): Functionality for scrolling tabs in TabControl

In this article, I will place header scrolling control buttons in TabControl WinForms object in case the header bar does not fit the size of the control. Besides, I will implement the shift of the header bar when clicking on the cropped tab header.
preview
Brute force approach to patterns search (Part VI): Cyclic optimization

Brute force approach to patterns search (Part VI): Cyclic optimization

In this article I will show the first part of the improvements that allowed me not only to close the entire automation chain for MetaTrader 4 and 5 trading, but also to do something much more interesting. From now on, this solution allows me to fully automate both creating EAs and optimization, as well as to minimize labor costs for finding effective trading configurations.
preview
DoEasy. Controls (Part 20): SplitContainer WinForms object

DoEasy. Controls (Part 20): SplitContainer WinForms object

In the current article, I will start developing the SplitContainer control from the MS Visual Studio toolkit. This control consists of two panels separated by a vertical or horizontal movable separator.
Graphics in DoEasy library (Part 84): Descendant classes of the abstract standard graphical object
Graphics in DoEasy library (Part 84): Descendant classes of the abstract standard graphical object

Graphics in DoEasy library (Part 84): Descendant classes of the abstract standard graphical object

In this article, I will consider creation of descendant objects for the terminal abstract standard graphical object. The class object describes the properties that are common for all graphical objects. So, it is simply some kind of a graphical object. To clarify its affiliation with a real graphical object, we need to set the properties inherent in this particular graphical object in the descendant object class.
preview
Neural networks made easy (Part 56): Using nuclear norm to drive research

Neural networks made easy (Part 56): Using nuclear norm to drive research

The study of the environment in reinforcement learning is a pressing problem. We have already looked at some approaches previously. In this article, we will have a look at yet another method based on maximizing the nuclear norm. It allows agents to identify environmental states with a high degree of novelty and diversity.
preview
How to create a simple Multi-Currency Expert Advisor using MQL5 (Part 6): Two RSI indicators cross each other's lines

How to create a simple Multi-Currency Expert Advisor using MQL5 (Part 6): Two RSI indicators cross each other's lines

The multi-currency expert advisor in this article is an expert advisor or trading robot that uses two RSI indicators with crossing lines, the Fast RSI which crosses with the Slow RSI.
preview
Implementing the Janus factor in MQL5

Implementing the Janus factor in MQL5

Gary Anderson developed a method of market analysis based on a theory he dubbed the Janus Factor. The theory describes a set of indicators that can be used to reveal trends and assess market risk. In this article we will implement these tools in mql5.
preview
Experiments with neural networks (Part 3): Practical application

Experiments with neural networks (Part 3): Practical application

In this article series, I use experimentation and non-standard approaches to develop a profitable trading system and check whether neural networks can be of any help for traders. MetaTrader 5 is approached as a self-sufficient tool for using neural networks in trading.
preview
Neural networks made easy (Part 54): Using random encoder for efficient research (RE3)

Neural networks made easy (Part 54): Using random encoder for efficient research (RE3)

Whenever we consider reinforcement learning methods, we are faced with the issue of efficiently exploring the environment. Solving this issue often leads to complication of the algorithm and training of additional models. In this article, we will look at an alternative approach to solving this problem.
Tomasz Tauzowski:"All I can do is pray for a loss position" (ATC 2010)
Tomasz Tauzowski:"All I can do is pray for a loss position" (ATC 2010)

Tomasz Tauzowski:"All I can do is pray for a loss position" (ATC 2010)

Tomasz Tauzowski (ttauzo) is a long-standing member of the top ten on the Automated Trading Championship 2010. For the seventh week his Expert Advisor is between the fifth and the seventh places. And no wonder: according to the report of the current Championship leader Boris Odinstov, ttauzo is one of the most stable EAs participating in the competition.
preview
Developing a trading Expert Advisor from scratch (Part 14): Adding Volume At Price (II)

Developing a trading Expert Advisor from scratch (Part 14): Adding Volume At Price (II)

Today we will add some more resources to our EA. This interesting article can provide some new ideas and methods of presenting information. At the same time, it can assist in fixing minor flaws in your projects.
preview
DoEasy. Controls (Part 9): Re-arranging WinForms object methods, RadioButton and Button controls

DoEasy. Controls (Part 9): Re-arranging WinForms object methods, RadioButton and Button controls

In this article, I will fix the names of WinForms object class methods and create Button and RadioButton WinForms objects.
preview
Population optimization algorithms: Invasive Weed Optimization (IWO)

Population optimization algorithms: Invasive Weed Optimization (IWO)

The amazing ability of weeds to survive in a wide variety of conditions has become the idea for a powerful optimization algorithm. IWO is one of the best algorithms among the previously reviewed ones.
preview
Neural networks made easy (Part 37): Sparse Attention

Neural networks made easy (Part 37): Sparse Attention

In the previous article, we discussed relational models which use attention mechanisms in their architecture. One of the specific features of these models is the intensive utilization of computing resources. In this article, we will consider one of the mechanisms for reducing the number of computational operations inside the Self-Attention block. This will increase the general performance of the model.
Interview with Matúš German (ATC 2012)
Interview with Matúš German (ATC 2012)

Interview with Matúš German (ATC 2012)

It's the second time Matúš German participates in the Automated Trading Championship. By the end of the fourth week of ATC 2012 his Expert Advisor has been holding its positions in the TOP-10 having about $30 000. Matúš is from Slovakia, from the little town Bardejov. Matúš is interested in trading for about 5 years and he develops Expert Advisors for 3 years already.
preview
Timeseries in DoEasy library (part 51): Composite multi-period multi-symbol standard indicators

Timeseries in DoEasy library (part 51): Composite multi-period multi-symbol standard indicators

In the article, complete development of objects of multi-period multi-symbol standard indicators. Using Ichimoku Kinko Hyo standard indicator example, analyze creation of compound custom indicators which have auxiliary drawn buffers for displaying data on the chart.
preview
Population optimization algorithms: ElectroMagnetism-like algorithm (ЕМ)

Population optimization algorithms: ElectroMagnetism-like algorithm (ЕМ)

The article describes the principles, methods and possibilities of using the Electromagnetic Algorithm in various optimization problems. The EM algorithm is an efficient optimization tool capable of working with large amounts of data and multidimensional functions.
preview
Developing a trading Expert Advisor from scratch (Part 20): New order system (III)

Developing a trading Expert Advisor from scratch (Part 20): New order system (III)

We continue to implement the new order system. The creation of such a system requires a good command of MQL5, as well as an understanding of how the MetaTrader 5 platform actually works and what resources it provides.
preview
DRAKON visual programming language — communication tool for MQL developers and customers

DRAKON visual programming language — communication tool for MQL developers and customers

DRAKON is a visual programming language designed to simplify interaction between specialists from different fields (biologists, physicists, engineers...) with programmers in Russian space projects (for example, in the Buran reusable spacecraft project). In this article, I will talk about how DRAKON makes the creation of algorithms accessible and intuitive, even if you have never encountered code, and also how it is easier for customers to explain their thoughts when ordering trading robots, and for programmers to make fewer mistakes in complex functions.
preview
The price movement model and its main provisions. (Part 3): Calculating optimal parameters of stock exchange speculations

The price movement model and its main provisions. (Part 3): Calculating optimal parameters of stock exchange speculations

Within the framework of the engineering approach developed by the author based on the probability theory, the conditions for opening a profitable position are found and the optimal (profit-maximizing) take profit and stop loss values are calculated.
Graphics in DoEasy library (Part 92): Standard graphical object memory class. Object property change history
Graphics in DoEasy library (Part 92): Standard graphical object memory class. Object property change history

Graphics in DoEasy library (Part 92): Standard graphical object memory class. Object property change history

In the article, I will create the class of the standard graphical object memory allowing the object to save its states when its properties are modified. In turn, this allows retracting to the previous graphical object states.
preview
DoEasy. Controls (Part 8): Base WinForms objects by categories, GroupBox and CheckBox controls

DoEasy. Controls (Part 8): Base WinForms objects by categories, GroupBox and CheckBox controls

The article considers creation of 'GroupBox' and 'CheckBox' WinForms objects, as well as the development of base objects for WinForms object categories. All created objects are still static, i.e. they are unable to interact with the mouse.
preview
DoEasy. Controls (Part 4): Panel control, Padding and Dock parameters

DoEasy. Controls (Part 4): Panel control, Padding and Dock parameters

In this article, I will implement handling Padding (internal indents/margin on all sides of an element) and Dock parameters (the way an object is located inside its container).
preview
Population optimization algorithms: Shuffled Frog-Leaping algorithm (SFL)

Population optimization algorithms: Shuffled Frog-Leaping algorithm (SFL)

The article presents a detailed description of the shuffled frog-leaping (SFL) algorithm and its capabilities in solving optimization problems. The SFL algorithm is inspired by the behavior of frogs in their natural environment and offers a new approach to function optimization. The SFL algorithm is an efficient and flexible tool capable of processing a variety of data types and achieving optimal solutions.
preview
Filtering and feature extraction in the frequency domain

Filtering and feature extraction in the frequency domain

In this article we explore the application of digital filters on time series represented in the frequency domain so as to extract unique features that may be useful to prediction models.
preview
Category Theory in MQL5 (Part 8): Monoids

Category Theory in MQL5 (Part 8): Monoids

This article continues the series on category theory implementation in MQL5. Here we introduce monoids as domain (set) that sets category theory apart from other data classification methods by including rules and an identity element.
preview
Developing a trading Expert Advisor from scratch (Part 17): Accessing data on the web (III)

Developing a trading Expert Advisor from scratch (Part 17): Accessing data on the web (III)

In this article we continue considering how to obtain data from the web and to use it in an Expert Advisor. This time we will proceed to developing an alternative system.