MQL4 and MQL5 Programming Articles

icon

Study the MQL5 language for programming trading strategies in numerous published articles mostly written by you - the community members. The articles are grouped into categories to help you quicker find answers to any questions related to programming: Integration, Tester, Trading Strategies, etc.

Follow our new publications and discuss them on the Forum!

Add a new article
latest | best
Andrey Voitenko: Programming errors cost me $15,000 (ATC 2010)
Andrey Voitenko: Programming errors cost me $15,000 (ATC 2010)

Andrey Voitenko: Programming errors cost me $15,000 (ATC 2010)

Andrey Voitenko is participating in the Automated Trading Championship for the first time, but his Expert Advisor is showing mature trading. For already several weeks Andrey's Expert Advisors has been listed in the top ten and seems to be continuing his positive performance. In this interview Andrey is telling about his EA's features, errors and the price they cost him.
Creating an Indicator with Multiple Indicator Buffers for Newbies
Creating an Indicator with Multiple Indicator Buffers for Newbies

Creating an Indicator with Multiple Indicator Buffers for Newbies

The complex codes consist of a set of simple codes. If you are familiar with them, it doesn't look so complicated. In this article, we will consider how to create an indicator with multiple indicator buffers. As an example, the Aroon indicator is analyzed in details, and two different versions of the code are presented.
Tomasz Tauzowski:"All I can do is pray for a loss position" (ATC 2010)
Tomasz Tauzowski:"All I can do is pray for a loss position" (ATC 2010)

Tomasz Tauzowski:"All I can do is pray for a loss position" (ATC 2010)

Tomasz Tauzowski (ttauzo) is a long-standing member of the top ten on the Automated Trading Championship 2010. For the seventh week his Expert Advisor is between the fifth and the seventh places. And no wonder: according to the report of the current Championship leader Boris Odinstov, ttauzo is one of the most stable EAs participating in the competition.
Simulink: a Guide for the Developers of Expert Advisors
Simulink: a Guide for the Developers of Expert Advisors

Simulink: a Guide for the Developers of Expert Advisors

I am not a professional programmer. And thus, the principle of "going from the simple to the complex" is of primary importance to me when I am working on trading system development. What exactly is simple for me? First of all, it is the visualization of the process of creating the system, and the logic of its work. Also, it is a minimum of handwritten code. In this article, I will attempt to create and test the trading system, based on a Matlab package, and then write an Expert Advisor for MetaTrader 5. The historical data from MetaTrader 5 will be used for the testing process.
Dimitar Manov: "I fear only extraordinary situations in the Championship" (ATC 2010)
Dimitar Manov: "I fear only extraordinary situations in the Championship" (ATC 2010)

Dimitar Manov: "I fear only extraordinary situations in the Championship" (ATC 2010)

In the recent review by Boris Odintsov the Expert Advisor of the Bulgarian Participant Dimitar Manov appeared among the most stable and reliable EAs. We decided to interview this developer and try to find the secret of his success. In this interview Dimitar has told us what situation would be unfavorable for his robot, why he's not using indicators and whether he is expecting to win the competition.
Designing and implementing new GUI widgets based on CChartObject class
Designing and implementing new GUI widgets based on CChartObject class

Designing and implementing new GUI widgets based on CChartObject class

After I wrote a previous article on semi-automatic Expert Advisor with GUI interface it turned out that it would be desirable to enhance interface with some new functionalities for more complex indicators and Expert Advisors. After getting acquainted with MQL5 standard library classes I implemented new widgets. This article describes a process of designing and implementing new MQL5 GUI widgets that can be used in indicators and Expert Advisors. The widgets presented in the article are CChartObjectSpinner, CChartObjectProgressBar and CChartObjectEditTable.
Technical Analysis: How Do We Analyze?
Technical Analysis: How Do We Analyze?

Technical Analysis: How Do We Analyze?

This article briefly describes the author's opinion on redrawing indicators, multi-timeframe indicators and displaying of quotes with Japanese candlesticks. The article contain no programming specifics and is of a general character.
The Use of the MQL5 Standard Trade Class libraries in writing an Expert Advisor
The Use of the MQL5 Standard Trade Class libraries in writing an Expert Advisor

The Use of the MQL5 Standard Trade Class libraries in writing an Expert Advisor

This article explains how to use the major functionalities of the MQL5 Standard Library Trade Classes in writing Expert Advisors which implements position closing and modifying, pending order placing and deletion and verifying of Margin before placing a trade. We have also demonstrated how Trade classes can be used to obtain order and deal details.
Alexander Anufrenko: "A danger foreseen is half avoided" (ATC 2010)
Alexander Anufrenko: "A danger foreseen is half avoided" (ATC 2010)

Alexander Anufrenko: "A danger foreseen is half avoided" (ATC 2010)

The risky development of Alexander Anufrenko (Anufrenko321) had been featured among the top three of the Championship for three weeks. Having suffered a catastrophic Stop Loss last week, his Expert Advisor lost about $60,000, but now once again he is approaching the leaders. In this interview the author of this interesting EA is describing the operating principles and characteristics of his application.
Building interactive semi-automatic drag-and-drop Expert Advisor based on predefined risk and R/R ratio
Building interactive semi-automatic drag-and-drop Expert Advisor based on predefined risk and R/R ratio

Building interactive semi-automatic drag-and-drop Expert Advisor based on predefined risk and R/R ratio

Some traders execute all their trades automatically, and some mix automatic and manual trades based on the output of several indicators. Being a member of the latter group I needed an interactive tool to asses dynamically risk and reward price levels directly from the chart. This article will present a way to implement an interactive semi-automatic Expert Advisor with predefined equity risk and R/R ratio. The Expert Advisor risk, R/R and lot size parameters can be changed during runtime on the EA panel.
Vladimir Tsyrulnik: The Essense of my program is improvisation! (ATC 2010)
Vladimir Tsyrulnik: The Essense of my program is improvisation! (ATC 2010)

Vladimir Tsyrulnik: The Essense of my program is improvisation! (ATC 2010)

Vladimir Tsyrulnik is the holder of one of the brightest highs of the current Championship. By the end of the third trading week Vladimir's Expert Advisor was on the sixth position. The IMEX algorithm the Expert Advisor is based on was developed by Vladimir. To learn more about this algorithm, we had an interview with Vladimir.
Growing Neural Gas: Implementation in MQL5
Growing Neural Gas: Implementation in MQL5

Growing Neural Gas: Implementation in MQL5

The article shows an example of how to develop an MQL5-program implementing the adaptive algorithm of clustering called Growing neural gas (GNG). The article is intended for the users who have studied the language documentation and have certain programming skills and basic knowledge in the area of neuroinformatics.
Interview with Boris Odintsov (ATC 2010)
Interview with Boris Odintsov (ATC 2010)

Interview with Boris Odintsov (ATC 2010)

Boris Odintsov is one of the most impressive participants of the Championship who managed to go beyond $100,000 on the third week of the competition. Boris explains the rapid rise of his expert Advisor as a favorable combination of circumstances. In this interview he tells about what is important in trading, and what market would be unfavorable for his EA.
Interview with Valery Mazurenko (ATC 2010)
Interview with Valery Mazurenko (ATC 2010)

Interview with Valery Mazurenko (ATC 2010)

By the end of the first trading week, Valery Mazurenrk (notused) with his multicurrency Expert Advisor ch2010 appeared on the top position. Having treated trading as a hobby, Valery is now trying to monetize this hobby and write a stable-operating Expert Advisor for real trading. In this interview he shares his opinion about the role of mathematics in trading and explains why object-oriented approach suits best to writing multicurrency EAs.
Guide to Testing and Optimizing of Expert Advisors in MQL5
Guide to Testing and Optimizing of Expert Advisors in MQL5

Guide to Testing and Optimizing of Expert Advisors in MQL5

This article explains the step by step process of identifying and resolving code errors as well as the steps in testing and optimizing of the Expert Advisor input parameters. You will learn how to use Strategy Tester of MetaTrader 5 client terminal to find the best symbol and set of input parameters for your Expert Advisor.
The "New Bar" Event Handler
The "New Bar" Event Handler

The "New Bar" Event Handler

MQL5 programming language is capable of solving problems on a brand new level. Even those tasks, that already have such solutions, thanks to object oriented programming can rise to a higher level. In this article we take a specially simple example of checking new bar on a chart, that was transformed into rather powerful and versatile tool. What tool? Find out in this article.
Technical Analysis: What Do We Analyze?
Technical Analysis: What Do We Analyze?

Technical Analysis: What Do We Analyze?

This article tries to analyze several peculiarities of representation of quotes available in the MetaTrader client terminal. The article is general, it doesn't concern programming.
Interview with Berron Parker (ATC 2010)
Interview with Berron Parker (ATC 2010)

Interview with Berron Parker (ATC 2010)

During the first week of the Championship Berron's Expert Advisor has been on the top position. He now tells us about his experience of EA development and difficulties of moving to MQL5. Berron says his EA is set up to work in a trend market, but can be weak in other market conditions. However, he is hopeful that his robot will show good results in this competition.
Evaluation of Trade Systems - the Effectiveness of Entering, Exiting and Trades in General
Evaluation of Trade Systems - the Effectiveness of Entering, Exiting and Trades in General

Evaluation of Trade Systems - the Effectiveness of Entering, Exiting and Trades in General

There are a lot of measures that allow determining the effectiveness and profitability of a trade system. However, traders are always ready to put any system to a new crash test. The article tells how the statistics based on measures of effectiveness can be used for the MetaTrader 5 platform. It includes the class for transformation of the interpretation of statistics by deals to the one that doesn't contradict the description given in the "Statistika dlya traderov" ("Statistics for Traders") book by S.V. Bulashev. It also includes an example of custom function for optimization.
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.
Protect Yourselves, Developers!
Protect Yourselves, Developers!

Protect Yourselves, Developers!

Protection of intellectual property is still a big problem. This article describes the basic principles of MQL4-programs protection. Using these principles you can ensure that results of your developments are not stolen by a thief, or at least to complicate his "work" so much that he will just refuse to do it.
Contest of Expert Advisors inside an Expert Advisor
Contest of Expert Advisors inside an Expert Advisor

Contest of Expert Advisors inside an Expert Advisor

Using virtual trading, you can create an adaptive Expert Advisor, which will turn on and off trades at the real market. Combine several strategies in a single Expert Advisor! Your multisystem Expert Advisor will automatically choose a trade strategy, which is the best to trade with at the real market, on the basis of profitability of virtual trades. This kind of approach allows decreasing drawdown and increasing profitability of your work at the market. Experiment and share your results with others! I think many people will be interested to know about your portfolio of strategies.
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.