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
Timeseries in DoEasy library (part 36): Object of timeseries for all used symbol periods
Timeseries in DoEasy library (part 36): Object of timeseries for all used symbol periods

Timeseries in DoEasy library (part 36): Object of timeseries for all used symbol periods

In this article, we will consider combining the lists of bar objects for each used symbol period into a single symbol timeseries object. Thus, each symbol will have an object storing the lists of all used symbol timeseries periods.
Here Comes the New MetaTrader 5 and MQL5
Here Comes the New MetaTrader 5 and MQL5

Here Comes the New MetaTrader 5 and MQL5

This is just a brief review of MetaTrader 5. I can't describe all the system's new features for such a short time period - the testing started on 2009.09.09. This is a symbolical date, and I am sure it will be a lucky number. A few days have passed since I got the beta version of the MetaTrader 5 terminal and MQL5. I haven't managed to try all its features, but I am already impressed.
preview
Multilayer perceptron and backpropagation algorithm

Multilayer perceptron and backpropagation algorithm

The popularity of these two methods grows, so a lot of libraries have been developed in Matlab, R, Python, C++ and others, which receive a training set as input and automatically create an appropriate network for the problem. Let us try to understand how the basic neural network type works (including single-neuron perceptron and multilayer perceptron). We will consider an exciting algorithm which is responsible for network training - gradient descent and backpropagation. Existing complex models are often based on such simple network models.
Library for easy and quick development of MetaTrader programs (part III). Collection of market orders and positions, search and sorting
Library for easy and quick development of MetaTrader programs (part III). Collection of market orders and positions, search and sorting

Library for easy and quick development of MetaTrader programs (part III). Collection of market orders and positions, search and sorting

In the first part, we started creating a large cross-platform library simplifying the development of programs for MetaTrader 5 and MetaTrader 4 platforms. Further on, we implemented the collection of history orders and deals. Our next step is creating a class for a convenient selection and sorting of orders, deals and positions in collection lists. We are going to implement the base library object called Engine and add collection of market orders and positions to the library.
Graphical Interfaces I: Testing Library in Programs of Different Types and in the MetaTrader 4 Terminal (Chapter 5)
Graphical Interfaces I: Testing Library in Programs of Different Types and in the MetaTrader 4 Terminal (Chapter 5)

Graphical Interfaces I: Testing Library in Programs of Different Types and in the MetaTrader 4 Terminal (Chapter 5)

In the previous chapter of the first part of the series about graphical interfaces, the form class was enriched by methods which allowed managing the form by pressing its controls. In this article, we will test our work in different types of MQL program such as indicators and scripts. As the library was designed to be cross-platform so it could be used in all MetaTrader platforms, we will also test it in MetaTrader 4.
Practical Use of Kohonen Neural Networks in Algorithmic Trading. Part II. Optimizing and forecasting
Practical Use of Kohonen Neural Networks in Algorithmic Trading. Part II. Optimizing and forecasting

Practical Use of Kohonen Neural Networks in Algorithmic Trading. Part II. Optimizing and forecasting

Based on universal tools designed for working with Kohonen networks, we construct the system of analyzing and selecting the optimal EA parameters and consider forecasting time series. In Part I, we corrected and improved the publicly available neural network classes, having added necessary algorithms. Now, it is time to apply them to practice.
MQL5 Cookbook: Using Different Print Modes
MQL5 Cookbook: Using Different Print Modes

MQL5 Cookbook: Using Different Print Modes

This is the first article of the MQL5 Cookbook series. I will start with simple examples to allow those who are taking their first steps in programming to gradually become familiar with the new language. I remember my first efforts at designing and programming trading systems which I may say was quite difficult, given the fact that it was the first programming language in my life. However, it turned out to be easier than I thought and it only took me a few months before I could develop a fairly complex program.
preview
Developing a trading Expert Advisor from scratch (Part 19): New order system (II)

Developing a trading Expert Advisor from scratch (Part 19): New order system (II)

In this article, we will develop a graphical order system of the "look what happens" type. Please note that we are not starting from scratch this time, but we will modify the existing system by adding more objects and events on the chart of the asset we are trading.
preview
Creating a comprehensive Owl trading strategy

Creating a comprehensive Owl trading strategy

My strategy is based on the classic trading fundamentals and the refinement of indicators that are widely used in all types of markets. This is a ready-made tool allowing you to follow the proposed new profitable trading strategy.
The Last Crusade
The Last Crusade

The Last Crusade

Take a look at your trading terminal. What means of price presentation can you see? Bars, candlesticks, lines. We are chasing time and prices whereas we only profit from prices. Shall we only give attention to prices when analyzing the market? This article proposes an algorithm and a script for point and figure charting ("naughts and crosses") Consideration is given to various price patterns whose practical use is outlined in recommendations provided.
MQL5 Cookbook: Indicator Subwindow Controls - Scrollbar
MQL5 Cookbook: Indicator Subwindow Controls - Scrollbar

MQL5 Cookbook: Indicator Subwindow Controls - Scrollbar

Let's continue exploring various controls and this time turn our attention to scrollbar. Just like in the previous article entitled "MQL5 Cookbook: Indicator Subwindow Controls - Buttons", all operations will be performed in the indicator subwindow. Take a moment to read the above mentioned article as it provides a detailed description of working with events in the OnChartEvent() function, while this point will only be casually touched upon in this article. For illustrative purposes, this time around we will create a vertical scrollbar for a large list of all financial instrument properties that can be obtained using MQL5 resources.
Prices in DoEasy library (Part 64): Depth of Market, classes of DOM snapshot and snapshot series objects
Prices in DoEasy library (Part 64): Depth of Market, classes of DOM snapshot and snapshot series objects

Prices in DoEasy library (Part 64): Depth of Market, classes of DOM snapshot and snapshot series objects

In this article, I will create two classes (the class of DOM snapshot object and the class of DOM snapshot series object) and test creation of the DOM data series.
Library for easy and quick development of MetaTrader programs (part VIII): Order and position modification events
Library for easy and quick development of MetaTrader programs (part VIII): Order and position modification events

Library for easy and quick development of MetaTrader programs (part VIII): Order and position modification events

In the previous articles, we started creating a large cross-platform library simplifying the development of programs for MetaTrader 5 and MetaTrader 4 platforms. In the seventh part, we added tracking StopLimit orders activation and prepared the functionality for tracking other events involving orders and positions. In this article, we will develop the class for tracking order and position modification events.
preview
Brute force approach to pattern search

Brute force approach to pattern search

In this article, we will search for market patterns, create Expert Advisors based on the identified patterns, and check how long these patterns remain valid, if they ever retain their validity.
How to visualize multicurrency trading history based on HTML and CSV reports
How to visualize multicurrency trading history based on HTML and CSV reports

How to visualize multicurrency trading history based on HTML and CSV reports

Since its introduction, MetaTrader 5 provides multicurrency testing options. This possibility is often used by traders. However the function is not universal. The article presents several programs for drawing graphical objects on charts based on HTML and CSV trading history reports. Multicurrency trading can be analyzed in parallel, in several sub-windows, as well as in one window using the dynamic switching command.
Graphical Interfaces X: Sorting, rebuilding the table and controls in the cells (build 11)
Graphical Interfaces X: Sorting, rebuilding the table and controls in the cells (build 11)

Graphical Interfaces X: Sorting, rebuilding the table and controls in the cells (build 11)

We continue to add new features to the rendered table: data sorting, managing the number of columns and rows, setting the table cell types to place controls into them.
Better programmer (Part 05): How to become a faster developer
Better programmer (Part 05): How to become a faster developer

Better programmer (Part 05): How to become a faster developer

Every developer wants to be able to write code faster, and being able to code faster and effective is not some kind of special ability that only a few people are born with. It's a skill that can be learned, that is what I'm trying to teach in this article.
Developing multi-module Expert Advisors
Developing multi-module Expert Advisors

Developing multi-module Expert Advisors

MQL programming language allows implementing the concept of modular development of trading strategies. The article shows an example of developing a multi-module Expert Advisor consisting of separately compiled file modules.
Graphical Interfaces X: Word wrapping algorithm in the Multiline Text box (build 12)
Graphical Interfaces X: Word wrapping algorithm in the Multiline Text box (build 12)

Graphical Interfaces X: Word wrapping algorithm in the Multiline Text box (build 12)

We continue to develop the Multiline Text box control. This time our task is to implement an automatic word wrapping in case a text box width overflow occurs, or a reverse word wrapping of the text to the previous line if the opportunity arises.
Extending MQL5 Standard Library and Reusing Code
Extending MQL5 Standard Library and Reusing Code

Extending MQL5 Standard Library and Reusing Code

MQL5 Standard Library makes your life as a developer easier. Nevertheless, it does not implement all the needs of all developers in the world, so if you feel that you need some more custom stuff you can take a step further and extend. This article walks you through integrating MetaQuotes' Zig-Zag technical indicator into the Standard Library. We get inspired by MetaQuotes' design philosophy to achieve our goal.
preview
Learn how to design a trading system by VIDYA

Learn how to design a trading system by VIDYA

Welcome to a new article from our series about learning how to design a trading system by the most popular technical indicators, in this article we will learn about a new technical tool and learn how to design a trading system by Variable Index Dynamic Average (VIDYA).
preview
Neural networks made easy (Part 9): Documenting the work

Neural networks made easy (Part 9): Documenting the work

We have already passed a long way and the code in our library is becoming bigger and bigger. This makes it difficult to keep track of all connections and dependencies. Therefore, I suggest creating documentation for the earlier created code and to keep it updating with each new step. Properly prepared documentation will help us see the integrity of our work.
Graphics in DoEasy library (Part 86): Graphical object collection - managing property modification
Graphics in DoEasy library (Part 86): Graphical object collection - managing property modification

Graphics in DoEasy library (Part 86): Graphical object collection - managing property modification

In this article, I will consider tracking property value modification, as well as removing and renaming graphical objects in the library.
Combinatorics and probability theory for trading (Part II): Universal fractal
Combinatorics and probability theory for trading (Part II): Universal fractal

Combinatorics and probability theory for trading (Part II): Universal fractal

In this article, we will continue to study fractals and will pay special attention to summarizing all the material. To do this, I will try to bring all earlier developments into a compact form which would be convenient and understandable for practical application in trading.
Movement continuation model - searching on the chart and execution statistics
Movement continuation model - searching on the chart and execution statistics

Movement continuation model - searching on the chart and execution statistics

This article provides programmatic definition of one of the movement continuation models. The main idea is defining two waves — the main and the correction one. For extreme points, I apply fractals as well as "potential" fractals - extreme points that have not yet formed as fractals.
preview
Neural networks made easy (Part 3): Convolutional networks

Neural networks made easy (Part 3): Convolutional networks

As a continuation of the neural network topic, I propose considering convolutional neural networks. This type of neural network are usually applied to analyzing visual imagery. In this article, we will consider the application of these networks in the financial markets.
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.
Swaps (Part I): Locking and Synthetic Positions
Swaps (Part I): Locking and Synthetic Positions

Swaps (Part I): Locking and Synthetic Positions

In this article I will try to expand the classic concept of swap trading methods. I will explain why I have come to the conclusion that this concept deserves special attention and is absolutely recommended for study.
Graphics in DoEasy library (Part 83): Class of the abstract standard graphical object
Graphics in DoEasy library (Part 83): Class of the abstract standard graphical object

Graphics in DoEasy library (Part 83): Class of the abstract standard graphical object

In this article, I will create the class of the abstract graphical object. This object is to serve as a basis for creating the class of standard graphical objects. Graphical objects feature multiple properties. Therefore, I will need to do a lot of preparatory work before actually creating the abstract graphical object class. This work includes setting the properties in the library enumerations.
preview
Making charts more interesting: Adding a background

Making charts more interesting: Adding a background

Many workstations contain some representative image which shows something about the user. These images make the working environment more beautiful and exciting. Let's see how to make the charts more interesting by adding a background.
A system of voice notifications for trade events and signals
A system of voice notifications for trade events and signals

A system of voice notifications for trade events and signals

Nowadays, voice assistants play a prominent role in human life, as we often use navigators, voice search and translators. In this article, I will try to develop a simple and user friendly system of voice notifications for various trade events, market states or signals generated by trading signals.
preview
Brute force approach to pattern search (Part III): New horizons

Brute force approach to pattern search (Part III): New horizons

This article provides a continuation to the brute force topic, and it introduces new opportunities for market analysis into the program algorithm, thereby accelerating the speed of analysis and improving the quality of results. New additions enable the highest-quality view of global patterns within this approach.
MQL5 Cookbook: Analyzing Position Properties in the MetaTrader 5 Strategy Tester
MQL5 Cookbook: Analyzing Position Properties in the MetaTrader 5 Strategy Tester

MQL5 Cookbook: Analyzing Position Properties in the MetaTrader 5 Strategy Tester

We will present a modified version of the Expert Advisor from the previous article "MQL5 Cookbook: Position Properties on the Custom Info Panel". Some of the issues we will address include getting data from bars, checking for new bar events on the current symbol, including a trade class of the Standard Library to a file, creating a function to search for trading signals and a function for executing trading operations, as well as determining trade events in the OnTrade() function.
preview
Understanding order placement in MQL5

Understanding order placement in MQL5

When creating any trading system, there is a task we need to deal with effectively. This task is order placement or to let the created trading system deal with orders automatically because it is crucial in any trading system. So, you will find in this article most of the topics that you need to understand about this task to create your trading system in terms of order placement effectively.
An Example of Developing a Spread Strategy for Moscow Exchange Futures
An Example of Developing a Spread Strategy for Moscow Exchange Futures

An Example of Developing a Spread Strategy for Moscow Exchange Futures

The MetaTrader 5 platform allows developing and testing trading robots that simultaneously trade multiple financial instruments. The built-in Strategy Tester automatically downloads required tick history from the broker's server taking into account contract specifications, so the developer does not need to do anything manually. This makes it possible to easily and reliably reproduce trading environment conditions, including even millisecond intervals between the arrival of ticks on different symbols. In this article we will demonstrate the development and testing of a spread strategy on two Moscow Exchange futures.
Deep Neural Networks (Part III). Sample selection and dimensionality reduction
Deep Neural Networks (Part III). Sample selection and dimensionality reduction

Deep Neural Networks (Part III). Sample selection and dimensionality reduction

This article is a continuation of the series of articles about deep neural networks. Here we will consider selecting samples (removing noise), reducing the dimensionality of input data and dividing the data set into the train/val/test sets during data preparation for training the neural network.
preview
Gradient Boosting (CatBoost) in the development of trading systems. A naive approach

Gradient Boosting (CatBoost) in the development of trading systems. A naive approach

Training the CatBoost classifier in Python and exporting the model to mql5, as well as parsing the model parameters and a custom strategy tester. The Python language and the MetaTrader 5 library are used for preparing the data and for training the model.
Freelance Jobs on MQL5.com - Developer's Favorite Place
Freelance Jobs on MQL5.com - Developer's Favorite Place

Freelance Jobs on MQL5.com - Developer's Favorite Place

Developers of trading robots no longer need to market their services to traders that require Expert Advisors - as now they will find you. Already, thousands of traders place orders to MQL5 freelance developers, and pay for work in on MQL5.com. For 4 years, this service facilitated three thousand traders to pay for more than 10 000 jobs performed. And the activity of traders and developers is constantly growing!
Custom Graphical Controls. Part 3. Forms
Custom Graphical Controls. Part 3. Forms

Custom Graphical Controls. Part 3. Forms

This is the last of the three articles devoted to graphical controls. It covers the creation of the main graphical interface component - the form - and its use in combination with other controls. In addition to the form classes, CFrame, CButton, CLabel classes have been added to the control library.
Graphical Interfaces IX: The Color Picker Control (Chapter 1)
Graphical Interfaces IX: The Color Picker Control (Chapter 1)

Graphical Interfaces IX: The Color Picker Control (Chapter 1)

With this article we begin chapter nine of series of articles dedicated to creating graphical interfaces in MetaTrader trading terminals. It consists of two chapters where new elements of controls and interface, such as color picker, color button, progress bar and line chart are presented.