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
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.
Time Series Forecasting Using Exponential Smoothing
Time Series Forecasting Using Exponential Smoothing

Time Series Forecasting Using Exponential Smoothing

The article familiarizes the reader with exponential smoothing models used for short-term forecasting of time series. In addition, it touches upon the issues related to optimization and estimation of the forecast results and provides a few examples of scripts and indicators. This article will be useful as a first acquaintance with principles of forecasting on the basis of exponential smoothing models.
MQL5 Programming Basics: Global Variables of the  MetaTrader 5 Terminal
MQL5 Programming Basics: Global Variables of the  MetaTrader 5 Terminal

MQL5 Programming Basics: Global Variables of the MetaTrader 5 Terminal

Global variables of the terminal provide an indispensable tool for developing sophisticated and reliable Expert Advisors. If you master the global variables, you will no more be able to imagine developing EAs on MQL5 without them.
Building an Expert Advisor using separate modules
Building an Expert Advisor using separate modules

Building an Expert Advisor using separate modules

When developing indicators, Expert Advisors and scripts, developers often need to create various pieces of code, which are not directly related to the trading strategy. In this article, we consider a way to create Expert Advisors using earlier created blocks, such as trailing, filtering and scheduling code, among others. We will see the benefits of this programming approach.
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.
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.
Expert Advisor based on the "New Trading Dimensions" by Bill Williams
Expert Advisor based on the "New Trading Dimensions" by Bill Williams

Expert Advisor based on the "New Trading Dimensions" by Bill Williams

In this article I will discuss the development of Expert Advisor, based on the book "New Trading Dimensions: How to Profit from Chaos in Stocks, Bonds, and Commodities" by Bill Williams. The strategy itself is well known and its use is still controversial among traders. The article considers trading signals of the system, the specifics of its implementation, and the results of testing on historical data.
The Flag Pattern
The Flag Pattern

The Flag Pattern

The article provides the analysis of the following patterns: Flag, Pennant, Wedge, Rectangle, Contracting Triangle, Expanding Triangle. In addition to analyzing their similarities and differences, we will create indicators for detecting these patterns on the chart, as well as a tester indicator for the fast evaluation of their effectiveness.
Reversal patterns: Testing the Head and Shoulders pattern
Reversal patterns: Testing the Head and Shoulders pattern

Reversal patterns: Testing the Head and Shoulders pattern

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

Visualize a Strategy in the MetaTrader 5 Tester

We all know the saying "Better to see once than hear a hundred times". You can read various books about Paris or Venice, but based on the mental images you wouldn't have the same feelings as on the evening walk in these fabulous cities. The advantage of visualization can easily be projected on any aspect of our lives, including work in the market, for example, the analysis of price on charts using indicators, and of course, the visualization of strategy testing. This article contains descriptions of all the visualization features of the MetaTrader 5 Strategy Tester.
Expert Advisor featuring GUI: Creating the panel (part I)
Expert Advisor featuring GUI: Creating the panel (part I)

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

Despite the fact that many traders still prefer manual trading, it is hardly possible to completely avoid the automation of routine operations. The article shows an example of developing a multi-symbol signal Expert Advisor for manual trading.
Trading with Donchian Channels
Trading with Donchian Channels

Trading with Donchian Channels

In this article, we develop and tests several strategies based on the Donchian channel using various indicator filters. We also perform a comparative analysis of their operation.
How to Copy Trading from MetaTrader 5 to MetaTrader 4
How to Copy Trading from MetaTrader 5 to MetaTrader 4

How to Copy Trading from MetaTrader 5 to MetaTrader 4

Is it possible to trade on a real MetaTrader 5 account today? How to organize such trading? The article contains the theory of these questions and the working codes used for copying trades from the MetaTrader 5 terminal to MetaTrader 4. The article will be useful both for the developers of Expert Advisors and for practicing traders.
Forecasting Time Series (Part 1): Empirical Mode Decomposition (EMD) Method
Forecasting Time Series (Part 1): Empirical Mode Decomposition (EMD) Method

Forecasting Time Series (Part 1): Empirical Mode Decomposition (EMD) Method

This article deals with the theory and practical use of the algorithm for forecasting time series, based on the empirical decomposition mode. It proposes the MQL implementation of this method and presents test indicators and Expert Advisors.
Patterns with Examples (Part I): Multiple Top
Patterns with Examples (Part I): Multiple Top

Patterns with Examples (Part I): Multiple Top

This is the first article in a series related to reversal patterns in the framework of algorithmic trading. We will begin with the most interesting pattern family, which originate from the Double Top and Double Bottom patterns.
Library for easy and quick development of MetaTrader programs (part XXVIII): Closure, removal and modification of pending trading requests
Library for easy and quick development of MetaTrader programs (part XXVIII): Closure, removal and modification of pending trading requests

Library for easy and quick development of MetaTrader programs (part XXVIII): Closure, removal and modification of pending trading requests

This is the third article about the concept of pending requests. We are going to complete the tests of pending trading requests by creating the methods for closing positions, removing pending orders and modifying position and pending order parameters.
Reversing: The holy grail or a dangerous delusion?
Reversing: The holy grail or a dangerous delusion?

Reversing: The holy grail or a dangerous delusion?

In this article, we will study the reverse martingale technique and will try to understand whether it is worth using, as well as whether it can help improve your trading strategy. We will create an Expert Advisor to operate on historic data and to check what indicators are best suitable for the reversing technique. We will also check whether it can be used without any indicator as an independent trading system. In addition, we will check if reversing can turn a loss-making trading system into a profitable one.
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.
Creating a custom news feed for MetaTrader 5
Creating a custom news feed for MetaTrader 5

Creating a custom news feed for MetaTrader 5

In this article we look at the possibility of creating a flexible news feed that offers more options in terms of the type of news and also its source. The article will show how a web API can be integrated with the MetaTrader 5 terminal.
Graphical Interfaces X: Updates for Easy And Fast Library (Build 3)
Graphical Interfaces X: Updates for Easy And Fast Library (Build 3)

Graphical Interfaces X: Updates for Easy And Fast Library (Build 3)

The next version of the Easy And Fast library (version 3) is presented in this article. Fixed certain flaws and added new features. More details further in the article.
Creating Custom Criteria of Optimization of Expert Advisors
Creating Custom Criteria of Optimization of Expert Advisors

Creating Custom Criteria of Optimization of Expert Advisors

The MetaTrader 5 Client Terminal offers a wide range of opportunities for optimization of Expert Advisor parameters. In addition to the optimization criteria included in the strategy tester, developers are given the opportunity of creating their own criteria. This leads to an almost limitless number of possibilities of testing and optimizing of Expert Advisors. The article describes practical ways of creating such criteria - both complex and simple ones.
MQL5 Wizard for Dummies
MQL5 Wizard for Dummies

MQL5 Wizard for Dummies

In early 2011 we released the first version of the MQL5 Wizard. This new application provides a simple and convenient tool to automatically generate trading robots. Any MetaTrader 5 user can create a custom Expert Advisor without even knowing how to program in MQL5.
Calculating the Hurst exponent
Calculating the Hurst exponent

Calculating the Hurst exponent

The article thoroughly explains the idea behind the Hurst exponent, as well as the meaning of its values and the calculation algorithm. A number of financial market segments are analyzed and the method of working with MetaTrader 5 products implementing the fractal analysis is described.
Graphical Interfaces X: The Standard Chart Control (build 4)
Graphical Interfaces X: The Standard Chart Control (build 4)

Graphical Interfaces X: The Standard Chart Control (build 4)

This time we will consider the Standard chart control. It will allow to create arrays of subcharts with the ability to synchronize horizontal scrolling. In addition, we will continue to optimize the library code to reduce the CPU load.
MQL5 Programming Basics: Strings
MQL5 Programming Basics: Strings

MQL5 Programming Basics: Strings

The article covers everything you can do with strings in MQL5. It should be of interest primarily to novice MQL5 programmers, while experienced developers will have a good opportunity to summarize and systematize their knowledge.
Library for easy and quick development of MetaTrader programs (part XXXIV): Pending trading requests - removing and modifying orders and positions under certain conditions
Library for easy and quick development of MetaTrader programs (part XXXIV): Pending trading requests - removing and modifying orders and positions under certain conditions

Library for easy and quick development of MetaTrader programs (part XXXIV): Pending trading requests - removing and modifying orders and positions under certain conditions

In this article, we will complete the description of the pending request trading concept and create the functionality for removing pending orders, as well as modifying orders and positions under certain conditions. Thus, we are going to have the entire functionality enabling us to develop simple custom strategies, or rather EA behavior logic activated upon user-defined conditions.
Synchronizing several same-symbol charts on different timeframes
Synchronizing several same-symbol charts on different timeframes

Synchronizing several same-symbol charts on different timeframes

When making trading decisions, we often have to analyze charts on several timeframes. At the same time, these charts often contain graphical objects. Applying the same objects to all charts is inconvenient. In this article, I propose to automate cloning of objects to be displayed on charts.
Learn how to design a trading system by Bollinger Bands
Learn how to design a trading system by Bollinger Bands

Learn how to design a trading system by Bollinger Bands

In this article, we will learn about Bollinger Bands which is one of the most popular indicators in the trading world. We will consider technical analysis and see how to design an algorithmic trading system based on the Bollinger Bands indicator.
Developing a self-adapting algorithm (Part II): Improving efficiency
Developing a self-adapting algorithm (Part II): Improving efficiency

Developing a self-adapting algorithm (Part II): Improving efficiency

In this article, I will continue the development of the topic by improving the flexibility of the previously created algorithm. The algorithm became more stable with an increase in the number of candles in the analysis window or with an increase in the threshold percentage of the overweight of falling or growing candles. I had to make a compromise and set a larger sample size for analysis or a larger percentage of the prevailing candle excess.
Basic math behind Forex trading
Basic math behind Forex trading

Basic math behind Forex trading

The article aims to describe the main features of Forex trading as simply and quickly as possible, as well as share some basic ideas with beginners. It also attempts to answer the most tantalizing questions in the trading community along with showcasing the development of a simple indicator.
Creating an assistant in manual trading
Creating an assistant in manual trading

Creating an assistant in manual trading

The number of trading robots used on the currency markets has significantly increased recently. They employ various concepts and strategies, however, none of them has yet succeeded to create a win-win sample of artificial intelligence. Therefore, many traders remain committed to manual trading. But even for such specialists, robotic assistants or, so called, trading panels, are created. This article is yet another example of creating a trading panel from scratch.
Testing patterns that arise when trading currency pair baskets. Part III
Testing patterns that arise when trading currency pair baskets. Part III

Testing patterns that arise when trading currency pair baskets. Part III

In this article, we finish testing the patterns that can be detected when trading currency pair baskets. Here we present the results of testing the patterns tracking the movement of pair's currencies relative to each other.
DiNapoli trading system
DiNapoli trading system

DiNapoli trading system

The article describes the Fibo levels-based trading system developed by Joe DiNapoli. The idea behind the system and the main concepts are explained, as well as a simple indicator is provided as an example for more clarity.
Auto detection of extreme points based on a specified price variation
Auto detection of extreme points based on a specified price variation

Auto detection of extreme points based on a specified price variation

Automation of trading strategies involving graphical patterns requires the ability to search for extreme points on the charts for further processing and interpretation. Existing tools do not always provide such an ability. The algorithms described in the article allow finding all extreme points on charts. The tools discussed here are equally efficient both during trends and flat movements. The obtained results are not strongly affected by a selected timeframe and are only defined by a specified scale.
preview
Programming a Deep Neural Network from Scratch using MQL Language

Programming a Deep Neural Network from Scratch using MQL Language

This article aims to teach the reader how to make a Deep Neural Network from scratch using the MQL4/5 language.
Interview with Dr. Alexander Elder: "I want to be a psychiatrist in the market"
Interview with Dr. Alexander Elder: "I want to be a psychiatrist in the market"

Interview with Dr. Alexander Elder: "I want to be a psychiatrist in the market"

I think financial markets are like manic-depressive patients. Sell when they have mania, and buy when they have depression. The envelope helps me determine where these levels of depression and mania are. There is a joke: "A neurotic is a man who builds castles in the skies, psychotic is the one who lives in them, and a psychiatrist is a person who collects the rent." I want to be a psychiatrist in the market. I want to collect the rent from the madness of the crowd.
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.
Custom Graphical Controls. Part 1: Creating a Simple Control
Custom Graphical Controls. Part 1: Creating a Simple Control

Custom Graphical Controls. Part 1: Creating a Simple Control

This article covers general principles of development of graphical controls. We are going to prepare tools for a quick and convenient work with graphical objects, analyze an example of creation of a simple control for entering text or numeric data as well as the ways of using it.
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.
Grid and martingale: what are they and how to use them?
Grid and martingale: what are they and how to use them?

Grid and martingale: what are they and how to use them?

In this article, I will try to explain in detail what grid and martingale are, as well as what they have in common. Besides, I will try to analyze how viable these strategies really are. The article features mathematical and practical sections.