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 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.
preview
Tips from a professional programmer (Part I): Code storing, debugging and compiling. Working with projects and logs

Tips from a professional programmer (Part I): Code storing, debugging and compiling. Working with projects and logs

These are some tips from a professional programmer about methods, techniques and auxiliary tools which can make programming easier.
Graphical Interfaces V: The List View Element (Chapter 2)
Graphical Interfaces V: The List View Element (Chapter 2)

Graphical Interfaces V: The List View Element (Chapter 2)

In the previous chapter, we wrote classes for creating vertical and horizontal scrollbars. In this chapter, we will implement them. We will write a class for creating the list view element, a compound part of which will be a vertical scrollbar.
Promote Your Development Projects Using EX5 Libraries
Promote Your Development Projects Using EX5 Libraries

Promote Your Development Projects Using EX5 Libraries

Hiding of the implementation details of classes/functions in an .ex5 file will enable you to share your know-how algorithms with other developers, set up common projects and promote them in the Web. And while the MetaQuotes team spares no effort to bring about the possibility of direct inheritance of ex5 library classes, we are going to implement it right now.
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.
MQL5 Cookbook: Handling BookEvent
MQL5 Cookbook: Handling BookEvent

MQL5 Cookbook: Handling BookEvent

This article considers BookEvent - a Depth of Market event, and the principle of its processing. An MQL program, handling states of Depth of Market, serves as an example. It is written using the object-oriented approach. Results of handling are displayed on the screen as a panel and Depth of Market levels.
preview
Adaptive indicators

Adaptive indicators

In this article, I will consider several possible approaches to creating adaptive indicators. Adaptive indicators are distinguished by the presence of feedback between the values of the input and output signals. This feedback allows the indicator to independently adjust to the optimal processing of financial time series values.
preview
Implementing an ARIMA training algorithm in MQL5

Implementing an ARIMA training algorithm in MQL5

In this article we will implement an algorithm that applies the Box and Jenkins Autoregressive Integrated Moving Average model by using Powells method of function minimization. Box and Jenkins stated that most time series could be modeled by one or both of two frameworks.
Graphical Interfaces VIII: The Calendar Control (Chapter 1)
Graphical Interfaces VIII: The Calendar Control (Chapter 1)

Graphical Interfaces VIII: The Calendar Control (Chapter 1)

In the part VIII of the series of articles dedicated to creating graphical interfaces in MetaTrader, we will consider complex composite controls like calendars, tree view, and file navigator. Due to the large amount of information, there are separate articles written for every subject. The first chapter of this part describes the calendar control and its expanded version — a drop down calendar.
Graphics in DoEasy library (Part 95): Composite graphical object controls
Graphics in DoEasy library (Part 95): Composite graphical object controls

Graphics in DoEasy library (Part 95): Composite graphical object controls

In this article, I will consider the toolkit for managing composite graphical objects - controls for managing an extended standard graphical object. Today, I will slightly digress from relocating a composite graphical object and implement the handler of change events on a chart featuring a composite graphical object. Besides, I will focus on the controls for managing a composite graphical object.
preview
How to create a simple Multi-Currency Expert Advisor using MQL5 (Part 1): Indicator Signals based on ADX in combination with Parabolic SAR

How to create a simple Multi-Currency Expert Advisor using MQL5 (Part 1): Indicator Signals based on ADX in combination with Parabolic SAR

The Multi-Currency Expert Advisor in this article is Expert Advisor or trading robot that can trade (open orders, close orders and manage orders an more) for more than 1 symbol pair only from one symbol chart.
preview
Using the CCanvas class in MQL applications

Using the CCanvas class in MQL applications

The article considers the use of the CCanvas class in MQL applications. The theory is accompanied by detailed explanations and examples for thorough understanding of CCanvas basics.
Graphical Interfaces II: Setting Up the Event Handlers of the Library (Chapter 3)
Graphical Interfaces II: Setting Up the Event Handlers of the Library (Chapter 3)

Graphical Interfaces II: Setting Up the Event Handlers of the Library (Chapter 3)

The previous articles contain the implementation of the classes for creating constituent parts of the main menu. Now, it is time to take a close look at the event handlers in the principle base classes and in the classes of the created controls. We will also pay special attention to managing the state of the chart depending on the location of the mouse cursor.
Prices in DoEasy library (part 63): Depth of Market and its abstract request class
Prices in DoEasy library (part 63): Depth of Market and its abstract request class

Prices in DoEasy library (part 63): Depth of Market and its abstract request class

In the article, I will start developing the functionality for working with the Depth of Market. I will also create the class of the Depth of Market abstract order object and its descendants.
Using Layouts and Containers for GUI Controls: The CGrid Class
Using Layouts and Containers for GUI Controls: The CGrid Class

Using Layouts and Containers for GUI Controls: The CGrid Class

This article presents an alternative method of GUI creation based on layouts and containers, using one layout manager — the CGrid class. The CGrid class is an auxiliary control that acts as a container for other containers and controls using a grid layout.
Graphical Interfaces XI: Text edit boxes and Combo boxes in table cells (build 15)
Graphical Interfaces XI: Text edit boxes and Combo boxes in table cells (build 15)

Graphical Interfaces XI: Text edit boxes and Combo boxes in table cells (build 15)

In this update of the library, the Table control (the CTable class) will be supplemented with new options. The lineup of controls in the table cells is expanded, this time adding text edit boxes and combo boxes. As an addition, this update also introduces the ability to resize the window of an MQL application during its runtime.
Library for easy and quick development of MetaTrader programs (part VII): StopLimit order activation events, preparing the functionality for order and position modification events
Library for easy and quick development of MetaTrader programs (part VII): StopLimit order activation events, preparing the functionality for order and position modification events

Library for easy and quick development of MetaTrader programs (part VII): StopLimit order activation events, preparing the functionality for 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 sixth part, we trained the library to work with positions on netting accounts. Here we will implement tracking StopLimit orders activation and prepare the functionality to track order and position modification events.
Graphical Interfaces XI: Integrating the Standard Graphics Library (build 16)
Graphical Interfaces XI: Integrating the Standard Graphics Library (build 16)

Graphical Interfaces XI: Integrating the Standard Graphics Library (build 16)

A new version of the graphics library for creating scientific charts (the CGraphic class) has been presented recently. This update of the developed library for creating graphical interfaces will introduce a version with a new control for creating charts. Now it is even easier to visualize data of different types.
preview
Neural networks made easy (Part 6): Experimenting with the neural network learning rate

Neural networks made easy (Part 6): Experimenting with the neural network learning rate

We have previously considered various types of neural networks along with their implementations. In all cases, the neural networks were trained using the gradient decent method, for which we need to choose a learning rate. In this article, I want to show the importance of a correctly selected rate and its impact on the neural network training, using examples.
MQL5 Cookbook - Multi-Currency Expert Advisor and Working with Pending Orders in MQL5
MQL5 Cookbook - Multi-Currency Expert Advisor and Working with Pending Orders in MQL5

MQL5 Cookbook - Multi-Currency Expert Advisor and Working with Pending Orders in MQL5

This time we are going to create a multi-currency Expert Advisor with a trading algorithm based on work with the pending orders Buy Stop and Sell Stop. This article considers the following matters: trading in a specified time range, placing/modifying/deleting pending orders, checking if the last position was closed at Take Profit or Stop Loss and control of the deals history for each symbol.
Timeseries in DoEasy library (part 46): Multi-period multi-symbol indicator buffers
Timeseries in DoEasy library (part 46): Multi-period multi-symbol indicator buffers

Timeseries in DoEasy library (part 46): Multi-period multi-symbol indicator buffers

In this article, I am going to improve the classes of indicator buffer objects to work in the multi-symbol mode. This will pave the way for creating multi-symbol multi-period indicators in custom programs. I will add the missing functionality to the calculated buffer objects allowing us to create multi-symbol multi-period standard indicators.
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.
How to Quickly Create an Expert Advisor for Automated Trading Championship 2010
How to Quickly Create an Expert Advisor for Automated Trading Championship 2010

How to Quickly Create an Expert Advisor for Automated Trading Championship 2010

In order to develop an expert to participate in Automated Trading Championship 2010, let's use a template of ready expert advisor. Even novice MQL5 programmer will be capable of this task, because for your strategies the basic classes, functions, templates are already developed. It's enough to write a minimal amount of code to implement your trading idea.
Optimization. A Few Simple Ideas
Optimization. A Few Simple Ideas

Optimization. A Few Simple Ideas

The optimization process can require significant resources of your computer or even of the MQL5 Cloud Network test agents. This article comprises some simple ideas that I use for work facilitation and improvement of the MetaTrader 5 Strategy Tester. I got these ideas from the documentation, forum and articles.
Graphics in DoEasy library (Part 77): Shadow object class
Graphics in DoEasy library (Part 77): Shadow object class

Graphics in DoEasy library (Part 77): Shadow object class

In this article, I will create a separate class for the shadow object, which is a descendant of the graphical element object, as well as add the ability to fill the object background with a gradient fill.
Other classes in DoEasy library (Part 72): Tracking and recording chart object parameters in the collection
Other classes in DoEasy library (Part 72): Tracking and recording chart object parameters in the collection

Other classes in DoEasy library (Part 72): Tracking and recording chart object parameters in the collection

In this article, I will complete working with chart object classes and their collection. I will also implement auto tracking of changes in chart properties and their windows, as well as saving new parameters to the object properties. Such a revision allows the future implementation of an event functionality for the entire chart collection.
Using Pseudo-Templates as Alternative to C++ Templates
Using Pseudo-Templates as Alternative to C++ Templates

Using Pseudo-Templates as Alternative to C++ Templates

The article describes a way of programming without using templates but keeping the style of programming iherenet to them. It tells about implementation of templates using custom methods and has a ready-made script attached for creating a code on the basis of specified templates.
Programming EA's Modes Using Object-Oriented Approach
Programming EA's Modes Using Object-Oriented Approach

Programming EA's Modes Using Object-Oriented Approach

This article explains the idea of multi-mode trading robot programming in MQL5. Every mode is implemented with the object-oriented approach. Instances of both mode classes hierarchy and classes for testing are provided. Multi-mode programming of trading robots is supposed to take into account all peculiarities of every operational mode of an EA written in MQL5. Functions and enumeration are created for identifying the mode.
Custom Graphical Controls. Part 2. Control Library
Custom Graphical Controls. Part 2. Control Library

Custom Graphical Controls. Part 2. Control Library

The second article of the "Custom Graphical Controls" series introduces a control library for handling the main problems arising in interaction between a program (Expert Advisor, script, indicator) and a user. The library contains a great number of classes (CInputBox, CSpinInputBox, CCheckBox, CRadioGroup, CVSсrollBar, CHSсrollBar, CList, CListMS, CComBox, CHMenu, CVMenu, CHProgress, CDialer, CDialerInputBox, CTable) and examples of their use.
Timeseries in DoEasy library (part 45): Multi-period indicator buffers
Timeseries in DoEasy library (part 45): Multi-period indicator buffers

Timeseries in DoEasy library (part 45): Multi-period indicator buffers

In this article, I will start the improvement of the indicator buffer objects and collection class for working in multi-period and multi-symbol modes. I am going to consider the operation of buffer objects for receiving and displaying data from any timeframe on the current symbol chart.
Studying the CCanvas Class. Anti-aliasing and Shadows
Studying the CCanvas Class. Anti-aliasing and Shadows

Studying the CCanvas Class. Anti-aliasing and Shadows

An anti-aliasing algorithm of the CCanvas class is the base for all constructions where anti-aliasing is being used. The article contains information about how this algorithm operates, and provides relevant examples of visualization. It also covers drawing shades of graphic objects and has a detailed algorithm developed for drawing shades on canvas. The numerical analysis library ALGLIB is used for calculations.
Indicator for Spindles Charting
Indicator for Spindles Charting

Indicator for Spindles Charting

The article regards spindle chart plotting and its usage in trading strategies and experts. First let's discuss the chart's appearance, plotting and connection with japanese candlestick chart. Next we analyze the indicator's implementation in the source code in the MQL5 language. Let's test the expert based on indicator and formulate the trading strategy.
Building a Spectrum Analyzer
Building a Spectrum Analyzer

Building a Spectrum Analyzer

This article is intended to get its readers acquainted with a possible variant of using graphical objects of the MQL5 language. It analyses an indicator, which implements a panel of managing a simple spectrum analyzer using the graphical objects. The article is meant for readers acquianted with basics of MQL5.
Graphics in DoEasy library (Part 81): Integrating graphics into library objects
Graphics in DoEasy library (Part 81): Integrating graphics into library objects

Graphics in DoEasy library (Part 81): Integrating graphics into library objects

It is time to start the integration of the already created objects into the previously created library objects. This will ultimately endow each library object with its own graphical object allowing users to interact with the program.
Graphical Interfaces VIII: the File Navigator Control (Chapter 3)
Graphical Interfaces VIII: the File Navigator Control (Chapter 3)

Graphical Interfaces VIII: the File Navigator Control (Chapter 3)

In the previous chapters of the eighth part of the series, our library has been reinforced by several classes for developing mouse pointers, calendars and tree views. The current article deals with the file navigator control that can also be used as part of an MQL application graphical interface.
Handling ZIP Archives in Pure MQL5
Handling ZIP Archives in Pure MQL5

Handling ZIP Archives in Pure MQL5

The MQL5 language keeps evolving, and its new features for working with data are constantly being added. Due to innovation it has recently become possible to operate with ZIP archives using regular MQL5 tools without getting third party DLL libraries involved. This article focuses on how this is done and provides the CZip class, which is a universal tool for reading, creating and modifying ZIP archives, as an example.
Growing Neural Gas: Implementation in MQL5
Growing Neural Gas: Implementation in MQL5

Growing Neural Gas: Implementation in MQL5

The article shows an example of how to develop an MQL5-program implementing the adaptive algorithm of clustering called Growing neural gas (GNG). The article is intended for the users who have studied the language documentation and have certain programming skills and basic knowledge in the area of neuroinformatics.
Graphical Interfaces XI: Refactoring the Library code (build 14.1)
Graphical Interfaces XI: Refactoring the Library code (build 14.1)

Graphical Interfaces XI: Refactoring the Library code (build 14.1)

As the library grows, its code must be optimized again in order to reduce its size. The version of the library described in this article has become even more object-oriented. This made the code easier to learn. A detailed description of the latest changes will allow the readers to develop the library independently based on their own needs.
Statistical Estimations
Statistical Estimations

Statistical Estimations

Estimation of statistical parameters of a sequence is very important, since most of mathematical models and methods are based on different assumptions. For example, normality of distribution law or dispersion value, or other parameters. Thus, when analyzing and forecasting of time series we need a simple and convenient tool that allows quickly and clearly estimating the main statistical parameters. The article shortly describes the simplest statistical parameters of a random sequence and several methods of its visual analysis. It offers the implementation of these methods in MQL5 and the methods of visualization of the result of calculations using the Gnuplot application.
preview
DoEasy. Controls (Part 1): First steps

DoEasy. Controls (Part 1): First steps

This article starts an extensive topic of creating controls in Windows Forms style using MQL5. My first object of interest is creating the panel class. It is already becoming difficult to manage things without controls. Therefore, I will create all possible controls in Windows Forms style.