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
Extract profit down to the last pip
Extract profit down to the last pip

Extract profit down to the last pip

The article describes an attempt to combine theory with practice in the algorithmic trading field. Most of discussions concerning the creation of Trading Systems is connected with the use of historic bars and various indicators applied thereon. This is the most well covered field and thus we will not consider it. Bars represent a very artificial entity; therefore we will work with something closer to proto-data, namely the price ticks.
Arranging a mailing campaign by means of Google services
Arranging a mailing campaign by means of Google services

Arranging a mailing campaign by means of Google services

A trader may want to arrange a mailing campaign to maintain business relationships with other traders, subscribers, clients or friends. Besides, there may be a necessity to send screenshotas, logs or reports. These may not be the most frequently arising tasks but having such a feature is clearly an advantage. The article deals with using several Google services simultaneously, developing an appropriate assembly on C# and integrating it with MQL tools.
Developing a cross-platform Expert Advisor to set StopLoss and TakeProfit based on risk settings
Developing a cross-platform Expert Advisor to set StopLoss and TakeProfit based on risk settings

Developing a cross-platform Expert Advisor to set StopLoss and TakeProfit based on risk settings

In this article, we will create an Expert Advisor for automated entry lot calculation based on risk values. Also the Expert Advisor will be able to automatically place Take Profit with the select ratio to Stop Loss. That is, it can calculate Take Profit based on any selected ratio, such as 3 to 1, 4 to 1 or any other selected value.
Library for easy and quick development of MetaTrader programs (part IX): Compatibility with MQL4 - Preparing data
Library for easy and quick development of MetaTrader programs (part IX): Compatibility with MQL4 - Preparing data

Library for easy and quick development of MetaTrader programs (part IX): Compatibility with MQL4 - Preparing data

In the previous articles, we started creating a large cross-platform library simplifying the development of programs for MetaTrader 5 and MetaTrader 4 platforms. In the eighth part, we implemented the class for tracking order and position modification events. Here, we will improve the library by making it fully compatible with MQL4.
Developing a cross-platform grider EA (part II): Range-based grid in trend direction
Developing a cross-platform grider EA (part II): Range-based grid in trend direction

Developing a cross-platform grider EA (part II): Range-based grid in trend direction

In this article, we will develop a grider EA for trading in a trend direction within a range. Thus, the EA is to be suited mostly for Forex and commodity markets. According to the tests, our grider showed profit since 2018. Unfortunately, this is not true for the period of 2014-2018.
Library for easy and quick development of MetaTrader programs (part VIII): Order and position modification events
Library for easy and quick development of MetaTrader programs (part VIII): Order and position modification events

Library for easy and quick development of MetaTrader programs (part VIII): Order and position modification events

In the previous articles, we started creating a large cross-platform library simplifying the development of programs for MetaTrader 5 and MetaTrader 4 platforms. In the seventh part, we added tracking StopLimit orders activation and prepared the functionality for tracking other events involving orders and positions. In this article, we will develop the class for tracking order and position modification events.
Grokking market "memory" through differentiation and entropy analysis
Grokking market "memory" through differentiation and entropy analysis

Grokking market "memory" through differentiation and entropy analysis

The scope of use of fractional differentiation is wide enough. For example, a differentiated series is usually input into machine learning algorithms. The problem is that it is necessary to display new data in accordance with the available history, which the machine learning model can recognize. In this article we will consider an original approach to time series differentiation. The article additionally contains an example of a self optimizing trading system based on a received differentiated series.
Price velocity measurement methods
Price velocity measurement methods

Price velocity measurement methods

There are multiple different approaches to market research and analysis. The main ones are technical and fundamental. In technical analysis, traders collect, process and analyze numerical data and parameters related to the market, including prices, volumes, etc. In fundamental analysis, traders analyze events and news affecting the markets directly or indirectly. The article deals with price velocity measurement methods and studies trading strategies based on that methods.
Evaluating the ability of Fractal index and Hurst exponent to predict financial time series
Evaluating the ability of Fractal index and Hurst exponent to predict financial time series

Evaluating the ability of Fractal index and Hurst exponent to predict financial time series

Studies related to search for the fractal behavior of financial data suggest that behind the seemingly chaotic behavior of economic time series there are hidden stable mechanisms of participants' collective behavior. These mechanisms can lead to the emergence of price dynamics on the exchange, which can define and describe specific properties of price series. When applied to trading, one could benefit from the indicators which can efficiently and reliably estimate the fractal parameters in the scale and time frame, which are relevant in practice.
Library for easy and quick development of MetaTrader programs (part VII): StopLimit order activation events, preparing the functionality for order and position modification events
Library for easy and quick development of MetaTrader programs (part VII): StopLimit order activation events, preparing the functionality for order and position modification events

Library for easy and quick development of MetaTrader programs (part VII): StopLimit order activation events, preparing the functionality for order and position modification events

In the previous articles, we started creating a large cross-platform library simplifying the development of programs for MetaTrader 5 and MetaTrader 4 platforms. In the sixth part, we trained the library to work with positions on netting accounts. Here we will implement tracking StopLimit orders activation and prepare the functionality to track order and position modification events.
Library for easy and quick development of MetaTrader programs (part VI): Netting account events
Library for easy and quick development of MetaTrader programs (part VI): Netting account events

Library for easy and quick development of MetaTrader programs (part VI): Netting account events

In the previous articles, we started creating a large cross-platform library simplifying the development of programs for MetaTrader 5 and MetaTrader 4 platforms. In the fifth part of the article series, we created trading event classes and the event collection, from which the events are sent to the base object of the Engine library and the control program chart. In this part, we will let the library to work on netting accounts.
Applying OLAP in trading (part 2): Visualizing the interactive multidimensional data analysis results
Applying OLAP in trading (part 2): Visualizing the interactive multidimensional data analysis results

Applying OLAP in trading (part 2): Visualizing the interactive multidimensional data analysis results

In this article, we consider the creation of an interactive graphical interface for an MQL program, which is designed for the processing of account history and trading reports using OLAP techniques. To obtain a visual result, we will use maximizable and scalable windows, an adaptive layout of rubber controls and a new control for displaying diagrams. To provide the visualization functionality, we will implement a GUI with the selection of variables along coordinate axes, as well as with the selection of aggregate functions, diagram types and sorting options.
Applying OLAP in trading (part 1): Online analysis of multidimensional data
Applying OLAP in trading (part 1): Online analysis of multidimensional data

Applying OLAP in trading (part 1): Online analysis of multidimensional data

The article describes how to create a framework for the online analysis of multidimensional data (OLAP), as well as how to implement this in MQL and to apply such analysis in the MetaTrader environment using the example of trading account history processing.
Developing graphical interfaces based on .Net Framework and C# (part 2): Additional graphical elements
Developing graphical interfaces based on .Net Framework and C# (part 2): Additional graphical elements

Developing graphical interfaces based on .Net Framework and C# (part 2): Additional graphical elements

The article is a follow-up of the previous publication "Developing graphical interfaces for Expert Advisors and indicators based on .Net Framework and C#". It introduces new graphical elements for creating graphical interfaces.
Library for easy and quick development of MetaTrader programs (part V): Classes and collection of trading events, sending events to the program
Library for easy and quick development of MetaTrader programs (part V): Classes and collection of trading events, sending events to the program

Library for easy and quick development of MetaTrader programs (part V): Classes and collection of trading events, sending events to the program

In the previous articles, we started creating a large cross-platform library simplifying the development of programs for MetaTrader 5 and MetaTrader 4 platforms. In the fourth part, we tested tracking trading events on the account. In this article, we will develop trading event classes and place them to the event collections. From there, they will be sent to the base object of the Engine library and the control program chart.
Selection and navigation utility in MQL5 and MQL4: Adding data to charts
Selection and navigation utility in MQL5 and MQL4: Adding data to charts

Selection and navigation utility in MQL5 and MQL4: Adding data to charts

In this article, we will continue expanding the functionality of the utility. This time, we will add the ability to display data that simplifies our trading. In particular, we are going to add High and Low prices of the previous day, round levels, High and Low prices of the year, session start time, etc.
Library for easy and quick development of MetaTrader programs (part IV): Trading events
Library for easy and quick development of MetaTrader programs (part IV): Trading events

Library for easy and quick development of MetaTrader programs (part IV): Trading events

In the previous articles, we started creating a large cross-platform library simplifying the development of programs for MetaTrader 5 and MetaTrader 4 platforms. We already have collections of historical orders and deals, market orders and positions, as well as the class for convenient selection and sorting of orders. In this part, we will continue the development of the base object and teach the Engine Library to track trading events on the account.
How to visualize multicurrency trading history based on HTML and CSV reports
How to visualize multicurrency trading history based on HTML and CSV reports

How to visualize multicurrency trading history based on HTML and CSV reports

Since its introduction, MetaTrader 5 provides multicurrency testing options. This possibility is often used by traders. However the function is not universal. The article presents several programs for drawing graphical objects on charts based on HTML and CSV trading history reports. Multicurrency trading can be analyzed in parallel, in several sub-windows, as well as in one window using the dynamic switching command.
Studying candlestick analysis techniques (part IV): Updates and additions to Pattern Analyzer
Studying candlestick analysis techniques (part IV): Updates and additions to Pattern Analyzer

Studying candlestick analysis techniques (part IV): Updates and additions to Pattern Analyzer

The article presents a new version of the Pattern Analyzer application. This version provides bug fixes and new features, as well as the revised user interface. Comments and suggestions from previous article were taken into account when developing the new version. The resulting application is described in this article.
Developing a cross-platform grider EA
Developing a cross-platform grider EA

Developing a cross-platform grider EA

In this article, we will learn how to create Expert Advisors (EAs) working both in MetaTrader 4 and MetaTrader 5. To do this, we are going to develop an EA constructing order grids. Griders are EAs that place several limit orders above the current price and the same number of limit orders below it simultaneously.
A DLL for MQL5 in 10 Minutes (Part II): Creating with Visual Studio 2017
A DLL for MQL5 in 10 Minutes (Part II): Creating with Visual Studio 2017

A DLL for MQL5 in 10 Minutes (Part II): Creating with Visual Studio 2017

The original basic article has not lost its relevance and thus if you are interested in this topic, be sure to read the first article. However much time has passed since then, so the current Visual Studio 2017 features an updated interface. The MetaTrader 5 platform has also acquired new features. The article provides a description of dll project development stages, as well as DLL setup and interaction with MetaTrader 5 tools.
Using MATLAB 2018 computational capabilities in MetaTrader 5
Using MATLAB 2018 computational capabilities in MetaTrader 5

Using MATLAB 2018 computational capabilities in MetaTrader 5

After the upgrade of the MATLAB package in 2015, it is necessary to consider a modern way of creating DLL libraries. The article uses a sample predictive indicator to illustrate the peculiarities of linking MetaTrader 5 and MATLAB using modern 64-bit versions of the platforms, which are utilized nowadays. With the entire sequence of connecting MATLAB considered, MQL5 developers will be able to create applications with advanced computational capabilities much faster, avoiding «pitfalls».
MTF indicators as the technical analysis tool
MTF indicators as the technical analysis tool

MTF indicators as the technical analysis tool

Most of traders agree that the current market state analysis starts with the evaluation of higher chart timeframes. The analysis is performed downwards to lower timeframes until the one, at which deals are performed. This analysis method seems to be a mandatory part of professional approach for successful trading. In this article, we will discuss multi-timeframe indicators and their creation ways, as well as we will provide MQL5 code examples. In addition to the general evaluation of advantages and disadvantages, we will propose a new indicator approach using the MTF mode.
Library for easy and quick development of MetaTrader programs (part III). Collection of market orders and positions, search and sorting
Library for easy and quick development of MetaTrader programs (part III). Collection of market orders and positions, search and sorting

Library for easy and quick development of MetaTrader programs (part III). Collection of market orders and positions, search and sorting

In the first part, we started creating a large cross-platform library simplifying the development of programs for MetaTrader 5 and MetaTrader 4 platforms. Further on, we implemented the collection of history orders and deals. Our next step is creating a class for a convenient selection and sorting of orders, deals and positions in collection lists. We are going to implement the base library object called Engine and add collection of market orders and positions to the library.
Extracting structured data from HTML pages using CSS selectors
Extracting structured data from HTML pages using CSS selectors

Extracting structured data from HTML pages using CSS selectors

The article provides a description of a universal method for analyzing and converting data from HTML documents based on CSS selectors. Trading reports, tester reports, your favorite economic calendars, public signals, account monitoring and additional online quote sources will become available straight from MQL.
Library for easy and quick development of MetaTrader programs (part II). Collection of historical orders and deals
Library for easy and quick development of MetaTrader programs (part II). Collection of historical orders and deals

Library for easy and quick development of MetaTrader programs (part II). Collection of historical orders and deals

In the first part, we started creating a large cross-platform library simplifying the development of programs for MetaTrader 5 and MetaTrader 4 platforms. We created the COrder abstract object which is a base object for storing data on history orders and deals, as well as on market orders and positions. Now we will develop all the necessary objects for storing account history data in collections.
Studying candlestick analysis techniques (part III): Library for pattern operations
Studying candlestick analysis techniques (part III): Library for pattern operations

Studying candlestick analysis techniques (part III): Library for pattern operations

The purpose of this article is to create a custom tool, which would enable users to receive and use the entire array of information about patterns discussed earlier. We will create a library of pattern related functions which you will be able to use in your own indicators, trading panels, Expert Advisors, etc.
Library for easy and quick development of MetaTrader programs (part I). Concept, data management and first results
Library for easy and quick development of MetaTrader programs (part I). Concept, data management and first results

Library for easy and quick development of MetaTrader programs (part I). Concept, data management and first results

While analyzing a huge number of trading strategies, orders for development of applications for MetaTrader 5 and MetaTrader 4 terminals and various MetaTrader websites, I came to the conclusion that all this diversity is based mostly on the same elementary functions, actions and values appearing regularly in different programs. This resulted in DoEasy cross-platform library for easy and quick development of МetaТrader 5 and МetaТrader 4 applications.
Scraping bond yield data from the web
Scraping bond yield data from the web

Scraping bond yield data from the web

Automate the collection of interest rate data to improve the performance of an Expert Advisor.
Developing graphical interfaces for Expert Advisors and indicators based on .Net Framework and C#
Developing graphical interfaces for Expert Advisors and indicators based on .Net Framework and C#

Developing graphical interfaces for Expert Advisors and indicators based on .Net Framework and C#

The article presents a simple and fast method of creating graphical windows using Visual Studio with subsequent integration into the Expert Advisor's MQL code. The article is meant for non-specialist audiences and does not require any knowledge of C# and .Net technology.
Color optimization of trading strategies
Color optimization of trading strategies

Color optimization of trading strategies

In this article we will perform an experiment: we will color optimization results. The color is determined by three parameters: the levels of red, green and blue (RGB). There are other color coding methods, which also use three parameters. Thus, three testing parameters can be converted to one color, which visually represents the values. Read this article to find out if such a representation can be useful.
MetaTrader 5 and Python integration: receiving and sending data
MetaTrader 5 and Python integration: receiving and sending data

MetaTrader 5 and Python integration: receiving and sending data

Comprehensive data processing requires extensive tools and is often beyond the sandbox of one single application. Specialized programming languages are used for processing and analyzing data, statistics and machine learning. One of the leading programming languages for data processing is Python. The article provides a description of how to connect MetaTrader 5 and Python using sockets, as well as how to receive quotes via the terminal API.
Studying candlestick analysis techniques (Part II): Auto search for new patterns
Studying candlestick analysis techniques (Part II): Auto search for new patterns

Studying candlestick analysis techniques (Part II): Auto search for new patterns

In the previous article, we analyzed 14 patterns selected from a large variety of existing candlestick formations. It is impossible to analyze all the patterns one by one, therefore another solution was found. The new system searches and tests new candlestick patterns based on known candlestick types.
MQL Parsing by Means of MQL
MQL Parsing by Means of MQL

MQL Parsing by Means of MQL

The article describes a preprocessor, a scanner, and a parser to be used in parsing the MQL-based source codes. MQL implementation is attached.
The power of ZigZag (part II). Examples of receiving, processing and displaying data
The power of ZigZag (part II). Examples of receiving, processing and displaying data

The power of ZigZag (part II). Examples of receiving, processing and displaying data

In the first part of the article, I have described a modified ZigZag indicator and a class for receiving data of that type of indicators. Here, I will show how to develop indicators based on these tools and write an EA for tests that features making deals according to signals formed by ZigZag indicator. As an addition, the article will introduce a new version of the EasyAndFast library for developing graphical user interfaces.
Studying candlestick analysis techniques (part I): Checking existing patterns
Studying candlestick analysis techniques (part I): Checking existing patterns

Studying candlestick analysis techniques (part I): Checking existing patterns

In this article, we will consider popular candlestick patterns and will try to find out if they are still relevant and effective in today's markets. Candlestick analysis appeared more than 20 years ago and has since become quite popular. Many traders consider Japanese candlesticks the most convenient and easily understandable asset price visualization form.
The power of ZigZag (part I). Developing the base class of the indicator
The power of ZigZag (part I). Developing the base class of the indicator

The power of ZigZag (part I). Developing the base class of the indicator

Many researchers do not pay enough attention to determining the price behavior. At the same time, complex methods are used, which very often are simply “black boxes”, such as machine learning or neural networks. The most important question arising in that case is what data to submit for training a particular model.
Practical application of correlations in trading
Practical application of correlations in trading

Practical application of correlations in trading

In this article, we will analyze the concept of correlation between variables, as well as methods for the calculation of correlation coefficients and their practical use in trading. Correlation is a statistical relationship between two or more random variables (or quantities which can be considered random with some acceptable degree of accuracy). Changes in one ore more variables lead to systematic changes of other related variables.
Applying Monte Carlo method in reinforcement learning
Applying Monte Carlo method in reinforcement learning

Applying Monte Carlo method in reinforcement learning

In the article, we will apply Reinforcement learning to develop self-learning Expert Advisors. In the previous article, we considered the Random Decision Forest algorithm and wrote a simple self-learning EA based on Reinforcement learning. The main advantages of such an approach (trading algorithm development simplicity and high "training" speed) were outlined. Reinforcement learning (RL) is easily incorporated into any trading EA and speeds up its optimization.
Practical Use of Kohonen Neural Networks in Algorithmic Trading. Part II. Optimizing and forecasting
Practical Use of Kohonen Neural Networks in Algorithmic Trading. Part II. Optimizing and forecasting

Practical Use of Kohonen Neural Networks in Algorithmic Trading. Part II. Optimizing and forecasting

Based on universal tools designed for working with Kohonen networks, we construct the system of analyzing and selecting the optimal EA parameters and consider forecasting time series. In Part I, we corrected and improved the publicly available neural network classes, having added necessary algorithms. Now, it is time to apply them to practice.