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 Progress Bar and Line Chart Controls (Chapter 2)
Graphical Interfaces IX: The Progress Bar and Line Chart Controls (Chapter 2)

Graphical Interfaces IX: The Progress Bar and Line Chart Controls (Chapter 2)

The second chapter of the part nine is dedicated to the progress bar and line chart controls. As always, there will be detailed examples provided to reveal how these controls can be used in custom MQL applications.
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.
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.
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.
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.
Graphical Interfaces VII: The Tabs Control (Chapter 2)
Graphical Interfaces VII: The Tabs Control (Chapter 2)

Graphical Interfaces VII: The Tabs Control (Chapter 2)

The first chapter of seventh part introduced three classes of controls for creating tables: text label table (CLabelsTable), edit box table (CTable) and rendered table (CCanvasTable). In this article (chapter two) we are going to consider the Tabs control.
Testing trading strategies on real ticks
Testing trading strategies on real ticks

Testing trading strategies on real ticks

The article provides the results of testing a simple trading strategy in three modes: "1 minute OHLC", "Every tick" and "Every tick based on real ticks" using actual historical data.
Graphical Interfaces VII: the Tables Controls (Chapter 1)
Graphical Interfaces VII: the Tables Controls (Chapter 1)

Graphical Interfaces VII: the Tables Controls (Chapter 1)

The seventh part of the series on MetaTrader graphical interfaces deals with three table types: text label, edit box and rendered one. Another important and frequently used controls are tabs allowing you to show/hide groups of other controls and develop space effective interfaces in your MQL applications.
The checks a trading robot must pass before publication in the Market
The checks a trading robot must pass before publication in the Market

The checks a trading robot must pass before publication in the Market

Before any product is published in the Market, it must undergo compulsory preliminary checks in order to ensure a uniform quality standard. This article considers the most frequent errors made by developers in their technical indicators and trading robots. An also shows how to self-test a product before sending it to the Market.
LifeHack for Traders: Indicators of Balance, Drawdown, Load and Ticks during Testing
LifeHack for Traders: Indicators of Balance, Drawdown, Load and Ticks during Testing

LifeHack for Traders: Indicators of Balance, Drawdown, Load and Ticks during Testing

How to make the testing process more visual? The answer is simple: you need to use one or more indicators in the Strategy Tester, including a tick indicator, an indicator of balance and equity, an indicator of drawdown and deposit load. This solution will help you visually track the nature of ticks, balance and equity changes, as well as drawdown and deposit load.
Universal Expert Advisor: Integration with Standard MetaTrader Modules of Signals (Part 7)
Universal Expert Advisor: Integration with Standard MetaTrader Modules of Signals (Part 7)

Universal Expert Advisor: Integration with Standard MetaTrader Modules of Signals (Part 7)

This part of the article describes the possibilities of the CStrategy engine integration with the signal modules included into the standard library in MetaTrader. The article describes how to work with signals, as well as how to create custom strategies on their basis.
Working with sockets in MQL, or How to become a signal provider
Working with sockets in MQL, or How to become a signal provider

Working with sockets in MQL, or How to become a signal provider

Sockets… What in our IT world could possibly exist without them? Dating back to 1982, and hardly changed up to the present time, they smoothly work for us every second. This is the foundation of network, the nerve endings of the Matrix we all live in.
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.
Creating a trading robot for Moscow Exchange. Where to start?
Creating a trading robot for Moscow Exchange. Where to start?

Creating a trading robot for Moscow Exchange. Where to start?

Many traders on Moscow Exchange would like to automate their trading algorithms, but they do not know where to start. The MQL5 language offers a huge range of trading functions, and it additionally provides ready classes that help users to make their first steps in algo trading.
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.
Universal Expert Advisor: A Custom Trailing Stop (Part 6)
Universal Expert Advisor: A Custom Trailing Stop (Part 6)

Universal Expert Advisor: A Custom Trailing Stop (Part 6)

The sixth part of the article about the universal Expert Advisor describes the use of the trailing stop feature. The article will guide you through how to create a custom trailing stop module using unified rules, as well as how to add it to the trading engine so that it would automatically manage positions.
Graphical Interfaces VI: the Slider and the Dual Slider Controls (Chapter 2)
Graphical Interfaces VI: the Slider and the Dual Slider Controls (Chapter 2)

Graphical Interfaces VI: the Slider and the Dual Slider Controls (Chapter 2)

In the previous article, we have enriched our library with four controls frequently used in graphical interfaces: checkbox, edit, edit with checkbox and check combobox. The second chapter of the sixth part will be dedicated to the slider and the dual slider controls.
Graphical Interfaces VI: the Checkbox Control, the Edit Control and their Mixed Types (Chapter 1)
Graphical Interfaces VI: the Checkbox Control, the Edit Control and their Mixed Types (Chapter 1)

Graphical Interfaces VI: the Checkbox Control, the Edit Control and their Mixed Types (Chapter 1)

This article is the beginning of the sixth part of the series dedicated to the development of the library for creating graphical interfaces in the MetaTrader terminals. In the first chapter, we are going to discuss the checkbox control, the edit control and their mixed types.
Universal Expert Advisor: Pending Orders and Hedging Support (Part 5)
Universal Expert Advisor: Pending Orders and Hedging Support (Part 5)

Universal Expert Advisor: Pending Orders and Hedging Support (Part 5)

This article provides further description of the CStrategy trading engine. By popular demand of users, we have added pending order support functions to the trading engine. Also, the latest version of the MetaTrader 5 now supports accounts with the hedging option. The same support has been added to CStrategy. The article provides a detailed description of algorithms for the use of pending orders, as well as of CStrategy operation principles on accounts with the hedging option enabled.
Graphical Interfaces V: The Combobox Control (Chapter 3)
Graphical Interfaces V: The Combobox Control (Chapter 3)

Graphical Interfaces V: The Combobox Control (Chapter 3)

In the first two chapters of the fifth part of the series, we developed classes for creating a scrollbar and a view list. In this chapter, we will speak about creating a class for the combobox control. This is also a compound control containing, among others, elements considered in the previous chapters of the fifth part.
Self-organizing feature maps (Kohonen maps) - revisiting the subject
Self-organizing feature maps (Kohonen maps) - revisiting the subject

Self-organizing feature maps (Kohonen maps) - revisiting the subject

This article describes techniques of operating with Kohonen maps. The subject will be of interest to both market researchers with basic level of programing in MQL4 and MQL5 and experienced programmers that face difficulties with connecting Kohonen maps to their projects.
Universal Expert Advisor: Trading in a Group and Managing a Portfolio of Strategies (Part 4)
Universal Expert Advisor: Trading in a Group and Managing a Portfolio of Strategies (Part 4)

Universal Expert Advisor: Trading in a Group and Managing a Portfolio of Strategies (Part 4)

In the last part of the series of articles about the CStrategy trading engine, we will consider simultaneous operation of multiple trading algorithms, will learn to load strategies from XML files, and will present a simple panel for selecting Expert Advisors from a single executable module, and managing their trading modes.
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.
Graphical Interfaces V: The Vertical and Horizontal Scrollbar (Chapter 1)
Graphical Interfaces V: The Vertical and Horizontal Scrollbar (Chapter 1)

Graphical Interfaces V: The Vertical and Horizontal Scrollbar (Chapter 1)

We are still discussing the development of the library for creating graphical interfaces in the MetaTrader environment. In the first article of the fifth part of the series, we will write classes for creating vertical and horizontal scrollbars.
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 IV: Informational Interface Elements (Chapter 1)
Graphical Interfaces IV: Informational Interface Elements (Chapter 1)

Graphical Interfaces IV: Informational Interface Elements (Chapter 1)

At the current stage of development, the library for creating graphical interfaces contains a form and several controls that can be attached to it. It was mentioned before that one of the future articles would be dedicated to the multi-window mode. Now, we have everything ready for that and we will deal with it in the following chapter. In this chapter, we will write classes for creating the status bar and tooltip informational interface elements.
MQL5 Cookbook - Programming moving channels
MQL5 Cookbook - Programming moving channels

MQL5 Cookbook - Programming moving channels

This article presents a method of programming the equidistant channel system. Certain details of building such channels are being considered here. Channel typification is provided, and a universal type of moving channels' method is suggested. Object-oriented programming (OOP) is used for code implementation.
Graphical Interfaces III: Groups of Simple and Multi-Functional Buttons (Chapter 2)
Graphical Interfaces III: Groups of Simple and Multi-Functional Buttons (Chapter 2)

Graphical Interfaces III: Groups of Simple and Multi-Functional Buttons (Chapter 2)

The first chapter of the series was about simple and multi-functional buttons. The second article will be dedicated to groups of interconnected buttons that will allow the creation of elements in an application when a user can select one of the option out of a set (group).
Graphical Interfaces III: Simple and Multi-Functional Buttons (Chapter 1)
Graphical Interfaces III: Simple and Multi-Functional Buttons (Chapter 1)

Graphical Interfaces III: Simple and Multi-Functional Buttons (Chapter 1)

Let us consider the button control. We will discuss examples of several classes for creating a simple button, buttons with extended functionality (icon button and split button) and interconnected buttons (button groups and radio button). Added to that, we will introduce some additions to existing classes for controls to broaden their capability.
Graphical Interfaces II: The Main Menu Element (Chapter 4)
Graphical Interfaces II: The Main Menu Element (Chapter 4)

Graphical Interfaces II: The Main Menu Element (Chapter 4)

This is the final chapter of the second part of the series about graphical interfaces. Here, we are going to consider the creation of the main menu. The development of this control and setting up handlers of the library classes for correct reaction to the user's actions will be demonstrated here. We will also discuss how to attach context menus to the items of the main menu. Adding to that, we will mention blocking currently inactive elements.
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.)
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.
Universal Expert Advisor: the Event Model and Trading Strategy Prototype (Part 2)
Universal Expert Advisor: the Event Model and Trading Strategy Prototype (Part 2)

Universal Expert Advisor: the Event Model and Trading Strategy Prototype (Part 2)

This article continues the series of publications on a universal Expert Advisor model. This part describes in detail the original event model based on centralized data processing, and considers the structure of the CStrategy base class of the engine.
Universal Expert Advisor: Trading Modes of Strategies (Part 1)
Universal Expert Advisor: Trading Modes of Strategies (Part 1)

Universal Expert Advisor: Trading Modes of Strategies (Part 1)

Any Expert Advisor developer, regardless of programming skills, is daily confronted with the same trading tasks and algorithmic problems, which should be solved to organize a reliable trading process. The article describes the possibilities of the CStrategy trading engine that can undertake the solution of these tasks and provide a user with convenient mechanism for describing a custom trading idea.
Graphical Interfaces II: the Separation Line and Context Menu Elements (Chapter 2)
Graphical Interfaces II: the Separation Line and Context Menu Elements (Chapter 2)

Graphical Interfaces II: the Separation Line and Context Menu Elements (Chapter 2)

In this article we will create the separation line element. It will be possible to use it not only as an independent interface element but also as a part of many other elements. After that, we will have everything required for the development of the context menu class, which will be also considered in this article in detail. Added to that, we will introduce all necessary additions to the class, which is the base for storing pointers to all the elements of the graphical interface of the application.
Graphical Interfaces II: the Menu Item Element (Chapter 1)
Graphical Interfaces II: the Menu Item Element (Chapter 1)

Graphical Interfaces II: the Menu Item Element (Chapter 1)

In the second part of the series, we will show in detail the development of such interface elements as main menu and context menu. We will also mention drawing elements and create a special class for it. We will discuss in depth such question as managing program events including custom ones.
Adding a control panel to an indicator or an Expert Advisor in no time
Adding a control panel to an indicator or an Expert Advisor in no time

Adding a control panel to an indicator or an Expert Advisor in no time

Have you ever felt the need to add a graphical panel to your indicator or Expert Advisor for greater speed and convenience? In this article, you will find out how to implement the dialog panel with the input parameters into your MQL4/MQL5 program step by step.
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.
Graphical Interfaces I: Functions for the Form Buttons and Deleting Interface Elements (Chapter 4)
Graphical Interfaces I: Functions for the Form Buttons and Deleting Interface Elements (Chapter 4)

Graphical Interfaces I: Functions for the Form Buttons and Deleting Interface Elements (Chapter 4)

In this article, we are going to continue developing the CWindow class by adding methods, which will allow managing the form by clicking on its controls. We will enable the program to be closed by a form button as well as implement a minimizing and maximizing feature for the form.
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.