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
Universal Expert Advisor: Custom Strategies and Auxiliary Trade Classes (Part 3)
Universal Expert Advisor: Custom Strategies and Auxiliary Trade Classes (Part 3)

Universal Expert Advisor: Custom Strategies and Auxiliary Trade Classes (Part 3)

In this article, we will continue analyzing the algorithms of the CStrategy trading engine. The third part of the series contains the detailed analysis of examples of how to develop specific trading strategies using this approach. Special attention is paid to auxiliary algorithms — Expert Advisor logging system and data access using a conventional indexer (Close[1], Open[0] etc.)
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.
Timeseries in DoEasy library (part 39): Library-based indicators - preparing data and timeseries events
Timeseries in DoEasy library (part 39): Library-based indicators - preparing data and timeseries events

Timeseries in DoEasy library (part 39): Library-based indicators - preparing data and timeseries events

The article deals with applying DoEasy library for creating multi-symbol multi-period indicators. We are going to prepare the library classes to work within indicators and test creating timeseries to be used as data sources in indicators. We will also implement creating and sending timeseries events.
Graphical Interfaces IV: the Multi-Window Mode and System of Priorities (Chapter 2)
Graphical Interfaces IV: the Multi-Window Mode and System of Priorities (Chapter 2)

Graphical Interfaces IV: the Multi-Window Mode and System of Priorities (Chapter 2)

In this chapter, we will extend the library implementation to the possibility of creating multi-window interfaces for the MQL applications. We will also develop a system of priorities for left mouse clicking on graphical objects. This is required to avoid problems when elements do not respond to the user's actions.
Graphical Interfaces I: Form for Controls (Chapter 2)
Graphical Interfaces I: Form for Controls (Chapter 2)

Graphical Interfaces I: Form for Controls (Chapter 2)

In this article we will create the first and main element of the graphical interface - a form for controls. Multiple controls can be attached to this form anywhere and in any combination.
Cross-Platform Expert Advisor: Time Filters
Cross-Platform Expert Advisor: Time Filters

Cross-Platform Expert Advisor: Time Filters

This article discusses the implementation of various methods of time filtering a cross-platform expert advisor. The time filter classes are responsible for checking whether or not a given time falls under a certain time configuration setting.
Studying the CCanvas Class. How to Draw Transparent Objects
Studying the CCanvas Class. How to Draw Transparent Objects

Studying the CCanvas Class. How to Draw Transparent Objects

Do you need more than awkward graphics of moving averages? Do you want to draw something more beautiful than a simple filled rectangle in your terminal? Attractive graphics can be drawn in the terminal. This can be implemented through the CСanvas class, which is used for creating custom graphics. With this class you can implement transparency, blend colors and produce the illusion of transparency by means of overlapping and blending colors.
MQL5 Wizard: Placing Orders, Stop-Losses and Take Profits on Calculated Prices. Standard Library Extension
MQL5 Wizard: Placing Orders, Stop-Losses and Take Profits on Calculated Prices. Standard Library Extension

MQL5 Wizard: Placing Orders, Stop-Losses and Take Profits on Calculated Prices. Standard Library Extension

This article describes the MQL5 Standard Library extension, which allows to create Expert Advisors, place orders, Stop Losses and Take Profits using the MQL5 Wizard by the prices received from included modules. This approach does not apply any additional restrictions on the number of modules and does not cause conflicts in their joint work.
preview
Machine learning in Grid and Martingale trading systems. Would you bet on it?

Machine learning in Grid and Martingale trading systems. Would you bet on it?

This article describes the machine learning technique applied to grid and martingale trading. Surprisingly, this approach has little to no coverage in the global network. After reading the article, you will be able to create your own trading bots.
Better Programmer (Part 01): You must stop doing these 5 things to become a successful MQL5 programmer
Better Programmer (Part 01): You must stop doing these 5 things to become a successful MQL5 programmer

Better Programmer (Part 01): You must stop doing these 5 things to become a successful MQL5 programmer

There are a lot of bad habits that newbies and even advanced programmers are doing that are keeping them from becoming the best they can be to their coding career. We are going to discuss and address them in this article. This article is a must read for everyone who wants to become successful developer in MQL5.
Trading DiNapoli levels
Trading DiNapoli levels

Trading DiNapoli levels

The article considers one of the variants for Expert Advisor practical realization to trade DiNapoli levels using MQL5 standard tools. Its performance is tested and conclusions are made.
Multicurrency monitoring of trading signals (Part 1): Developing the application structure
Multicurrency monitoring of trading signals (Part 1): Developing the application structure

Multicurrency monitoring of trading signals (Part 1): Developing the application structure

In this article, we will discuss the idea of creating a multicurrency monitor of trading signals and will develop a future application structure along with its prototype, as well as create its framework for further operation. The article presents a step-by-step creation of a flexible multicurrency application which will enable the generation of trading signals and which will assist traders in finding the desired signals.
Universal Expert Advisor: Accessing Symbol Properties (Part 8)
Universal Expert Advisor: Accessing Symbol Properties (Part 8)

Universal Expert Advisor: Accessing Symbol Properties (Part 8)

The eighth part of the article features the description of the CSymbol class, which is a special object that provides access to any trading instrument. When used inside an Expert Advisor, the class provides a wide set of symbol properties, while allowing to simplify Expert Advisor programming and to expand its functionality.
Practical application of neural networks in trading
Practical application of neural networks in trading

Practical application of neural networks in trading

In this article, we will consider the main aspects of integration of neural networks and the trading terminal, with the purpose of creating a fully featured trading robot.
MQL5.com Freelance: Developers' Source of Income (Infographic)
MQL5.com Freelance: Developers' Source of Income (Infographic)

MQL5.com Freelance: Developers' Source of Income (Infographic)

On the occasion of the MQL5 Freelance Service fourth birthday, we have prepared an info-graphic demonstrating the service results for the entire time of its existence. The figures speak for themselves: more than 10 000 orders worth about $600,000 in total have been executed to date, while 3 000 customers and 300 developers have already used the service.
preview
Mathematics in trading: Sharpe and Sortino ratios

Mathematics in trading: Sharpe and Sortino ratios

Return on investments is the most obvious indicator which investors and novice traders use for the analysis of trading efficiency. Professional traders use more reliable tools to analyze strategies, such as Sharpe and Sortino ratios, among others.
Using indicators for optimizing Expert Advisors in real time
Using indicators for optimizing Expert Advisors in real time

Using indicators for optimizing Expert Advisors in real time

Efficiency of any trading robot depends on the correct selection of its parameters (optimization). However, parameters that are considered optimal for one time interval may not retain their effectiveness in another period of trading history. Besides, EAs showing profit during tests turn out to be loss-making in real time. The issue of continuous optimization comes to the fore here. When facing plenty of routine work, humans always look for ways to automate it. In this article, I propose a non-standard approach to solving this issue.
Quick Manual Trading Toolkit: Basic Functionality
Quick Manual Trading Toolkit: Basic Functionality

Quick Manual Trading Toolkit: Basic Functionality

Today, many traders switch to automated trading systems which can require additional setup or can be fully automated and ready to use. However, there is a considerable part of traders who prefer trading manually, in the old fashioned way. In this article, we will create toolkit for quick manual trading, using hotkeys, and for performing typical trading actions in one click.
SQL and MQL5: Working with SQLite Database
SQL and MQL5: Working with SQLite Database

SQL and MQL5: Working with SQLite Database

This article is intended for developers who would be interested in using SQL in their projects. It explains the functionality and advantages of SQLite. The article does not require special knowledge of SQLite functions, yet minimum understanding of SQL would be beneficial.
Optimization management (Part I): Creating a GUI
Optimization management (Part I): Creating a GUI

Optimization management (Part I): Creating a GUI

This article describes the process of creating an extension for the MetaTrader terminal. The solution discussed helps to automate the optimization process by running optimizations in other terminals. A few more articles will be written concerning this topic. The extension has been developed using the C# language and design patterns, which additionally demonstrates the ability to expand the terminal capabilities by developing custom modules, as well as the ability to create custom graphical user interfaces using the functionality of a preferred programming language.
Regular expressions for traders
Regular expressions for traders

Regular expressions for traders

A regular expression is a special language for handling texts by applying a specified rule, also called a regex or regexp for short. In this article, we are going to show how to handle a trade report with the RegularExpressions library for MQL5, and will also demonstrate the optimization results after using it.
preview
Cluster analysis (Part I): Mastering the slope of indicator lines

Cluster analysis (Part I): Mastering the slope of indicator lines

Cluster analysis is one of the most important elements of artificial intelligence. In this article, I attempt applying the cluster analysis of the indicator slope to get threshold values for determining whether a market is flat or following a trend.
Interview with Rogério Figurelli (ATC 2012)
Interview with Rogério Figurelli (ATC 2012)

Interview with Rogério Figurelli (ATC 2012)

Today we are going to talk with Rogério Figurelli (figurelli), a regular participant from Brazil that has not missed any Automated Trading Championship since 2007. This year, he also began to sell his Championship's Expert Advisor in the Market along with his other products. Rogério believes that MetaTrader 5 platform certification on the largest Brazilian exchange BM&FBOVESPA will reveal new professional developers and traders, who do not yet know the full potential of robot investors.
Random Walk and the Trend Indicator
Random Walk and the Trend Indicator

Random Walk and the Trend Indicator

Random Walk looks very similar to the real market data, but it has some significant features. In this article we will consider the properties of Random Walk, simulated using the coin-tossing game. To study the properties of the data, the trendiness indicator is developed.
LifeHack for trader: "Quiet" optimization or Plotting trade distributions
LifeHack for trader: "Quiet" optimization or Plotting trade distributions

LifeHack for trader: "Quiet" optimization or Plotting trade distributions

Analysis of the trade history and plotting distribution charts of trading results in HTML depending on position entry time. The charts are displayed in three sections - by hours, by days of the week and by months.
preview
Dealing with Time (Part 1): The Basics

Dealing with Time (Part 1): The Basics

Functions and code snippets that simplify and clarify the handling of time, broker offset, and the changes to summer or winter time. Accurate timing may be a crucial element in trading. At the current hour, is the stock exchange in London or New York already open or not yet open, when does the trading time for Forex trading start and end? For a trader who trades manually and live, this is not a big problem.
Data Exchange between Indicators: It's Easy
Data Exchange between Indicators: It's Easy

Data Exchange between Indicators: It's Easy

We want to create such an environment, which would provide access to data of indicators attached to a chart, and would have the following properties: absence of data copying; minimal modification of the code of available methods, if we need to use them; MQL code is preferable (of course, we have to use DLL, but we will use just a dozen of strings of C++ code). The article describes an easy method to develop a program environment for the MetaTrader terminal, that would provide means for accessing indicator buffers from other MQL programs.
Parallel Calculations in MetaTrader 5
Parallel Calculations in MetaTrader 5

Parallel Calculations in MetaTrader 5

Time has been a great value throughout the history of mankind, and we strive not to waste it unnecessarily. This article will tell you how to accelerate the work of your Expert Advisor if your computer has a multi-core processor. Moreover, the implementation of the proposed method does not require the knowledge of any other languages besides MQL5.
TradeObjects: Automation of trading based on MetaTrader graphical objects
TradeObjects: Automation of trading based on MetaTrader graphical objects

TradeObjects: Automation of trading based on MetaTrader graphical objects

The article deals with a simple approach to creating an automated trading system based on the chart linear markup and offers a ready-made Expert Advisor using the standard properties of the MetaTrader 4 and 5 objects and supporting the main trading operations.
Better Programmer (Part 07): Notes on becoming a successful freelance developer
Better Programmer (Part 07): Notes on becoming a successful freelance developer

Better Programmer (Part 07): Notes on becoming a successful freelance developer

Do you wish to become a successful Freelance developer on MQL5? If the answer is yes, this article is right for you.
preview
Creating an EA that works automatically (Part 01): Concepts and structures

Creating an EA that works automatically (Part 01): Concepts and structures

Today we'll see how to create an Expert Advisor that simply and safely works in automatic mode.
Extracting structured data from HTML pages using CSS selectors
Extracting structured data from HTML pages using CSS selectors

Extracting structured data from HTML pages using CSS selectors

The article provides a description of a universal method for analyzing and converting data from HTML documents based on CSS selectors. Trading reports, tester reports, your favorite economic calendars, public signals, account monitoring and additional online quote sources will become available straight from MQL.
Applying network functions, or MySQL without DLL: Part II - Program for monitoring changes in signal properties
Applying network functions, or MySQL without DLL: Part II - Program for monitoring changes in signal properties

Applying network functions, or MySQL without DLL: Part II - Program for monitoring changes in signal properties

In the previous part, we considered the implementation of the MySQL connector. In this article, we will consider its application by implementing the service for collecting signal properties and the program for viewing their changes over time. The implemented example has practical sense if users need to observe changes in properties that are not displayed on the signal's web page.
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.
Library for easy and quick development of MetaTrader programs (part XXIII): Base trading class - verification of valid parameters
Library for easy and quick development of MetaTrader programs (part XXIII): Base trading class - verification of valid parameters

Library for easy and quick development of MetaTrader programs (part XXIII): Base trading class - verification of valid parameters

In the article, we continue the development of the trading class by implementing the control over incorrect trading order parameter values and voicing trading events.
Studying candlestick analysis techniques (part IV): Updates and additions to Pattern Analyzer
Studying candlestick analysis techniques (part IV): Updates and additions to Pattern Analyzer

Studying candlestick analysis techniques (part IV): Updates and additions to Pattern Analyzer

The article presents a new version of the Pattern Analyzer application. This version provides bug fixes and new features, as well as the revised user interface. Comments and suggestions from previous article were taken into account when developing the new version. The resulting application is described in this article.
Applying OLAP in trading (part 1): Online analysis of multidimensional data
Applying OLAP in trading (part 1): Online analysis of multidimensional data

Applying OLAP in trading (part 1): Online analysis of multidimensional data

The article describes how to create a framework for the online analysis of multidimensional data (OLAP), as well as how to implement this in MQL and to apply such analysis in the MetaTrader environment using the example of trading account history processing.
The power of ZigZag (part I). Developing the base class of the indicator
The power of ZigZag (part I). Developing the base class of the indicator

The power of ZigZag (part I). Developing the base class of the indicator

Many researchers do not pay enough attention to determining the price behavior. At the same time, complex methods are used, which very often are simply “black boxes”, such as machine learning or neural networks. The most important question arising in that case is what data to submit for training a particular model.
A Universal Channel with the Graphical Interface
A Universal Channel with the Graphical Interface

A Universal Channel with the Graphical Interface

All channel indicators are displayed as three lines, including central, top and bottom lines. The drawing principle of the central line is similar to a moving average, while the moving average indicator is mostly used for drawing channels. The top and bottom lines are located at equal distances from the central line. This distance can be determined in points, as percent of price (the Envelopes indicator), using a standard deviation value (Bollinger Bands), or an ATR value (Keltner channel).
preview
Useful and exotic techniques for automated trading

Useful and exotic techniques for automated trading

In this article I will demonstrate some very interesting and useful techniques for automated trading. Some of them may be familiar to you. I will try to cover the most interesting methods and will explain why they are worth using. Furthermore, I will show what these techniques are apt to in practice. We will create Expert Advisors and test all the described techniques using historic quotes.