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
Optimal approach to the development and analysis of trading systems
Optimal approach to the development and analysis of trading systems

Optimal approach to the development and analysis of trading systems

In this article, I will show the criteria to be used when selecting a system or a signal for investing your funds, as well as describe the optimal approach to the development of trading systems and highlight the importance of this matter in Forex trading.
preview
Timeseries in DoEasy library (part 57): Indicator buffer data object

Timeseries in DoEasy library (part 57): Indicator buffer data object

In the article, develop an object which will contain all data of one buffer for one indicator. Such objects will be necessary for storing serial data of indicator buffers. With their help, it will be possible to sort and compare buffer data of any indicators, as well as other similar data with each other.
preview
Timeseries in DoEasy library (part 56): Custom indicator object, get data from indicator objects in the collection

Timeseries in DoEasy library (part 56): Custom indicator object, get data from indicator objects in the collection

The article considers creation of the custom indicator object for the use in EAs. Let’s slightly improve library classes and add methods to get data from indicator objects in EAs.
preview
Practical application of neural networks in trading. Python (Part I)

Practical application of neural networks in trading. Python (Part I)

In this article, we will analyze the step-by-step implementation of a trading system based on the programming of deep neural networks in Python. This will be performed using the TensorFlow machine learning library developed by Google. We will also use the Keras library for describing neural networks.
preview
Neural networks made easy (Part 5): Multithreaded calculations in OpenCL

Neural networks made easy (Part 5): Multithreaded calculations in OpenCL

We have earlier discussed some types of neural network implementations. In the considered networks, the same operations are repeated for each neuron. A logical further step is to utilize multithreaded computing capabilities provided by modern technology in an effort to speed up the neural network learning process. One of the possible implementations is described in this article.
preview
Timeseries in DoEasy library (part 55): Indicator collection class

Timeseries in DoEasy library (part 55): Indicator collection class

The article continues developing indicator object classes and their collections. For each indicator object create its description and correct collection class for error-free storage and getting indicator objects from the collection list.
preview
Neural networks made easy (Part 4): Recurrent networks

Neural networks made easy (Part 4): Recurrent networks

We continue studying the world of neural networks. In this article, we will consider another type of neural networks, recurrent networks. This type is proposed for use with time series, which are represented in the MetaTrader 5 trading platform by price charts.
preview
Timeseries in DoEasy library (part 54): Descendant classes of abstract base indicator

Timeseries in DoEasy library (part 54): Descendant classes of abstract base indicator

The article considers creation of classes of descendant objects of base abstract indicator. Such objects will provide access to features of creating indicator EAs, collecting and getting data value statistics of various indicators and prices. Also, create indicator object collection from which getting access to properties and data of each indicator created in the program will be possible.
Grid and martingale: what are they and how to use them?
Grid and martingale: what are they and how to use them?

Grid and martingale: what are they and how to use them?

In this article, I will try to explain in detail what grid and martingale are, as well as what they have in common. Besides, I will try to analyze how viable these strategies really are. The article features mathematical and practical sections.
preview
Brute force approach to pattern search

Brute force approach to pattern search

In this article, we will search for market patterns, create Expert Advisors based on the identified patterns, and check how long these patterns remain valid, if they ever retain their validity.
preview
Timeseries in DoEasy library (part 53): Abstract base indicator class

Timeseries in DoEasy library (part 53): Abstract base indicator class

The article considers creation of an abstract indicator which further will be used as the base class to create objects of library’s standard and custom indicators.
preview
Timeseries in DoEasy library (part 52): Cross-platform nature of multi-period multi-symbol  single-buffer standard indicators

Timeseries in DoEasy library (part 52): Cross-platform nature of multi-period multi-symbol single-buffer standard indicators

In the article, consider creation of multi-symbol multi-period standard indicator Accumulation/Distribution. Slightly improve library classes with respect to indicators so that, the programs developed for outdated platform MetaTrader 4 based on this library could work normally when switching over to MetaTrader 5.
preview
Parallel Particle Swarm Optimization

Parallel Particle Swarm Optimization

The article describes a method of fast optimization using the particle swarm algorithm. It also presents the method implementation in MQL, which is ready for use both in single-threaded mode inside an Expert Advisor and in a parallel multi-threaded mode as an add-on that runs on local tester agents.
preview
Neural networks made easy (Part 3): Convolutional networks

Neural networks made easy (Part 3): Convolutional networks

As a continuation of the neural network topic, I propose considering convolutional neural networks. This type of neural network are usually applied to analyzing visual imagery. In this article, we will consider the application of these networks in the financial markets.
preview
Continuous walk-forward optimization (Part 8): Program improvements and fixes

Continuous walk-forward optimization (Part 8): Program improvements and fixes

The program has been modified based on comments and requests from users and readers of this article series. This article contains a new version of the auto optimizer. This version implements requested features and provides other improvements, which I found when working with the program.
Basic math behind Forex trading
Basic math behind Forex trading

Basic math behind Forex trading

The article aims to describe the main features of Forex trading as simply and quickly as possible, as well as share some basic ideas with beginners. It also attempts to answer the most tantalizing questions in the trading community along with showcasing the development of a simple indicator.
preview
Advanced resampling and selection of CatBoost models by brute-force method

Advanced resampling and selection of CatBoost models by brute-force method

This article describes one of the possible approaches to data transformation aimed at improving the generalizability of the model, and also discusses sampling and selection of CatBoost models.
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.
A scientific approach to the development of trading algorithms
A scientific approach to the development of trading algorithms

A scientific approach to the development of trading algorithms

The article considers the methodology for developing trading algorithms, in which a consistent scientific approach is used to analyze possible price patterns and to build trading algorithms based on these patterns. Development ideals are demonstrated using examples.
preview
CatBoost machine learning algorithm from Yandex with no Python or R knowledge required

CatBoost machine learning algorithm from Yandex with no Python or R knowledge required

The article provides the code and the description of the main stages of the machine learning process using a specific example. To obtain the model, you do not need Python or R knowledge. Furthermore, basic MQL5 knowledge is enough — this is exactly my level. Therefore, I hope that the article will serve as a good tutorial for a broad audience, assisting those interested in evaluating machine learning capabilities and in implementing them in their programs.
preview
Timeseries in DoEasy library (part 50): Multi-period multi-symbol standard indicators with a shift

Timeseries in DoEasy library (part 50): Multi-period multi-symbol standard indicators with a shift

In the article, let’s improve library methods for correct display of multi-symbol multi-period standard indicators, which lines are displayed on the current symbol chart with a shift set in the settings. As well, let’s put things in order in methods of work with standard indicators and remove the redundant code to the library area in the final indicator program.
preview
Custom symbols: Practical basics

Custom symbols: Practical basics

The article is devoted to the programmatic generation of custom symbols which are used to demonstrate some popular methods for displaying quotes. It describes a suggested variant of minimally invasive adaptation of Expert Advisors for trading a real symbol from a derived custom symbol chart. MQL source codes are attached to this article.
preview
Neural networks made easy (Part 2): Network training and testing

Neural networks made easy (Part 2): Network training and testing

In this second article, we will continue to study neural networks and will consider an example of using our created CNet class in Expert Advisors. We will work with two neural network models, which show similar results both in terms of training time and prediction accuracy.
What is a trend and is the market structure based on trend or flat?
What is a trend and is the market structure based on trend or flat?

What is a trend and is the market structure based on trend or flat?

Traders often talk about trends and flats but very few of them really understand what a trend/flat really is and even fewer are able to clearly explain these concepts. Discussing these basic terms is often beset by a solid set of prejudices and misconceptions. However, if we want to make profit, we need to understand the mathematical and logical meaning of these concepts. In this article, I will take a closer look at the essence of trend and flat, as well as try to define whether the market structure is based on trend, flat or something else. I will also consider the most optimal strategies for making profit on trend and flat markets.
preview
Websockets for MetaTrader 5

Websockets for MetaTrader 5

Before the introduction of the network functionality provided with the updated MQL5 API, MetaTrader programs have been limited in their ability to connect and interface with websocket based services. But of course this has all changed, in this article we will explore the implementation of a websocket library in pure MQL5. A brief description of the websocket protocol will be given along with a step by step guide on how to use the resulting library.
Price series discretization, random component and noise
Price series discretization, random component and noise

Price series discretization, random component and noise

We usually analyze the market using candlesticks or bars that slice the price series into regular intervals. Doesn't such discretization method distort the real structure of market movements? Discretization of an audio signal at regular intervals is an acceptable solution because an audio signal is a function that changes over time. The signal itself is an amplitude which depends on time. This signal property is fundamental.
preview
Timeseries in DoEasy library (part 49): Multi-period multi-symbol multi-buffer standard indicators

Timeseries in DoEasy library (part 49): Multi-period multi-symbol multi-buffer standard indicators

In the current article, I will improve the library classes to implement the ability to develop multi-symbol multi-period standard indicators requiring several indicator buffers to display their data.
preview
Gradient Boosting (CatBoost) in the development of trading systems. A naive approach

Gradient Boosting (CatBoost) in the development of trading systems. A naive approach

Training the CatBoost classifier in Python and exporting the model to mql5, as well as parsing the model parameters and a custom strategy tester. The Python language and the MetaTrader 5 library are used for preparing the data and for training the model.
Using cryptography with external applications
Using cryptography with external applications

Using cryptography with external applications

In this article, we consider encryption/decryption of objects in MetaTrader and in external applications. Our purpose is to determine the conditions under which the same results will be obtained with the same initial data.
Timeseries in DoEasy library (part 48): Multi-period multi-symbol indicators on one buffer in a subwindow
Timeseries in DoEasy library (part 48): Multi-period multi-symbol indicators on one buffer in a subwindow

Timeseries in DoEasy library (part 48): Multi-period multi-symbol indicators on one buffer in a subwindow

The article considers an example of creating multi-symbol multi-period standard indicators using a single indicator buffer for construction and working in the indicator subwindow. I am going to prepare the library classes for working with standard indicators working in the program main window and having more than one buffer for displaying their data.
A system of voice notifications for trade events and signals
A system of voice notifications for trade events and signals

A system of voice notifications for trade events and signals

Nowadays, voice assistants play a prominent role in human life, as we often use navigators, voice search and translators. In this article, I will try to develop a simple and user friendly system of voice notifications for various trade events, market states or signals generated by trading signals.
Timeseries in DoEasy library (part 47): Multi-period multi-symbol standard indicators
Timeseries in DoEasy library (part 47): Multi-period multi-symbol standard indicators

Timeseries in DoEasy library (part 47): Multi-period multi-symbol standard indicators

In this article, I will start developing the methods of working with standard indicators, which will ultimately allow creating multi-symbol multi-period standard indicators based on library classes. Besides, I will add the "Skipped bars" event to the timeseries classes and eliminate excessive load from the main program code by moving the library preparation functions to CEngine class.
On Methods to Detect Overbought/Oversold Zones. Part I
On Methods to Detect Overbought/Oversold Zones. Part I

On Methods to Detect Overbought/Oversold Zones. Part I

Overbought/oversold zones characterize a certain state of the market, differentiating through weaker changes in the prices of securities. This adverse change in the synamics is pronounced most at the final stage in the development of trends of any scales. Since the profit value in trading depends directly on the capability of covering as large trend amplitude as possible, the accuracy of detecting such zones is a key task in trading with any securities whatsoever.
Probability theory and mathematical statistics with examples (part I): Fundamentals and elementary theory
Probability theory and mathematical statistics with examples (part I): Fundamentals and elementary theory

Probability theory and mathematical statistics with examples (part I): Fundamentals and elementary theory

Trading is always about making decisions in the face of uncertainty. This means that the results of the decisions are not quite obvious at the time these decisions are made. This entails the importance of theoretical approaches to the construction of mathematical models allowing us to describe such cases in meaningful manner.
Quick Manual Trading Toolkit: Working with open positions and pending orders
Quick Manual Trading Toolkit: Working with open positions and pending orders

Quick Manual Trading Toolkit: Working with open positions and pending orders

In this article, we will expand the capabilities of the toolkit: we will add the ability to close trade positions upon specific conditions and will create tables for controlling market and pending orders, with the ability to edit these orders.
Timeseries in DoEasy library (part 46): Multi-period multi-symbol indicator buffers
Timeseries in DoEasy library (part 46): Multi-period multi-symbol indicator buffers

Timeseries in DoEasy library (part 46): Multi-period multi-symbol indicator buffers

In this article, I am going to improve the classes of indicator buffer objects to work in the multi-symbol mode. This will pave the way for creating multi-symbol multi-period indicators in custom programs. I will add the missing functionality to the calculated buffer objects allowing us to create multi-symbol multi-period standard indicators.
Calculating mathematical expressions (Part 2). Pratt and shunting yard parsers
Calculating mathematical expressions (Part 2). Pratt and shunting yard parsers

Calculating mathematical expressions (Part 2). Pratt and shunting yard parsers

In this article, we consider the principles of mathematical expression parsing and evaluation using parsers based on operator precedence. We will implement Pratt and shunting-yard parser, byte-code generation and calculations by this code, as well as view how to use indicators as functions in expressions and how to set up trading signals in Expert Advisors based on these indicators.
Timeseries in DoEasy library (part 45): Multi-period indicator buffers
Timeseries in DoEasy library (part 45): Multi-period indicator buffers

Timeseries in DoEasy library (part 45): Multi-period indicator buffers

In this article, I will start the improvement of the indicator buffer objects and collection class for working in multi-period and multi-symbol modes. I am going to consider the operation of buffer objects for receiving and displaying data from any timeframe on the current symbol chart.
Calculating mathematical expressions (Part 1). Recursive descent parsers
Calculating mathematical expressions (Part 1). Recursive descent parsers

Calculating mathematical expressions (Part 1). Recursive descent parsers

The article considers the basic principles of mathematical expression parsing and calculation. We will implement recursive descent parsers operating in the interpreter and fast calculation modes, based on a pre-built syntax tree.
Quick Manual Trading Toolkit: Basic Functionality
Quick Manual Trading Toolkit: Basic Functionality

Quick Manual Trading Toolkit: Basic Functionality

Today, many traders switch to automated trading systems which can require additional setup or can be fully automated and ready to use. However, there is a considerable part of traders who prefer trading manually, in the old fashioned way. In this article, we will create toolkit for quick manual trading, using hotkeys, and for performing typical trading actions in one click.