Articles with MQL5 programming examples

icon

Access a huge collection of articles with code examples showing how to create indicators and trading robots for the MetaTrader platform in the MQL5 language. Source codes are attached to the articles, so you can open them in MetaEditor and run them to see how the applications work.

These articles will be useful both for those who have just started exploring automated trading and for professional traders with programming experience. They feature not only examples, but also contain new ideas.

Add a new article
latest | best
Graphical Interfaces VIII: The Tree View Control (Chapter 2)
Graphical Interfaces VIII: The Tree View Control (Chapter 2)

Graphical Interfaces VIII: The Tree View Control (Chapter 2)

The previous chapter of part VIII on graphical interfaces has focused on the elements of static and drop-down calendar. The second chapter will be dedicated to an equally complex element — a tree view, that is included in every complete library used for creating graphical interfaces. A tree view implemented in this article contains multiple flexible settings and modes, thus allowing to adjust this element of control to your needs.
preview
Evaluating ONNX models using regression metrics

Evaluating ONNX models using regression metrics

Regression is a task of predicting a real value from an unlabeled example. The so-called regression metrics are used to assess the accuracy of regression model predictions.
Tracing, Debugging and Structural Analysis of Source Code
Tracing, Debugging and Structural Analysis of Source Code

Tracing, Debugging and Structural Analysis of Source Code

The entire complex of problems of creating a structure of an executed code and its tracing can be solved without serious difficulties. This possibility has appeared in MetaTrader 5 due to the new feature of the MQL5 language - automatic creation of variables of complex type of data (structures and classes) and their elimination when going out of local scope. The article contains the description of the methodology and the ready-made tool.
Graphics in DoEasy library (Part 94): Moving and deleting composite graphical objects
Graphics in DoEasy library (Part 94): Moving and deleting composite graphical objects

Graphics in DoEasy library (Part 94): Moving and deleting composite graphical objects

In this article, I will start the development of various composite graphical object events. We will also partially consider moving and deleting a composite graphical object. In fact, here I am going to fine-tune the things I implemented in the previous article.
preview
How to create a simple Multi-Currency Expert Advisor using MQL5 (Part 2): Indicator Signals: Multi Timeframe Parabolic SAR Indicator

How to create a simple Multi-Currency Expert Advisor using MQL5 (Part 2): Indicator Signals: Multi Timeframe Parabolic SAR Indicator

The Multi-Currency Expert Advisor in this article is Expert Advisor or trading robot that can trade (open orders, close orders and manage orders for example: Trailing Stop Loss and Trailing Profit) for more than 1 symbol pair only from one symbol chart. This time we will use only 1 indicator, namely Parabolic SAR or iSAR in multi-timeframes starting from PERIOD_M15 to PERIOD_D1.
Graphics in DoEasy library (Part 89): Programming standard graphical objects. Basic functionality
Graphics in DoEasy library (Part 89): Programming standard graphical objects. Basic functionality

Graphics in DoEasy library (Part 89): Programming standard graphical objects. Basic functionality

Currently, the library is able to track standard graphical objects on the client terminal chart, including their removal and modification of some of their parameters. At the moment, it lacks the ability to create standard graphical objects from custom programs.
Other classes in DoEasy library (Part 70): Expanding functionality and auto updating the chart object collection
Other classes in DoEasy library (Part 70): Expanding functionality and auto updating the chart object collection

Other classes in DoEasy library (Part 70): Expanding functionality and auto updating the chart object collection

In this article, I will expand the functionality of chart objects and arrange navigation through charts, creation of screenshots, as well as saving and applying templates to charts. Also, I will implement auto update of the collection of chart objects, their windows and indicators within them.
Prices in DoEasy library (part 60): Series list of symbol tick data
Prices in DoEasy library (part 60): Series list of symbol tick data

Prices in DoEasy library (part 60): Series list of symbol tick data

In this article, I will create the list for storing tick data of a single symbol and check its creation and retrieval of required data in an EA. Tick data lists that are individual for each used symbol will further constitute a collection of tick data.
Calculation of Integral Characteristics of Indicator Emissions
Calculation of Integral Characteristics of Indicator Emissions

Calculation of Integral Characteristics of Indicator Emissions

Indicator emissions are a little-studied area of market research. Primarily, this is due to the difficulty of analysis that is caused by the processing of very large arrays of time-varying data. Existing graphical analysis is too resource intensive and has therefore triggered the development of a parsimonious algorithm that uses time series of emissions. This article demonstrates how visual (intuitive image) analysis can be replaced with the study of integral characteristics of emissions. It can be of interest to both traders and developers of automated trading systems.
Graphics in DoEasy library (Part 80): "Geometric animation frame" object class
Graphics in DoEasy library (Part 80): "Geometric animation frame" object class

Graphics in DoEasy library (Part 80): "Geometric animation frame" object class

In this article, I will optimize the code of classes from the previous articles and create the geometric animation frame object class allowing us to draw regular polygons with a given number of vertices.
Graphical Interfaces XI: Rendered controls (build 14.2)
Graphical Interfaces XI: Rendered controls (build 14.2)

Graphical Interfaces XI: Rendered controls (build 14.2)

In the new version of the library, all controls will be drawn on separate graphical objects of the OBJ_BITMAP_LABEL type. We will also continue to describe the optimization of code: changes in the core classes of the library will be discussed.
Library for easy and quick development of MetaTrader programs (part IX): Compatibility with MQL4 - Preparing data
Library for easy and quick development of MetaTrader programs (part IX): Compatibility with MQL4 - Preparing data

Library for easy and quick development of MetaTrader programs (part IX): Compatibility with MQL4 - Preparing data

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 eighth part, we implemented the class for tracking order and position modification events. Here, we will improve the library by making it fully compatible with MQL4.
preview
Neural networks made easy (Part 13): Batch Normalization

Neural networks made easy (Part 13): Batch Normalization

In the previous article, we started considering methods aimed at improving neural network training quality. In this article, we will continue this topic and will consider another approach — batch data normalization.
MQL5 Programming Basics: Global Variables of the Terminal
MQL5 Programming Basics: Global Variables of the Terminal

MQL5 Programming Basics: Global Variables of the Terminal

This article highlights object-oriented capabilities of the MQL5 language for creating objects facilitating work with global variables of the terminal. As a practical example I consider a case when global variables are used as control points for implementation of program stages.
preview
Developing a Replay System — Market simulation (Part 03): Adjusting the settings (I)

Developing a Replay System — Market simulation (Part 03): Adjusting the settings (I)

Let's start by clarifying the current situation, because we didn't start in the best way. If we don't do it now, we'll be in trouble soon.
preview
Population optimization algorithms: Particle swarm (PSO)

Population optimization algorithms: Particle swarm (PSO)

In this article, I will consider the popular Particle Swarm Optimization (PSO) algorithm. Previously, we discussed such important characteristics of optimization algorithms as convergence, convergence rate, stability, scalability, as well as developed a test stand and considered the simplest RNG algorithm.
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.
Prices in DoEasy library (part 62): Updating tick series in real time, preparation for working with Depth of Market
Prices in DoEasy library (part 62): Updating tick series in real time, preparation for working with Depth of Market

Prices in DoEasy library (part 62): Updating tick series in real time, preparation for working with Depth of Market

In this article, I will implement updating tick data in real time and prepare the symbol object class for working with Depth of Market (DOM itself is to be implemented in the next article).
preview
Timeseries in DoEasy library (part 58): Timeseries of indicator buffer data

Timeseries in DoEasy library (part 58): Timeseries of indicator buffer data

In conclusion of the topic of working with timeseries organise storage, search and sort of data stored in indicator buffers which will allow to further perform the analysis based on values of the indicators to be created on the library basis in programs. The general concept of all collection classes of the library allows to easily find necessary data in the corresponding collection. Respectively, the same will be possible in the class created today.
Library for easy and quick development of MetaTrader programs (part VI): Netting account events
Library for easy and quick development of MetaTrader programs (part VI): Netting account events

Library for easy and quick development of MetaTrader programs (part VI): Netting account 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 fifth part of the article series, we created trading event classes and the event collection, from which the events are sent to the base object of the Engine library and the control program chart. In this part, we will let the library to work on netting accounts.
Other classes in DoEasy library (Part 67): Chart object class
Other classes in DoEasy library (Part 67): Chart object class

Other classes in DoEasy library (Part 67): Chart object class

In this article, I will create the chart object class (of a single trading instrument chart) and improve the collection class of MQL5 signal objects so that each signal object stored in the collection updates all its parameters when updating the list.
preview
Timeseries in DoEasy library (part 55): Indicator collection class

Timeseries in DoEasy library (part 55): Indicator collection class

The article continues developing indicator object classes and their collections. For each indicator object create its description and correct collection class for error-free storage and getting indicator objects from the collection list.
Graphical interfaces X: New features for the Rendered table (build 9)
Graphical interfaces X: New features for the Rendered table (build 9)

Graphical interfaces X: New features for the Rendered table (build 9)

Until today, the CTable was the most advanced type of tables among all presented in the library. This table is assembled from edit boxes of the OBJ_EDIT type, and its further development becomes problematic. Therefore, in terms of maximum capabilities, it is better to develop rendered tables of the CCanvasTable type even at the current development stage of the library. Its current version is completely lifeless, but starting from this article, we will try to fix the situation.
Graphics in DoEasy library (Part 87): Graphical object collection - managing object property modification on all open charts
Graphics in DoEasy library (Part 87): Graphical object collection - managing object property modification on all open charts

Graphics in DoEasy library (Part 87): Graphical object collection - managing object property modification on all open charts

In this article, I will continue my work on tracking standard graphical object events and create the functionality allowing users to control changes in the properties of graphical objects placed on any charts opened in the terminal.
preview
DoEasy. Controls (Part 2): Working on the CPanel class

DoEasy. Controls (Part 2): Working on the CPanel class

In the current article, I will get rid of some errors related to handling graphical elements and continue the development of the CPanel control. In particular, I will implement the methods for setting the parameters of the font used by default for all panel text objects.
preview
Complex indicators made easy using objects

Complex indicators made easy using objects

This article provides a method to create complex indicators while also avoiding the problems that arise when dealing with multiple plots, buffers and/or combining data from multiple sources.
preview
Matrix and Vector operations in MQL5

Matrix and Vector operations in MQL5

Matrices and vectors have been introduced in MQL5 for efficient operations with mathematical solutions. The new types offer built-in methods for creating concise and understandable code that is close to mathematical notation. Arrays provide extensive capabilities, but there are many cases in which matrices are much more efficient.
preview
Creating an EA that works automatically (Part 15): Automation (VII)

Creating an EA that works automatically (Part 15): Automation (VII)

To complete this series of articles on automation, we will continue discussing the topic of the previous article. We will see how everything will fit together, making the EA run like clockwork.
preview
Build Self Optmising Expert Advisors in MQL5

Build Self Optmising Expert Advisors in MQL5

Build expert advisors that look forward and adjust themselves to any market.
preview
Timeseries in DoEasy library (part 49): Multi-period multi-symbol multi-buffer standard indicators

Timeseries in DoEasy library (part 49): Multi-period multi-symbol multi-buffer standard indicators

In the current article, I will improve the library classes to implement the ability to develop multi-symbol multi-period standard indicators requiring several indicator buffers to display their data.
preview
Timeseries in DoEasy library (part 56): Custom indicator object, get data from indicator objects in the collection

Timeseries in DoEasy library (part 56): Custom indicator object, get data from indicator objects in the collection

The article considers creation of the custom indicator object for the use in EAs. Let’s slightly improve library classes and add methods to get data from indicator objects in EAs.
DIY technical indicator
DIY technical indicator

DIY technical indicator

In this article, I will consider the algorithms allowing you to create your own technical indicator. You will learn how to obtain pretty complex and interesting results with very simple initial assumptions.
Other classes in DoEasy library (Part 68): Chart window object class and indicator object classes in the chart window
Other classes in DoEasy library (Part 68): Chart window object class and indicator object classes in the chart window

Other classes in DoEasy library (Part 68): Chart window object class and indicator object classes in the chart window

In this article, I will continue the development of the chart object class. I will add the list of chart window objects featuring the lists of available indicators.
Graphics in DoEasy library (Part 79): "Animation frame" object class and its descendant objects
Graphics in DoEasy library (Part 79): "Animation frame" object class and its descendant objects

Graphics in DoEasy library (Part 79): "Animation frame" object class and its descendant objects

In this article, I will develop the class of a single animation frame and its descendants. The class is to allow drawing shapes while maintaining and then restoring the background under them.
preview
Population optimization algorithms: Ant Colony Optimization (ACO)

Population optimization algorithms: Ant Colony Optimization (ACO)

This time I will analyze the Ant Colony optimization algorithm. The algorithm is very interesting and complex. In the article, I make an attempt to create a new type of ACO.
Other classes in DoEasy library (Part 71): Chart object collection events
Other classes in DoEasy library (Part 71): Chart object collection events

Other classes in DoEasy library (Part 71): Chart object collection events

In this article, I will create the functionality for tracking some chart object events — adding/removing symbol charts and chart subwindows, as well as adding/removing/changing indicators in chart windows.
Better Programmer (Part 04): How to become a faster developer
Better Programmer (Part 04): How to become a faster developer

Better Programmer (Part 04): 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 by every coder, regardless of years of experience on the keyboard.
MQL5 Cookbook: Reducing the Effect of Overfitting and Handling the Lack of Quotes
MQL5 Cookbook: Reducing the Effect of Overfitting and Handling the Lack of Quotes

MQL5 Cookbook: Reducing the Effect of Overfitting and Handling the Lack of Quotes

Whatever trading strategy you use, there will always be a question of what parameters to choose to ensure future profits. This article gives an example of an Expert Advisor with a possibility to optimize multiple symbol parameters at the same time. This method is intended to reduce the effect of overfitting parameters and handle situations where data from a single symbol are not enough for the study.
Graphics in DoEasy library (Part 91): Standard graphical object events. Object name change history
Graphics in DoEasy library (Part 91): Standard graphical object events. Object name change history

Graphics in DoEasy library (Part 91): Standard graphical object events. Object name change history

In this article, I will refine the basic functionality for providing control over graphical object events from a library-based program. I will start from implementing the functionality for storing the graphical object change history using the "Object name" property as an example.
preview
Neural networks made easy (Part 14): Data clustering

Neural networks made easy (Part 14): Data clustering

It has been more than a year since I published my last article. This is quite a lot time to revise ideas and to develop new approaches. In the new article, I would like to divert from the previously used supervised learning method. This time we will dip into unsupervised learning algorithms. In particular, we will consider one of the clustering algorithms—k-means.