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
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.
Cross-Platform Expert Advisor: Orders
Cross-Platform Expert Advisor: Orders

Cross-Platform Expert Advisor: Orders

MetaTrader 4 and MetaTrader 5 uses different conventions in processing trade requests. This article discusses the possibility of using a class object that can be used to represent the trades processed by the server, in order for a cross-platform expert advisor to further work on them, regardless of the version of the trading platform and mode being used.
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.
Practical evaluation of the adaptive market following method
Practical evaluation of the adaptive market following method

Practical evaluation of the adaptive market following method

The main difference of the trading system proposed in the article is the use of mathematical tools for analyzing stock quotes. The system applies digital filtering and spectral estimation of discrete time series. The theoretical aspects of the strategy are described and a test Expert Advisor is created.
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.
Timeseries in DoEasy library (part 40): Library-based indicators - updating data in real time
Timeseries in DoEasy library (part 40): Library-based indicators - updating data in real time

Timeseries in DoEasy library (part 40): Library-based indicators - updating data in real time

The article considers the development of a simple multi-period indicator based on the DoEasy library. Let's improve the timeseries classes to receive data from any timeframes to display it on the current chart period.
Indicator for Kagi Charting
Indicator for Kagi Charting

Indicator for Kagi Charting

The article proposes Kagi chart indicator with various charting options and additional functions. Also, indicator charting principle and its MQL5 implementation features are considered. The most popular cases of its implementation in trading are displayed - Yin/Yang exchange strategy, pushing away from the trend line and consistently increasing "shoulders"/decreasing "waists".
Creating a new trading strategy using a technology of resolving entries into indicators
Creating a new trading strategy using a technology of resolving entries into indicators

Creating a new trading strategy using a technology of resolving entries into indicators

The article suggests a technology helping everyone to create custom trading strategies by assembling an individual indicator set, as well as to develop custom market entry signals.
The Simple Example of Creating an Indicator Using Fuzzy Logic
The Simple Example of Creating an Indicator Using Fuzzy Logic

The Simple Example of Creating an Indicator Using Fuzzy Logic

The article is devoted to the practical application of the fuzzy logic concept for financial markets analysis. We propose the example of the indicator generating signals based on two fuzzy rules based on Envelopes indicator. The developed indicator uses several indicator buffers: 7 buffers for calculations, 5 buffers for the charts display and 2 color buffers.
The NRTR indicator and trading modules based on NRTR for the MQL5 Wizard
The NRTR indicator and trading modules based on NRTR for the MQL5 Wizard

The NRTR indicator and trading modules based on NRTR for the MQL5 Wizard

In this article we are going to analyze the NRTR indicator and create a trading system based on this indicator. We are going to develop a module of trading signals that can be used in creating strategies based on a combination of NRTR with additional trend confirmation indicators.
Universal Expert Advisor: Pending Orders and Hedging Support (Part 5)
Universal Expert Advisor: Pending Orders and Hedging Support (Part 5)

Universal Expert Advisor: Pending Orders and Hedging Support (Part 5)

This article provides further description of the CStrategy trading engine. By popular demand of users, we have added pending order support functions to the trading engine. Also, the latest version of the MetaTrader 5 now supports accounts with the hedging option. The same support has been added to CStrategy. The article provides a detailed description of algorithms for the use of pending orders, as well as of CStrategy operation principles on accounts with the hedging option enabled.
Random Forests Predict Trends
Random Forests Predict Trends

Random Forests Predict Trends

This article considers using the Rattle package for automatic search of patterns for predicting long and short positions of currency pairs on Forex. This article can be useful both for novice and experienced traders.
Cross-Platform Expert Advisor: Order Manager
Cross-Platform Expert Advisor: Order Manager

Cross-Platform Expert Advisor: Order Manager

This article discusses the creation of an order manager for a cross-platform expert advisor. The order manager is responsible for the entry and exit of orders or positions entered by the expert, as well as for keeping an independent record of such trades that is usable for both versions.
Learn how to design a trading system by Envelopes
Learn how to design a trading system by Envelopes

Learn how to design a trading system by Envelopes

In this article, I will share with you one of the methods of how to trade bands. This time we will consider Envelopes and will see how easy it is to create some strategies based on the Envelopes.
A New Approach to Interpreting Classic and Hidden Divergence. Part II
A New Approach to Interpreting Classic and Hidden Divergence. Part II

A New Approach to Interpreting Classic and Hidden Divergence. Part II

The article provides a critical examination of regular divergence and efficiency of various indicators. In addition, it contains filtering options for an increased analysis accuracy and features description of non-standard solutions. As a result, we will create a new tool for solving the technical task.
Graphical Interfaces I: Animating the Graphical Interface (Chapter 3)
Graphical Interfaces I: Animating the Graphical Interface (Chapter 3)

Graphical Interfaces I: Animating the Graphical Interface (Chapter 3)

In the previous article, we started developing a form class for controls. In this article, we are going to continue doing that by filling this class with methods for moving a form over the chart area. We will then integrate this interface component into the core of the library. Also, we will ensure that the color of a form control changes when the mouse cursor is hovering over it.
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.
Finding Errors and Logging
Finding Errors and Logging

Finding Errors and Logging

MetaEditor 5 has the debugging feature. But when you write your MQL5 programs, you often want to display not the individual values, but all messages that appear during testing and online work. When the log file contents have large size, it is obvious to automate quick and easy retrieval of required message. In this article we will consider ways of finding errors in MQL5 programs and methods of logging. Also we will simplify logging into files and will get to know a simple program LogMon for comfortable viewing of logs.
MQL5 Wizard: How to Teach an EA to Open Pending Orders at Any Price
MQL5 Wizard: How to Teach an EA to Open Pending Orders at Any Price

MQL5 Wizard: How to Teach an EA to Open Pending Orders at Any Price

The article describes a method of modifying the code of a trading signal module for the implementation of the functionality allowing you to set pending orders at any distance from the current price: it may be the Close or Open price of the previous bar or the value of the moving average. There are plenty of options. Important is that you can set any opening price for a pending order. This article will be useful to traders who trade with pending orders.
Timeseries in DoEasy library (part 41): Sample multi-symbol multi-period indicator
Timeseries in DoEasy library (part 41): Sample multi-symbol multi-period indicator

Timeseries in DoEasy library (part 41): Sample multi-symbol multi-period indicator

In the article, we will consider a sample multi-symbol multi-period indicator using the timeseries classes of the DoEasy library displaying the chart of a selected currency pair on a selected timeframe as candles in a subwindow. I am going to modify the library classes a bit and create a separate file for storing enumerations for program inputs and selecting a compilation language.
Limitations and Verifications in Expert Advisors
Limitations and Verifications in Expert Advisors

Limitations and Verifications in Expert Advisors

Is it allowed to trade this symbol on Monday? Is there enough money to open position? How big is the loss if Stop Loss triggers? How to limit the number of pending orders? Was the trade operation executed at the current bar or at the previous one? If a trade robot cannot perform this kind of verifications, then any trade strategy can turn into a losing one. This article shows the examples of verifications that are useful in any Expert Advisor.
preview
Practical application of neural networks in trading. It's time to practice

Practical application of neural networks in trading. It's time to practice

The article provides a description and instructions for the practical use of neural network modules on the Matlab platform. It also covers the main aspects of creation of a trading system using the neural network module. In order to be able to introduce the complex within one article, I had to modify it so as to combine several neural network module functions in one program.
MQL5 Cookbook: Using Indicators to Set Trading Conditions in Expert Advisors
MQL5 Cookbook: Using Indicators to Set Trading Conditions in Expert Advisors

MQL5 Cookbook: Using Indicators to Set Trading Conditions in Expert Advisors

In this article, we will continue to modify the Expert Advisor we have been working on throughout the preceding articles of the MQL5 Cookbook series. This time, the Expert Advisor will be enhanced with indicators whose values will be used to check position opening conditions. To spice it up, we will create a drop-down list in the external parameters to be able to select one out of three trading indicators.
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.
Applying the probability theory to trading gaps
Applying the probability theory to trading gaps

Applying the probability theory to trading gaps

In this article, we will apply the probability theory and mathematical statistics methods to creating and testing trading strategies. We will also look for optimal trading risk using the differences between the price and the random walk. It is proved that if prices behave like a zero-drift random walk (with no directional trend), then profitable trading is impossible.
preview
How to master Machine Learning

How to master Machine Learning

Check out this selection of useful materials which can assist traders in improving their algorithmic trading knowledge. The era of simple algorithms is passing, and it is becoming harder to succeed without the use of Machine Learning techniques and Neural Networks.
An Example of a Trading Strategy Based on Timezone Differences on Different Continents
An Example of a Trading Strategy Based on Timezone Differences on Different Continents

An Example of a Trading Strategy Based on Timezone Differences on Different Continents

Surfing the Internet, it is easy to find many strategies, which will give you a number of various recommendations. Let’s take an insider’s approach and look into the process of strategy creation, based on the differences in timezones on different continents.
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.
Graphical Interfaces III: Simple and Multi-Functional Buttons (Chapter 1)
Graphical Interfaces III: Simple and Multi-Functional Buttons (Chapter 1)

Graphical Interfaces III: Simple and Multi-Functional Buttons (Chapter 1)

Let us consider the button control. We will discuss examples of several classes for creating a simple button, buttons with extended functionality (icon button and split button) and interconnected buttons (button groups and radio button). Added to that, we will introduce some additions to existing classes for controls to broaden their capability.
Use MQL5.community channels and group chats
Use MQL5.community channels and group chats

Use MQL5.community channels and group chats

The MQL5.com website brings together traders from all over the world. Users publish articles, share free codes, sell products in the Market, perform Freelance orders and copy trading signals. You can communicate with them on the Forum, in trader chats and in MetaTrader channels.
Time Series Forecasting Using Exponential Smoothing (continued)
Time Series Forecasting Using Exponential Smoothing (continued)

Time Series Forecasting Using Exponential Smoothing (continued)

This article seeks to upgrade the indicator created earlier on and briefly deals with a method for estimating forecast confidence intervals using bootstrapping and quantiles. As a result, we will get the forecast indicator and scripts to be used for estimation of the forecast accuracy.
R-squared as an estimation of quality of the strategy balance curve
R-squared as an estimation of quality of the strategy balance curve

R-squared as an estimation of quality of the strategy balance curve

This article describes the construction of the custom optimization criterion R-squared. This criterion can be used to estimate the quality of a strategy's balance curve and to select the most smoothly growing and stable strategies. The work discusses the principles of its construction and statistical methods used in estimation of properties and quality of this metric.
MQL5 Wizard: How to Create a Risk and Money Management Module
MQL5 Wizard: How to Create a Risk and Money Management Module

MQL5 Wizard: How to Create a Risk and Money Management Module

The generator of trading strategies of the MQL5 Wizard greatly simplifies testing of trading ideas. The article describes how to develop a custom risk and money management module and enable it in the MQL5 Wizard. As an example we've considered a money management algorithm, in which the size of the trade volume is determined by the results of the previous deal. The structure and format of description of the created class for the MQL5 Wizard are also discussed in the article.
How to Write a Good Description for a Market Product
How to Write a Good Description for a Market Product

How to Write a Good Description for a Market Product

MQL5 Market has many products for sale but some of their descriptions leave much to be desired. Many texts are obviously in need of improvement, as common traders are not able to comprehend them. This article will help you to put your product in a favorable light. Use our recommendations to write an eye-catching description that will easily show your customers what exactly you are selling.
LifeHack for Trader: A comparative report of several tests
LifeHack for Trader: A comparative report of several tests

LifeHack for Trader: A comparative report of several tests

The article deals with the simultaneous launch of Expert Advisor testing on four different trading instruments. The final comparison of four testing reports is provided in a table similar to how goods are represented in online stores. An additional bonus is that distribution charts will be automatically created for each symbol.
Graphics in DoEasy library (Part 75): Methods of handling primitives and text in the basic graphical element
Graphics in DoEasy library (Part 75): Methods of handling primitives and text in the basic graphical element

Graphics in DoEasy library (Part 75): Methods of handling primitives and text in the basic graphical element

In this article, I will continue the development of the basic graphical element class of all library graphical objects powered by the CCanvas Standard Library class. I will create the methods for drawing graphical primitives and for displaying a text on a graphical element object.
Using WinInet in MQL5.  Part 2:  POST Requests and Files
Using WinInet in MQL5.  Part 2:  POST Requests and Files

Using WinInet in MQL5. Part 2: POST Requests and Files

In this article, we continue studying the principles of working with Internet using HTTP requests and exchange of information with server. It describes new functions of the CMqlNet class, methods of sending information from forms and sending of files using POST requests as well as authorization on websites under your login using Cookies.
Analyzing trading results using HTML reports
Analyzing trading results using HTML reports

Analyzing trading results using HTML reports

The MetaTrader 5 platform features functionality for saving trading reports, as well as Expert Advisor testing and optimization reports. Trading and testing reports can be saved in two formats: XLSX and HTML, while the optimization report can be saved in XML. In this article we consider the HTML testing report, the XML optimization report and the HTML trading history report.
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.
Library for easy and quick development of MetaTrader programs (part XXV): Handling errors returned by the trade server
Library for easy and quick development of MetaTrader programs (part XXV): Handling errors returned by the trade server

Library for easy and quick development of MetaTrader programs (part XXV): Handling errors returned by the trade server

After we send a trading order to the server, we need to check the error codes or the absence of errors. In this article, we will consider handling errors returned by the trade server and prepare for creating pending trading requests.