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
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.
Research of Statistical Recurrences of Candle Directions
Research of Statistical Recurrences of Candle Directions

Research of Statistical Recurrences of Candle Directions

Is it possible to predict the behavior of the market for a short upcoming interval of time, based on the recurring tendencies of candle directions, at specific times throughout the day? That is, If such an occurrence is found in the first place. This question has probably arisen in the mind of every trader. The purpose of this article is to attempt to predict the behavior of the market, based on the statistical recurrences of candle directions during specific intervals of time.
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.
The Magic of Filtration
The Magic of Filtration

The Magic of Filtration

Most of the automated trading systems developers use some form of trading signals filtration. In this article, we explore the creation and implementation of bandpass and discrete filters for Expert Advisors, to improve the characteristics of the automated trading system.
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.
OOP in MQL5 by Example: Processing Warning and Error Codes
OOP in MQL5 by Example: Processing Warning and Error Codes

OOP in MQL5 by Example: Processing Warning and Error Codes

The article describes an example of creating a class for working with the trade server return codes and all the errors that occur during the MQL-program run. Read the article, and you will learn how to work with classes and objects in MQL5. At the same time, this is a convenient tool for handling errors; and you can further change this tool according to your specific needs.
MQL for "Dummies": How to Design and Construct Object Classes
MQL for "Dummies": How to Design and Construct Object Classes

MQL for "Dummies": How to Design and Construct Object Classes

By creating a sample program of visual design, we demonstrate how to design and construct classes in MQL5. The article is written for beginner programmers, who are working on MT5 applications. We propose a simple and easy grasping technology for creating classes, without the need to deeply immerse into the theory of object-oriented programming.
Creating Active Control Panels in MQL5 for Trading
Creating Active Control Panels in MQL5 for Trading

Creating Active Control Panels in MQL5 for Trading

The article covers the problem of development of active control panels in MQL5. Interface elements are managed by the event handling mechanism. Besides, the option of a flexible setup of control elements properties is available. The active control panel allows working with positions, as well setting, modifying and deleting market and pending orders.
Practical Application Of Databases For Markets Analysis
Practical Application Of Databases For Markets Analysis

Practical Application Of Databases For Markets Analysis

Working with data has become the main task for modern software - both for standalone and network applications. To solve this problem a specialized software were created. These are Database Management Systems (DBMS), that can structure, systematize and organize data for their computer storage and processing. As for trading, the most of analysts don't use databases in their work. But there are tasks, where such a solution would have to be handy. This article provides an example of indicators, that can save and load data from databases both with client-server and file-server architectures.
Migrating from MQL4 to MQL5
Migrating from MQL4 to MQL5

Migrating from MQL4 to MQL5

This article is a quick guide to MQL4 language functions, it will help you to migrate your programs from MQL4 to MQL5. For each MQL4 function (except trading functions) the description and MQL5 implementation are presented, it allows you to reduce the conversion time significantly. For convenience, the MQL4 functions are divided into groups, similar to MQL4 Reference.
A Virtual Order Manager to track orders within the position-centric MetaTrader 5 environment
A Virtual Order Manager to track orders within the position-centric MetaTrader 5 environment

A Virtual Order Manager to track orders within the position-centric MetaTrader 5 environment

This class library can be added to an MetaTrader 5 Expert Advisor to enable it to be written with an order-centric approach broadly similar to MetaTrader 4, in comparison to the position-based approach of MetaTrader 5. It does this by keeping track of virtual orders at the MetaTrader 5 client terminal, while maintaining a protective broker stop for each position for disaster protection.
Creating an Indicator with Graphical Control Options
Creating an Indicator with Graphical Control Options

Creating an Indicator with Graphical Control Options

Those who are familiar with market sentiments, know the MACD indicator (its full name is Moving Average Convergence/Divergence) - the powerful tool for analyzing the price movement, used by traders from the very first moments of appearance of the computer analysis methods. In this article we'll consider possible modifications of MACD and implement them in one indicator with the possibility to graphically switch between the modifications.
MetaTrader 5: Publishing trading forecasts and live trading statements via e-mail on blogs, social networks and dedicated websites
MetaTrader 5: Publishing trading forecasts and live trading statements via e-mail on blogs, social networks and dedicated websites

MetaTrader 5: Publishing trading forecasts and live trading statements via e-mail on blogs, social networks and dedicated websites

This article aims to present ready-made solutions for publishing forecasts using MetaTrader 5. It covers a range of ideas: from using dedicated websites for publishing MetaTrader statements, through setting up one's own website with virtually no web programming experience needed and finally integration with a social network microblogging service that allows many readers to join and follow the forecasts. All solutions presented here are 100% free and possible to setup by anyone with a basic knowledge of e-mail and ftp services. There are no obstacles to use the same techniques for professional hosting and commercial trading forecast services.
Creating a "Snake" Game in MQL5
Creating a "Snake" Game in MQL5

Creating a "Snake" Game in MQL5

This article describes an example of "Snake" game programming. In MQL5, the game programming became possible primarily due to event handling features. The object-oriented programming greatly simplifies this process. In this article, you will learn the event processing features, the examples of use of the Standard MQL5 Library classes and details of periodic function calls.
Creating Tick Indicators in MQL5
Creating Tick Indicators in MQL5

Creating Tick Indicators in MQL5

In this article, we will consider the creation of two indicators: the tick indicator, which plots the tick chart of the price and tick candle indicator, which plot candles with the specified number of ticks. Each of the indicators writes the incoming prices into a file, and uses the saved data after the restart of the indicator (these data also can be used by the other programs)
Using the Object Pointers in MQL5
Using the Object Pointers in MQL5

Using the Object Pointers in MQL5

By default, all objects in MQL5 are passed by reference, but there is a possibility to use the object pointers. However it's necessary to perform the pointer checking, because the object may be not initialized. In this case, the MQL5 program will be terminated with critical error and unloaded. The objects, created automatically, doesn't cause such an error, so in this sence, they are quite safe. In this article, we will try to understand the difference between the object reference and object pointer, and consider how to write secure code, that uses the pointers.
MQL5: Analysis and Processing of Commodity Futures Trading Commission (CFTC) Reports in MetaTrader 5
MQL5: Analysis and Processing of Commodity Futures Trading Commission (CFTC) Reports in MetaTrader 5

MQL5: Analysis and Processing of Commodity Futures Trading Commission (CFTC) Reports in MetaTrader 5

In this article, we will develop a tool for CFTC report analysis. We will solve the following problem: to develop an indicator, that allows using the CFTC report data directly from the data files provided by Commission without an intermediate processing and conversion. Further, it can be used for the different purposes: to plot the data as an indicator, to proceed with the data in the other indicators, in the scripts for the automated analysis, in the Expert Advisors for the use in the trading strategies.
Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator
Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator

Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator

MetaQuotes Programming Language 5 (MQL5), included in MetaTrader 5 Client Terminal, has many new possibilities and higher performance, compared to MQL4. This article will help you to get acquainted with this new programming language. The simple examples of how to write an Expert Advisor and Custom Indicator are presented in this article. We will also consider some details of MQL5 language, that are necessary to understand these examples.
Drawing Indicator's Emissions in MQL5
Drawing Indicator's Emissions in MQL5

Drawing Indicator's Emissions in MQL5

In this article, we will consider the emission of indicators - a new approach to the market research. The calculation of emission is based on the intersection of different indicators: more and more points with different colors and shapes appear after each tick. They form numerous clusters like nebulae, clouds, tracks, lines, arcs, etc. These shapes help to detect the invisible springs and forces that affect the movement of market prices.
The Drawing Styles in MQL5
The Drawing Styles in MQL5

The Drawing Styles in MQL5

There are 6 drawing styles in MQL4 and 18 drawing styles in MQL5. Therefore, it may be worth writing an article to introduce MQL5's drawing styles. In this article, we will consider the details of drawing styles in MQL5. In addition, we will create an indicator to demonstrate how to use these drawing styles, and refine the plotting.
Practical Implementation of Digital Filters in MQL5 for Beginners
Practical Implementation of Digital Filters in MQL5 for Beginners

Practical Implementation of Digital Filters in MQL5 for Beginners

The idea of digital signal filtering has been widely discussed on forum topics about building trading systems. And it would be imprudent not to create a standard code of digital filters in MQL5. In this article the author describes the transformation of simple SMA indicator's code from his article "Custom Indicators in MQL5 for Newbies" into code of more complicated and universal digital filter. This article is a logical sequel to the previous article. It also tells how to replace text in code and how to correct programming errors.
MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors
MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors

MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors

In order to obtain values of a built-in or custom indicator in an Expert Advisor, first its handle should be created using the corresponding function. Examples in the article show how to use this or that technical indicator while creating your own programs. The article describes indicators that are built n the MQL5 language. It is intended for those who don't have much experience in the development of trading strategies and offers simple and clear ways of working with indicators using the offered library of functions.