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
Analyzing Candlestick Patterns
Analyzing Candlestick Patterns

Analyzing Candlestick Patterns

Construction of Japanese candlestick chart and analysis of candlestick patterns constitute an amazing area of technical analysis. The advantage of candlesticks is that they represent data in such a manner that you can track the dynamics inside the data. In this article we analyze candlestick types, classification of candlestick patterns and present an indicator that can determine candlestick patterns.
Controlling the Slope of Balance Curve During Work of an Expert Advisor
Controlling the Slope of Balance Curve During Work of an Expert Advisor

Controlling the Slope of Balance Curve During Work of an Expert Advisor

Finding rules for a trade system and programming them in an Expert Advisor is a half of the job. Somehow, you need to correct the operation of the Expert Advisor as it accumulates the results of trading. This article describes one of approaches, which allows improving performance of an Expert Advisor through creation of a feedback that measures slope of the balance curve.
Adaptive Trading Systems and Their Use in the MetaTrader 5 Client Terminal
Adaptive Trading Systems and Their Use in the MetaTrader 5 Client Terminal

Adaptive Trading Systems and Their Use in the MetaTrader 5 Client Terminal

This article suggests a variant of an adaptive system that consists of many strategies, each of which performs its own "virtual" trade operations. Real trading is performed in accordance with the signals of a most profitable strategy at the moment. Thanks to using of the object-oriented approach, classes for working with data and trade classes of the Standard library, the architecture of the system appeared to be simple and scalable; now you can easily create and analyze the adaptive systems that include hundreds of trade strategies.
Several Ways of Finding a Trend in MQL5
Several Ways of Finding a Trend in MQL5

Several Ways of Finding a Trend in MQL5

Any trader would give a lot for opportunity to accurately detect a trend at any given time. Perhaps, this is the Holy Grail that everyone is looking for. In this article we will consider several ways to detect a trend. To be more precise - how to program several classical ways to detect a trend by means of MQL5.
Interview with Alexander Topchylo (ATC 2010)
Interview with Alexander Topchylo (ATC 2010)

Interview with Alexander Topchylo (ATC 2010)

Alexander Topchylo (Better) is the winner of the Automated Trading Championship 2007. Alexander is an expert in neural networks - his Expert Advisor based on a neural network was on top of best EAs of year 2007. In this interview Alexander tells us about his life after the Championships, his own business and new algorithms for trading systems.
Using the TesterWithdrawal() Function for Modeling the Withdrawals of Profit
Using the TesterWithdrawal() Function for Modeling the Withdrawals of Profit

Using the TesterWithdrawal() Function for Modeling the Withdrawals of Profit

This article describes the usage of the TesterWithDrawal() function for estimating risks in trade systems which imply the withdrawing of a certain part of assets during their operation. In addition, it describes the effect of this function on the algorithm of calculation of the drawdown of equity in the strategy tester. This function is useful when optimizing parameter of your Expert Advisors.
How to Quickly Create an Expert Advisor for Automated Trading Championship 2010
How to Quickly Create an Expert Advisor for Automated Trading Championship 2010

How to Quickly Create an Expert Advisor for Automated Trading Championship 2010

In order to develop an expert to participate in Automated Trading Championship 2010, let's use a template of ready expert advisor. Even novice MQL5 programmer will be capable of this task, because for your strategies the basic classes, functions, templates are already developed. It's enough to write a minimal amount of code to implement your trading idea.
20 Trade Signals in MQL5
20 Trade Signals in MQL5

20 Trade Signals in MQL5

This article will teach you how to receive trade signals that are necessary for a trade system to work. The examples of forming 20 trade signals are given here as separate custom functions that can be used while developing Expert Advisors. For your convenience, all the functions used in the article are combined in a single mqh include file that can be easily connected to a future Expert Advisor.
The Prototype of a Trading Robot
The Prototype of a Trading Robot

The Prototype of a Trading Robot

This article summarizes and systematizes the principles of creating algorithms and elements of trading systems. The article considers designing of expert algorithm. As an example the CExpertAdvisor class is considered, which can be used for quick and easy development of trading systems.
Interview with Leonid Velichkovsky: "The Biggest Myth about Neural Networks is Super-Profitability" (ATC 2010)
Interview with Leonid Velichkovsky: "The Biggest Myth about Neural Networks is Super-Profitability" (ATC 2010)

Interview with Leonid Velichkovsky: "The Biggest Myth about Neural Networks is Super-Profitability" (ATC 2010)

The hero of our interview Leonid Velichkovski (LeoV) has already participated in Automated Trading Championships. In 2008, his multicurrency neural network was like a bright flash in the sky, earning $110,000 in a certain moment, but eventually fell victim to its own aggressive money management. Two years ago, in his interview Leonid share his own trading experience and told us about the features of his Expert Advisor. On the eve of the ATC 2010, Leonid talks about the most common myths and misconceptions associated with neural networks.
How to Create Your Own Trailing Stop
How to Create Your Own Trailing Stop

How to Create Your Own Trailing Stop

The basic rule of trader - let profit to grow, cut off losses! This article considers one of the basic techniques, allowing to follow this rule - moving the protective stop level (Stop loss level) after increasing position profit, i.e. - Trailing Stop level. You'll find the step by step procedure to create a class for trailing stop on SAR and NRTR indicators. Everyone will be able to insert this trailing stop into their experts or use it independently to control positions in their accounts.
MetaTrader 5 and MATLAB Interaction
MetaTrader 5 and MATLAB Interaction

MetaTrader 5 and MATLAB Interaction

This article covers the details of interaction between MetaTrader 5 and MatLab mathematical package. It shows the mechanism of data conversion, the process of developing a universal library to interact with MatLab desktop. It also covers the use of DLL generated by MatLab environment. This article is intended for experienced readers, who know C++ and MQL5.
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.
Creating Multi-Colored Indicators in MQL5
Creating Multi-Colored Indicators in MQL5

Creating Multi-Colored Indicators in MQL5

In this article, we will consider how to create multi-colored indicators or convert the existing ones to multi-color. MQL5 allows to represent the information in the convenient form. Now it isn't necessary to look at a dozen of charts with indicators and perform analyses of the RSI or Stochastic levels, it's better just to paint the candles with different colors depending on the values of the indicators.
Creating and Publishing of Trade Reports and SMS Notification
Creating and Publishing of Trade Reports and SMS Notification

Creating and Publishing of Trade Reports and SMS Notification

Traders don't always have ability and desire to seat at the trading terminal for hours. Especially, if trading system is more or less formalized and can automatically identify some of the market states. This article describes how to generate a report of trade results (using Expert Advisor, Indicator or Script) as HTML-file and upload it via FTP to WWW-server. We will also consider sending notification of trade events as SMS to mobile phone.
Transferring Indicators from MQL4 to MQL5
Transferring Indicators from MQL4 to MQL5

Transferring Indicators from MQL4 to MQL5

This article is dedicated to peculiarities of transferring price constructions written in MQL4 to MQL5. To make the process of transferring indicator calculations from MQL4 to MQL5 easier, the mql4_2_mql5.mqh library of functions is suggested. Its usage is described on the basis of transferring of the MACD, Stochastic and RSI indicators.
The Optimal Method for Calculation of Total Position Volume by Specified Magic Number
The Optimal Method for Calculation of Total Position Volume by Specified Magic Number

The Optimal Method for Calculation of Total Position Volume by Specified Magic Number

The problem of calculation of the total position volume of the specified symbol and magic number is considered in this article. The proposed method requests only the minimum necessary part of the history of deals, finds the closest time when the total position was equal to zero, and performs the calculations with the recent deals. Working with global variables of the client terminal is also considered.
Interview with Nikolay Kositsin: multicurrency EA are less risky (ATC 2010)
Interview with Nikolay Kositsin: multicurrency EA are less risky (ATC 2010)

Interview with Nikolay Kositsin: multicurrency EA are less risky (ATC 2010)

Nikolay Kositsin has told us about his developments. He believes multicurrency Expert Advisors are a promising direction; and he is an experienced developer of such robots. At the championships, Nikolay participates only with multicurrency EAs. His Expert Advisor was the only multicurrency EA among the prize winners of all the ATC contests.
How to Write an Indicator on the Basis of Another Indicator
How to Write an Indicator on the Basis of Another Indicator

How to Write an Indicator on the Basis of Another Indicator

In MQL5 you can write an indicator both from a scratch and on the basis of another already existing indicator, in-built in the client terminal or a custom one. And here you also have two ways - to improve an indicator by adding new calculations and graphical styles to it , or to use an indicator in-built in the client terminal or a custom one via the iCustom() or IndicatorCreate() functions.
Testing Performance of Moving Averages Calculation in MQL5
Testing Performance of Moving Averages Calculation in MQL5

Testing Performance of Moving Averages Calculation in MQL5

A number of indicators have appeared since the time of first Moving Average indicator creation. Many of them use the similar smoothing methods, but the performances of different moving averages algorithms have not been studied. In this article, we will consider possible ways of use the Moving Averages in MQL5 and compare their performance.
Processing of trade events in Expert Advisor using the OnTrade() function
Processing of trade events in Expert Advisor using the OnTrade() function

Processing of trade events in Expert Advisor using the OnTrade() function

MQL5 gave a mass of innovations, including work with events of various types (timer events, trade events, custom events, etc.). Ability to handle events allows you to create completely new type of programs for automatic and semi-automatic trading. In this article we will consider trade events and write some code for the OnTrade() function, that will process the Trade event.
The Use of ORDER_MAGIC for Trading with Different Expert Advisors on a Single Instrument
The Use of ORDER_MAGIC for Trading with Different Expert Advisors on a Single Instrument

The Use of ORDER_MAGIC for Trading with Different Expert Advisors on a Single Instrument

This article considers the questions of information coding, using the magic-identification, as well as the division, assembly, and synchronization of automatic trading of different Expert Advisors. This article will be interesting to beginners, as well as to more experienced traders, because it tackles the question of virtual positions, which can be useful in the implementation of complex systems of synchronization of Expert Advisors and various strategies.
A Library for Constructing a Chart via Google Chart API
A Library for Constructing a Chart via Google Chart API

A Library for Constructing a Chart via Google Chart API

The construction of various types of diagrams is an essential part of the analyses of the market situation and the testing of a trading system. Frequently, in order to construct a nice looking diagram, it is necessary to organize the data output into a file, after which it is used in applications such as MS Excel. This is not very convenient and deprives us of the ability to dynamically update the data. Google Charts API provided the means for creating charts in online modes, by sending a special request to the server. In this article we attempt to automate the process of creating such a request and obtaining a chart from the Google server.
The Principles of Economic Calculation of Indicators
The Principles of Economic Calculation of Indicators

The Principles of Economic Calculation of Indicators

Calls to user and technical indicators takes up very little space in the program code of automated trading systems. Often it’s simply a few code lines. But it often happens that it is these few lines of code which use up the largest portion of time, which needs to be spent on testing the Expert Advisor. Therefore, everything that is related to data calculations within an indicator, needs to be considered much more thoroughly than would seem at first glance. This article will talk precisely about this.
How to Order a Trading Robot in MQL5 and MQL4
How to Order a Trading Robot in MQL5 and MQL4

How to Order a Trading Robot in MQL5 and MQL4

"Freelance" is the largest freelance service for ordering MQL4/MQL5 trading robots and technical indicators. Hundreds of professional developers are ready to develop a custom trading application for the MetaTrader 4/5 terminal.
Writing an Expert Advisor Using the MQL5 Object-Oriented Programming Approach
Writing an Expert Advisor Using the MQL5 Object-Oriented Programming Approach

Writing an Expert Advisor Using the MQL5 Object-Oriented Programming Approach

This article focuses on the object oriented approach to doing what we did in the article "Step-By-Step Guide to writing an Expert Advisor in MQL5 for Beginners" - creating a simple Expert Advisor. Most people think this is difficult, but I want to assure you that by the time you finish reading this article, you will be able to write your own Expert Advisor which is object oriented based.
Functions for Money Management in an Expert Advisor
Functions for Money Management in an Expert Advisor

Functions for Money Management in an Expert Advisor

The development of trading strategies primarily focuses on searching for patterns for entering and exiting the market, as well as maintaining positions. If we are able to formalize some patterns into rules for automated trading, then the trader faces the question of calculating the volume of positions, the size of the margins, as well as maintaining a safe level of mortgage funds for assuring open positions in an automated mode. In this article we will use the MQL5 language to construct simple examples of conducting these calculations.
Creating an Expert Advisor, which Trades on a Number of Instruments
Creating an Expert Advisor, which Trades on a Number of Instruments

Creating an Expert Advisor, which Trades on a Number of Instruments

The concept of diversification of assets on financial markets is quiet old, and has always attracted beginner traders. In this article, the author proposes a maximally simple approach to a construction of a multi-currency Expert Advisor, for an initial introduction to this direction of trading strategies.
Creating Information Boards Using Standard Library Classes and Google Chart API
Creating Information Boards Using Standard Library Classes and Google Chart API

Creating Information Boards Using Standard Library Classes and Google Chart API

The MQL5 programming language primarily targets the creation of automated trading systems and complex instruments of technical analyses. But aside from this, it allows us to create interesting information systems for tracking market situations, and provides a return connection with the trader. The article describes the MQL5 Standard Library components, and shows examples of their use in practice for reaching these objectives. It also demonstrates an example of using Google Chart API for the creation of charts.
Genetic Algorithms - It's Easy!
Genetic Algorithms - It's Easy!

Genetic Algorithms - It's Easy!

In this article the author talks about evolutionary calculations with the use of a personally developed genetic algorithm. He demonstrates the functioning of the algorithm, using examples, and provides practical recommendations for its usage.
A DLL-free solution to communicate between MetaTrader 5 terminals using Named Pipes
A DLL-free solution to communicate between MetaTrader 5 terminals using Named Pipes

A DLL-free solution to communicate between MetaTrader 5 terminals using Named Pipes

The article describes how to implement Interprocess Communication between MetaTrader 5 client terminals using named pipes. For the use of the named pipes, the CNamedPipes class is developed. For the test of its use and to measure the connection throughput, the tick indicator, the server and client scripts are presented. The use of named pipes is sufficient for real-time quotes.
Guide to writing a DLL for MQL5 in Delphi
Guide to writing a DLL for MQL5 in Delphi

Guide to writing a DLL for MQL5 in Delphi

The article examines the mechanism of creating a DLL module, using the popular programming language of ObjectPascal, within a Delphi programming environment. The materials, provided in this article, are designed to primarily target beginner programmers, who are working with problems, which breach the boundaries of the embedded programming language of MQL5, by connecting the outside DLL modules.
An Example of a Trading System Based on a Heiken-Ashi Indicator
An Example of a Trading System Based on a Heiken-Ashi Indicator

An Example of a Trading System Based on a Heiken-Ashi Indicator

In this article we look into the question of using a Heiken-Ashi indicator in trading. Based on this indicator, a simple trading system is considered and an MQL5 Expert Advisor is written. Trading operations are implemented on the bases of classes of the Standard class library. The testing results of the reviewed trading strategy, are based on the history, and obtained using the built-in MetaTrader 5 strategy tester, are provided in the article.
Using WinInet.dll for Data Exchange between Terminals via the Internet
Using WinInet.dll for Data Exchange between Terminals via the Internet

Using WinInet.dll for Data Exchange between Terminals via the Internet

This article describes the principles of working with the Internet via the use of HTTP requests, and data exchange between terminals, using an intermediate server. An MqlNet library class is presented for working with Internet resources in the MQL5 environment. Monitoring prices from different brokers, exchanging messages with other traders without exiting the terminal, searching for information on the Internet – these are just some examples, reviewed in this article.
Creating a Multi-Currency Indicator, Using a Number of Intermediate Indicator Buffers
Creating a Multi-Currency Indicator, Using a Number of Intermediate Indicator Buffers

Creating a Multi-Currency Indicator, Using a Number of Intermediate Indicator Buffers

There has been a recent rise of interest in the cluster analyses of the FOREX market. MQL5 opens up new possibilities of researching the trends of the movement of currency pairs. A key feature of MQL5, differentiating it from MQL4, is the possibility of using an unlimited amount of indicator buffers. This article describes an example of the creation of a multi-currency indicator.
Step-By-Step Guide to writing an Expert Advisor in MQL5 for Beginners
Step-By-Step Guide to writing an Expert Advisor in MQL5 for Beginners

Step-By-Step Guide to writing an Expert Advisor in MQL5 for Beginners

The Expert Advisors programming in MQL5 is simple, and you can learn it easy. In this step by step guide, you will see the basic steps required in writing a simple Expert Advisor based on a developed trading strategy. The structure of an Expert Advisor, the use of built-in technical indicators and trading functions, the details of the Debug mode and use of the Strategy Tester are presented.
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.
Connection of Expert Advisor with ICQ in MQL5
Connection of Expert Advisor with ICQ in MQL5

Connection of Expert Advisor with ICQ in MQL5

This article describes the method of information exchange between the Expert Advisor and ICQ users, several examples are presented. The provided material will be interesting for those, who wish to receive trading information remotely from a client terminal, through an ICQ client in their mobile phone or PDA.
New Opportunities with MetaTrader 5
New Opportunities with MetaTrader 5

New Opportunities with MetaTrader 5

MetaTrader 4 gained its popularity with traders from all over the world, and it seemed like nothing more could be wished for. With its high processing speed, stability, wide array of possibilities for writing indicators, Expert Advisors, and informatory-trading systems, and the ability to chose from over a hundred different brokers, - the terminal greatly distinguished itself from the rest. But time doesn’t stand still, and we find ourselves facing a choice of MetaTrade 4 or MetaTrade 5. In this article, we will describe the main differences of the 5th generation terminal from our current favor.
The Algorithm of Ticks' Generation within the Strategy Tester of the MetaTrader 5 Terminal
The Algorithm of Ticks' Generation within the Strategy Tester of the MetaTrader 5 Terminal

The Algorithm of Ticks' Generation within the Strategy Tester of the MetaTrader 5 Terminal

MetaTrader 5 allows us to simulate automatic trading, within an embedded strategy tester, by using Expert Advisors and the MQL5 language. This type of simulation is called testing of Expert Advisors, and can be implemented using multithreaded optimization, as well as simultaneously on a number of instruments. In order to provide a thorough testing, a generation of ticks based on the available minute history, needs to be performed. This article provides a detailed description of the algorithm, by which the ticks are generated for the historical testing in the MetaTrader 5 client terminal.