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
Using OpenCL to test candlestick patterns
Using OpenCL to test candlestick patterns

Using OpenCL to test candlestick patterns

The article describes the algorithm for implementing the OpenCL candlestick patterns tester in the "1 minute OHLC" mode. We will also compare its speed with the built-in strategy tester launched in the fast and slow optimization modes.
DIY multi-threaded asynchronous MQL5 WebRequest
DIY multi-threaded asynchronous MQL5 WebRequest

DIY multi-threaded asynchronous MQL5 WebRequest

The article describes the library allowing you to increase the efficiency of working with HTTP requests in MQL5. Execution of WebRequest in non-blocking mode is implemented in additional threads that use auxiliary charts and Expert Advisors, exchanging custom events and reading shared resources. The source codes are applied as well.
Reversing: Formalizing the entry point and developing a manual trading algorithm
Reversing: Formalizing the entry point and developing a manual trading algorithm

Reversing: Formalizing the entry point and developing a manual trading algorithm

This is the last article within the series devoted to the Reversing trading strategy. Here we will try to solve the problem, which caused the testing results instability in previous articles. We will also develop and test our own algorithm for manual trading in any market using the reversing strategy.
Reversing: Reducing maximum drawdown and testing other markets
Reversing: Reducing maximum drawdown and testing other markets

Reversing: Reducing maximum drawdown and testing other markets

In this article, we continue to dwell on reversing techniques. We will try to reduce the maximum balance drawdown till an acceptable level for the instruments considered earlier. We will see if the measures will reduce the profit. We will also check how the reversing method performs on other markets, including stock, commodity, index, ETF and agricultural markets. Attention, the article contains a lot of images!
Reversal patterns: Testing the Head and Shoulders pattern
Reversal patterns: Testing the Head and Shoulders pattern

Reversal patterns: Testing the Head and Shoulders pattern

This article is a follow-up to the previous one called "Reversal patterns: Testing the Double top/bottom pattern". Now we will have a look at another well-known reversal pattern called Head and Shoulders, compare the trading efficiency of the two patterns and make an attempt to combine them into a single trading system.
Reversal patterns: Testing the Double top/bottom pattern
Reversal patterns: Testing the Double top/bottom pattern

Reversal patterns: Testing the Double top/bottom pattern

Traders often look for trend reversal points since the price has the greatest potential for movement at the very beginning of a newly formed trend. Consequently, various reversal patterns are considered in the technical analysis. The Double top/bottom is one of the most well-known and frequently used ones. The article proposes the method of the pattern programmatic detection. It also tests the pattern's profitability on history data.
Gap - a profitable strategy or 50/50?
Gap - a profitable strategy or 50/50?

Gap - a profitable strategy or 50/50?

The article dwells on gaps — significant differences between a close price of a previous timeframe and an open price of the next one, as well as on forecasting a daily bar direction. Applying the GetOpenFileName function by the system DLL is considered as well.
Using limit orders instead of Take Profit without changing the EA's original code
Using limit orders instead of Take Profit without changing the EA's original code

Using limit orders instead of Take Profit without changing the EA's original code

Using limit orders instead of conventional take profits has long been a topic of discussions on the forum. What is the advantage of this approach and how can it be implemented in your trading? In this article, I want to offer you my vision of this topic.
Movement continuation model - searching on the chart and execution statistics
Movement continuation model - searching on the chart and execution statistics

Movement continuation model - searching on the chart and execution statistics

This article provides programmatic definition of one of the movement continuation models. The main idea is defining two waves — the main and the correction one. For extreme points, I apply fractals as well as "potential" fractals - extreme points that have not yet formed as fractals.
EA remote control methods
EA remote control methods

EA remote control methods

The main advantage of trading robots lies in the ability to work 24 hours a day on a remote VPS server. But sometimes it is necessary to intervene in their work, while there may be no direct access to the server. Is it possible to manage EAs remotely? The article proposes one of the options for controlling EAs via external commands.
100 best optimization passes (part 1). Developing optimization analyzer
100 best optimization passes (part 1). Developing optimization analyzer

100 best optimization passes (part 1). Developing optimization analyzer

The article dwells on the development of an application for selecting the best optimization passes using several possible options. The application is able to sort out the optimization results by a variety of factors. Optimization passes are always written to a database, therefore you can always select new robot parameters without re-optimization. Besides, you are able to see all optimization passes on a single chart, calculate parametric VaR ratios and build the graph of the normal distribution of passes and trading results of a certain ratio set. Besides, the graphs of some calculated ratios are built dynamically beginning with the optimization start (or from a selected date to another selected date).
Modeling time series using custom symbols according to specified distribution laws
Modeling time series using custom symbols according to specified distribution laws

Modeling time series using custom symbols according to specified distribution laws

The article provides an overview of the terminal's capabilities for creating and working with custom symbols, offers options for simulating a trading history using custom symbols, trend and various chart patterns.
Reversing: The holy grail or a dangerous delusion?
Reversing: The holy grail or a dangerous delusion?

Reversing: The holy grail or a dangerous delusion?

In this article, we will study the reverse martingale technique and will try to understand whether it is worth using, as well as whether it can help improve your trading strategy. We will create an Expert Advisor to operate on historic data and to check what indicators are best suitable for the reversing technique. We will also check whether it can be used without any indicator as an independent trading system. In addition, we will check if reversing can turn a loss-making trading system into a profitable one.
Using indicators for optimizing Expert Advisors in real time
Using indicators for optimizing Expert Advisors in real time

Using indicators for optimizing Expert Advisors in real time

Efficiency of any trading robot depends on the correct selection of its parameters (optimization). However, parameters that are considered optimal for one time interval may not retain their effectiveness in another period of trading history. Besides, EAs showing profit during tests turn out to be loss-making in real time. The issue of continuous optimization comes to the fore here. When facing plenty of routine work, humans always look for ways to automate it. In this article, I propose a non-standard approach to solving this issue.
MQL5 Cookbook: Getting properties of an open hedge position
MQL5 Cookbook: Getting properties of an open hedge position

MQL5 Cookbook: Getting properties of an open hedge position

MetaTrader 5 is a multi-asset platform. Moreover, it supports different position management systems. Such opportunities provide significantly expanded options for the implementation and formalization of trading ideas. In this article, we discuss methods of handling and accounting of position properties in the hedging mode. The article features a derived class, as well as examples showing how to get and process the properties of a hedge position.
Automated Optimization of an EA for MetaTrader 5
Automated Optimization of an EA for MetaTrader 5

Automated Optimization of an EA for MetaTrader 5

This article describes the implementation of a self-optimization mechanism under MetaTrader 5.
Elder-Ray (Bulls Power and Bears Power)
Elder-Ray (Bulls Power and Bears Power)

Elder-Ray (Bulls Power and Bears Power)

The article dwells on Elder-Ray trading system based on Bulls Power, Bears Power and Moving Average indicators (EMA — exponential averaging). This system was described by Alexander Elder in his book "Trading for a Living".
50,000 completed orders in the MQL5.com Freelance service
50,000 completed orders in the MQL5.com Freelance service

50,000 completed orders in the MQL5.com Freelance service

Members of the official MetaTrader Freelance service have completed more than 50,000 orders as at October 2018. This is the world's largest Freelance site for MQL programmers: more than a thousand developers, dozens of new orders daily and 7 languages localization.
Combining trend and flat strategies
Combining trend and flat strategies

Combining trend and flat strategies

There are numerous trading strategies out there. Some of them look for a trend, while others define ranges of price fluctuations to trade within them. Is it possible to combine these two approaches to increase profitability?
Deep Neural Networks (Part VIII). Increasing the classification quality of bagging ensembles
Deep Neural Networks (Part VIII). Increasing the classification quality of bagging ensembles

Deep Neural Networks (Part VIII). Increasing the classification quality of bagging ensembles

The article considers three methods which can be used to increase the classification quality of bagging ensembles, and their efficiency is estimated. The effects of optimization of the ELM neural network hyperparameters and postprocessing parameters are evaluated.
PairPlot graph based on CGraphic for analyzing correlations between data arrays (time series)
PairPlot graph based on CGraphic for analyzing correlations between data arrays (time series)

PairPlot graph based on CGraphic for analyzing correlations between data arrays (time series)

Comparing several time series during a technical analysis is a quite common task that requires appropriate tools. In this article, I suggest developing a tool for graphical analysis and detecting correlations between two or more time series.
950 websites broadcast the Economic Calendar from MetaQuotes
950 websites broadcast the Economic Calendar from MetaQuotes

950 websites broadcast the Economic Calendar from MetaQuotes

The widget provides websites with a detailed release schedule of 500 indicators and indices, of the world's largest economies. Thus, traders quickly receive up-to-date information on all important events with explanations and graphs in addition to the main website content.
Developing stock indicators featuring volume control through the example of the delta indicator
Developing stock indicators featuring volume control through the example of the delta indicator

Developing stock indicators featuring volume control through the example of the delta indicator

The article deals with the algorithm of developing stock indicators based on real volumes using the CopyTicks() and CopyTicksRange() functions. Some subtle aspects of developing such indicators, as well as their operation in real time and in the strategy tester are also described.
Universal RSI indicator for working in two directions simultaneously
Universal RSI indicator for working in two directions simultaneously

Universal RSI indicator for working in two directions simultaneously

When developing trading algorithms, we often encounter a problem: how to determine where a trend/flat begins and ends? In this article, we try to create a universal indicator, in which we try to combine signals for different types of strategies. We will try to simplify the process of obtaining trade signals in an expert as much as possible. An example of combining several indicators in one will be given.
Custom presentation of trading history and creation of report diagrams
Custom presentation of trading history and creation of report diagrams

Custom presentation of trading history and creation of report diagrams

The article describes custom methods for assessing the trading history. Two classes have been written for downloading and analyzing history. The first of them collects the trading history and represents it as a summary table. The second one deals with statistics: it calculates a number of variables and builds charts for a more efficient evaluation of trading results.
14,000 trading robots in the MetaTrader Market
14,000 trading robots in the MetaTrader Market

14,000 trading robots in the MetaTrader Market

The largest store of ready-made applications for algo-trading now features 13,970 products. This includes 4,800 robots, 6,500 indicators, 2,400 utilities and other solutions. Almost half of the applications (6,000) are available for rent. Also, a quarter of the total number of products (3,800) can be downloaded for free.
Trading account monitoring is an indispensable trader's tool
Trading account monitoring is an indispensable trader's tool

Trading account monitoring is an indispensable trader's tool

Trading account monitoring provides a detailed report on all completed deals. All trading statistics are collected automatically and provided to you as easy-to-understand diagrams and graphs.
Expert Advisor featuring GUI: Adding functionality (part II)
Expert Advisor featuring GUI: Adding functionality (part II)

Expert Advisor featuring GUI: Adding functionality (part II)

This is the second part of the article showing the development of a multi-symbol signal Expert Advisor for manual trading. We have already created the graphical interface. It is now time to connect it with the program's functionality.
Integrating MQL-based Expert Advisors and databases (SQL Server, .NET and C#)
Integrating MQL-based Expert Advisors and databases (SQL Server, .NET and C#)

Integrating MQL-based Expert Advisors and databases (SQL Server, .NET and C#)

The article describes how to add the ability to work with Microsoft SQL Server database server to MQL5-based Expert Advisors. Import of functions from a DLL is used. The DLL is created using the Microsoft .NET platform and the C# language. The methods used in the article are also suitable for experts written in MQL4, with minor adjustments.
Visualizing optimization results using a selected criterion
Visualizing optimization results using a selected criterion

Visualizing optimization results using a selected criterion

In the article, we continue to develop the MQL application for working with optimization results. This time, we will show how to form the table of the best results after optimizing the parameters by specifying another criterion via the graphical interface.
Testing currency pair patterns: Practical application and real trading perspectives. Part IV
Testing currency pair patterns: Practical application and real trading perspectives. Part IV

Testing currency pair patterns: Practical application and real trading perspectives. Part IV

This article concludes the series devoted to trading currency pair baskets. Here we test the remaining pattern and discuss applying the entire method in real trading. Market entries and exits, searching for patterns and analyzing them, complex use of combined indicators are considered.
Deep Neural Networks (Part VII). Ensemble of neural networks: stacking
Deep Neural Networks (Part VII). Ensemble of neural networks: stacking

Deep Neural Networks (Part VII). Ensemble of neural networks: stacking

We continue to build ensembles. This time, the bagging ensemble created earlier will be supplemented with a trainable combiner — a deep neural network. One neural network combines the 7 best ensemble outputs after pruning. The second one takes all 500 outputs of the ensemble as input, prunes and combines them. The neural networks will be built using the keras/TensorFlow package for Python. The features of the package will be briefly considered. Testing will be performed and the classification quality of bagging and stacking ensembles will be compared.
How to create Requirements Specification for ordering a trading robot
How to create Requirements Specification for ordering a trading robot

How to create Requirements Specification for ordering a trading robot

Are you trading using your own strategy? If your system rules can be formally described as software algorithms, it is better to entrust trading to an automated Expert Advisor. A robot does not need sleep or food and is not subject to human weaknesses. In this article, we show how to create Requirements Specification when ordering a trading robot in the Freelance service.
Implementing indicator calculations into an Expert Advisor code
Implementing indicator calculations into an Expert Advisor code

Implementing indicator calculations into an Expert Advisor code

The reasons for moving an indicator code to an Expert Advisor may vary. How to assess the pros and cons of this approach? The article describes implementing an indicator code into an EA. Several experiments are conducted to assess the speed of the EA's operation.
Comparative analysis of 10 flat trading strategies
Comparative analysis of 10 flat trading strategies

Comparative analysis of 10 flat trading strategies

The article explores the advantages and disadvantages of trading in flat periods. The ten strategies created and tested within this article are based on the tracking of price movements inside a channel. Each strategy is provided with a filtering mechanism, which is aimed at avoiding false market entry signals.
Applying the Monte Carlo method for optimizing trading strategies
Applying the Monte Carlo method for optimizing trading strategies

Applying the Monte Carlo method for optimizing trading strategies

Before launching a robot on a trading account, we usually test and optimize it on quotes history. However, a reasonable question arises: how can past results help us in the future? The article describes applying the Monte Carlo method to construct custom criteria for trading strategy optimization. In addition, the EA stability criteria are considered.
Deep Neural Networks (Part VI). Ensemble of neural network classifiers: bagging
Deep Neural Networks (Part VI). Ensemble of neural network classifiers: bagging

Deep Neural Networks (Part VI). Ensemble of neural network classifiers: bagging

The article discusses the methods for building and training ensembles of neural networks with bagging structure. It also determines the peculiarities of hyperparameter optimization for individual neural network classifiers that make up the ensemble. The quality of the optimized neural network obtained in the previous article of the series is compared with the quality of the created ensemble of neural networks. Possibilities of further improving the quality of the ensemble's classification are considered.
Expert Advisor featuring GUI: Creating the panel (part I)
Expert Advisor featuring GUI: Creating the panel (part I)

Expert Advisor featuring GUI: Creating the panel (part I)

Despite the fact that many traders still prefer manual trading, it is hardly possible to completely avoid the automation of routine operations. The article shows an example of developing a multi-symbol signal Expert Advisor for manual trading.
How to analyze the trades of the Signal selected in the chart
How to analyze the trades of the Signal selected in the chart

How to analyze the trades of the Signal selected in the chart

The trade Signals service develops in leaps and bounds. Trusting our funds to a signal provider, we would like to minimize the risk of losing our deposit. So how to puzzle out in this forest of trade signals? How to find the one that would produce profits? This paper proposes to create a tool for visually analyzing the history of trades on trade signals in a symbol chart.
Improving Panels: Adding transparency, changing background color and inheriting from CAppDialog/CWndClient
Improving Panels: Adding transparency, changing background color and inheriting from CAppDialog/CWndClient

Improving Panels: Adding transparency, changing background color and inheriting from CAppDialog/CWndClient

In this article, we continue studying the use of CAppDialog. Now we will learn how to set color for the background, borders and header of the dialog box. Also, this article provides a step-by-step description of how to add transparency for an application window when dragging it within the chart. We will consider how to create child classes of CAppDialog or CWndClient and analyze new specifics of working with controls. Finally, we will review new Projects from a new perspective.