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
Drawing Resistance and Support Levels Using MQL5
Drawing Resistance and Support Levels Using MQL5

Drawing Resistance and Support Levels Using MQL5

This article describes a method of finding four extremum points for drawing support and resistance levels based on them. In order to find extremums on a chart of a currency pair, RSI indicator is used. To give an example, we have provided an indicator code that displays support and resistance levels.
Native Twitter Client for MT4 and MT5 without DLL
Native Twitter Client for MT4 and MT5 without DLL

Native Twitter Client for MT4 and MT5 without DLL

Ever wanted to access tweets and/or post your trade signals on Twitter ? Search no more, these on-going article series will show you how to do it without using any DLL. Enjoy the journey of implementing Twitter API using MQL. In this first part, we will follow the glory path of authentication and authorization in accessing Twitter API.
Integrating MQL-based Expert Advisors and databases (SQL Server, .NET and C#)
Integrating MQL-based Expert Advisors and databases (SQL Server, .NET and C#)

Integrating MQL-based Expert Advisors and databases (SQL Server, .NET and C#)

The article describes how to add the ability to work with Microsoft SQL Server database server to MQL5-based Expert Advisors. Import of functions from a DLL is used. The DLL is created using the Microsoft .NET platform and the C# language. The methods used in the article are also suitable for experts written in MQL4, with minor adjustments.
MQL5 Programming Basics: Global Variables of the  MetaTrader 5 Terminal
MQL5 Programming Basics: Global Variables of the  MetaTrader 5 Terminal

MQL5 Programming Basics: Global Variables of the MetaTrader 5 Terminal

Global variables of the terminal provide an indispensable tool for developing sophisticated and reliable Expert Advisors. If you master the global variables, you will no more be able to imagine developing EAs on MQL5 without them.
The Flag Pattern
The Flag Pattern

The Flag Pattern

The article provides the analysis of the following patterns: Flag, Pennant, Wedge, Rectangle, Contracting Triangle, Expanding Triangle. In addition to analyzing their similarities and differences, we will create indicators for detecting these patterns on the chart, as well as a tester indicator for the fast evaluation of their effectiveness.
Reversal patterns: Testing the Head and Shoulders pattern
Reversal patterns: Testing the Head and Shoulders pattern

Reversal patterns: Testing the Head and Shoulders pattern

This article is a follow-up to the previous one called "Reversal patterns: Testing the Double top/bottom pattern". Now we will have a look at another well-known reversal pattern called Head and Shoulders, compare the trading efficiency of the two patterns and make an attempt to combine them into a single trading system.
Visualize a Strategy in the MetaTrader 5 Tester
Visualize a Strategy in the MetaTrader 5 Tester

Visualize a Strategy in the MetaTrader 5 Tester

We all know the saying "Better to see once than hear a hundred times". You can read various books about Paris or Venice, but based on the mental images you wouldn't have the same feelings as on the evening walk in these fabulous cities. The advantage of visualization can easily be projected on any aspect of our lives, including work in the market, for example, the analysis of price on charts using indicators, and of course, the visualization of strategy testing. This article contains descriptions of all the visualization features of the MetaTrader 5 Strategy Tester.
Expert Advisor featuring GUI: Creating the panel (part I)
Expert Advisor featuring GUI: Creating the panel (part I)

Expert Advisor featuring GUI: Creating the panel (part I)

Despite the fact that many traders still prefer manual trading, it is hardly possible to completely avoid the automation of routine operations. The article shows an example of developing a multi-symbol signal Expert Advisor for manual trading.
Library for easy and quick development of MetaTrader programs (part XXVIII): Closure, removal and modification of pending trading requests
Library for easy and quick development of MetaTrader programs (part XXVIII): Closure, removal and modification of pending trading requests

Library for easy and quick development of MetaTrader programs (part XXVIII): Closure, removal and modification of pending trading requests

This is the third article about the concept of pending requests. We are going to complete the tests of pending trading requests by creating the methods for closing positions, removing pending orders and modifying position and pending order parameters.
Creating a custom news feed for MetaTrader 5
Creating a custom news feed for MetaTrader 5

Creating a custom news feed for MetaTrader 5

In this article we look at the possibility of creating a flexible news feed that offers more options in terms of the type of news and also its source. The article will show how a web API can be integrated with the MetaTrader 5 terminal.
Graphical Interfaces X: Updates for Easy And Fast Library (Build 3)
Graphical Interfaces X: Updates for Easy And Fast Library (Build 3)

Graphical Interfaces X: Updates for Easy And Fast Library (Build 3)

The next version of the Easy And Fast library (version 3) is presented in this article. Fixed certain flaws and added new features. More details further in the article.
MQL5 Wizard for Dummies
MQL5 Wizard for Dummies

MQL5 Wizard for Dummies

In early 2011 we released the first version of the MQL5 Wizard. This new application provides a simple and convenient tool to automatically generate trading robots. Any MetaTrader 5 user can create a custom Expert Advisor without even knowing how to program in MQL5.
Graphical Interfaces X: The Standard Chart Control (build 4)
Graphical Interfaces X: The Standard Chart Control (build 4)

Graphical Interfaces X: The Standard Chart Control (build 4)

This time we will consider the Standard chart control. It will allow to create arrays of subcharts with the ability to synchronize horizontal scrolling. In addition, we will continue to optimize the library code to reduce the CPU load.
MQL5 Programming Basics: Strings
MQL5 Programming Basics: Strings

MQL5 Programming Basics: Strings

The article covers everything you can do with strings in MQL5. It should be of interest primarily to novice MQL5 programmers, while experienced developers will have a good opportunity to summarize and systematize their knowledge.
Library for easy and quick development of MetaTrader programs (part XXXIV): Pending trading requests - removing and modifying orders and positions under certain conditions
Library for easy and quick development of MetaTrader programs (part XXXIV): Pending trading requests - removing and modifying orders and positions under certain conditions

Library for easy and quick development of MetaTrader programs (part XXXIV): Pending trading requests - removing and modifying orders and positions under certain conditions

In this article, we will complete the description of the pending request trading concept and create the functionality for removing pending orders, as well as modifying orders and positions under certain conditions. Thus, we are going to have the entire functionality enabling us to develop simple custom strategies, or rather EA behavior logic activated upon user-defined conditions.
Synchronizing several same-symbol charts on different timeframes
Synchronizing several same-symbol charts on different timeframes

Synchronizing several same-symbol charts on different timeframes

When making trading decisions, we often have to analyze charts on several timeframes. At the same time, these charts often contain graphical objects. Applying the same objects to all charts is inconvenient. In this article, I propose to automate cloning of objects to be displayed on charts.
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.
preview
Programming a Deep Neural Network from Scratch using MQL Language

Programming a Deep Neural Network from Scratch using MQL Language

This article aims to teach the reader how to make a Deep Neural Network from scratch using the MQL4/5 language.
Custom Graphical Controls. Part 1: Creating a Simple Control
Custom Graphical Controls. Part 1: Creating a Simple Control

Custom Graphical Controls. Part 1: Creating a Simple Control

This article covers general principles of development of graphical controls. We are going to prepare tools for a quick and convenient work with graphical objects, analyze an example of creation of a simple control for entering text or numeric data as well as the ways of using it.
Creating an Indicator with Multiple Indicator Buffers for Newbies
Creating an Indicator with Multiple Indicator Buffers for Newbies

Creating an Indicator with Multiple Indicator Buffers for Newbies

The complex codes consist of a set of simple codes. If you are familiar with them, it doesn't look so complicated. In this article, we will consider how to create an indicator with multiple indicator buffers. As an example, the Aroon indicator is analyzed in details, and two different versions of the code are presented.
preview
OpenCL: From Naive Towards More Insightful Programming

OpenCL: From Naive Towards More Insightful Programming

This article focuses on some optimization capabilities that open up when at least some consideration is given to the underlying hardware on which the OpenCL kernel is executed. The figures obtained are far from being ceiling values but even they suggest that having the existing resources available here and now (OpenCL API as implemented by the developers of the terminal does not allow to control some parameters important for optimization - particularly, the work group size), the performance gain over the host program execution is very substantial.
MQL5 Cookbook: Monitoring Multiple Time Frames in a Single Window
MQL5 Cookbook: Monitoring Multiple Time Frames in a Single Window

MQL5 Cookbook: Monitoring Multiple Time Frames in a Single Window

There are 21 time frames available in MetaTrader 5 for analysis. You can take advantage of special chart objects that you can place on the existing chart and set the symbol, time frame and some other properties right there. This article will provide detailed information on such chart graphical objects: we will create an indicator with controls (buttons) that will allow us to set multiple chart objects in a subwindow at the same time. Furthermore, chart objects will accurately fit in the subwindow and will be automatically adjusted when the main chart or terminal window is resized.
Indicator for Constructing a Three Line Break Chart
Indicator for Constructing a Three Line Break Chart

Indicator for Constructing a Three Line Break Chart

This article is dedicated to the Three Line Break chart, suggested by Steve Nison in his book "Beyond Candlesticks". The greatest advantage of this chart is that it allows filtering minor fluctuations of a price in relation to the previous movement. We are going to discuss the principle of the chart construction, the code of the indicator and some examples of trading strategies based on it.
Genetic Algorithms - It's Easy!
Genetic Algorithms - It's Easy!

Genetic Algorithms - It's Easy!

In this article the author talks about evolutionary calculations with the use of a personally developed genetic algorithm. He demonstrates the functioning of the algorithm, using examples, and provides practical recommendations for its usage.
Advanced Adaptive Indicators Theory and Implementation in MQL5
Advanced Adaptive Indicators Theory and Implementation in MQL5

Advanced Adaptive Indicators Theory and Implementation in MQL5

This article will describe advanced adaptive indicators and their implementation in MQL5: Adaptive Cyber Cycle, Adaptive Center of Gravity and Adaptive RVI. All indicators were originally presented in "Cybernetic Analysis for Stocks and Futures" by John F. Ehlers.
Tips from a professional programmer (Part II): Storing and exchanging parameters between an Expert Advisor, scripts and external programs
Tips from a professional programmer (Part II): Storing and exchanging parameters between an Expert Advisor, scripts and external programs

Tips from a professional programmer (Part II): Storing and exchanging parameters between an Expert Advisor, scripts and external programs

These are some tips from a professional programmer about methods, techniques and auxiliary tools which can make programming easier. We will discuss parameters which can be restored after terminal restart (shutdown). All examples are real working code segments from my Cayman project.
The Basics of Object-Oriented Programming
The Basics of Object-Oriented Programming

The Basics of Object-Oriented Programming

You don't need to know what are polymorphism, encapsulation, etc. all about in to use object-oriented programming (OOP)... you may simply use these features. This article covers the basics of OOP with hands-on examples.
Debugging MQL5 Programs
Debugging MQL5 Programs

Debugging MQL5 Programs

This article is intended primarily for the programmers who have already learned the language but have not fully mastered the program development yet. It reveals some debugging techniques and presents a combined experience of the author and many other programmers.
LifeHack for traders: Blending ForEach with defines (#define)
LifeHack for traders: Blending ForEach with defines (#define)

LifeHack for traders: Blending ForEach with defines (#define)

The article is an intermediate step for those who still writes in MQL4 and has no desire to switch to MQL5. We continue to search for opportunities to write code in MQL4 style. This time, we will look into the macro substitution of the #define preprocessor.
Trading Signal Generator Based on a Custom Indicator
Trading Signal Generator Based on a Custom Indicator

Trading Signal Generator Based on a Custom Indicator

How to create a trading signal generator based on a custom indicator? How to create a custom indicator? How to get access to custom indicator data? Why do we need the IS_PATTERN_USAGE(0) structure and model 0?
Universal Trend with the Graphical Interface
Universal Trend with the Graphical Interface

Universal Trend with the Graphical Interface

In this article a universal trend indicator is created based on a number of standard indicators. An additionally created graphical interface allows selecting the type of indicator and adjusting its parameter. The indicator is displayed in a separate window with rows of colored icons.
3D Modeling in MQL5
3D Modeling in MQL5

3D Modeling in MQL5

A time series is a dynamic system, in which values of a random variable are received continuously or at successive equally spaced points in time. Transition from 2D to 3D market analysis provides a new look at complex processes and research objects. The article describes visualization methods providing 3D representation of two-dimensional data.
Developing stock indicators featuring volume control through the example of the delta indicator
Developing stock indicators featuring volume control through the example of the delta indicator

Developing stock indicators featuring volume control through the example of the delta indicator

The article deals with the algorithm of developing stock indicators based on real volumes using the CopyTicks() and CopyTicksRange() functions. Some subtle aspects of developing such indicators, as well as their operation in real time and in the strategy tester are also described.
Expert Advisor featuring GUI: Adding functionality (part II)
Expert Advisor featuring GUI: Adding functionality (part II)

Expert Advisor featuring GUI: Adding functionality (part II)

This is the second part of the article showing the development of a multi-symbol signal Expert Advisor for manual trading. We have already created the graphical interface. It is now time to connect it with the program's functionality.
Graphics in DoEasy library (Part 88): Graphical object collection — two-dimensional dynamic array for storing dynamically changing object properties
Graphics in DoEasy library (Part 88): Graphical object collection — two-dimensional dynamic array for storing dynamically changing object properties

Graphics in DoEasy library (Part 88): Graphical object collection — two-dimensional dynamic array for storing dynamically changing object properties

In this article, I will create a dynamic multidimensional array class with the ability to change the amount of data in any dimension. Based on the created class, I will create a two-dimensional dynamic array to store some dynamically changed properties of graphical objects.
Library for easy and quick development of MetaTrader programs (part XV): Collection of symbol objects
Library for easy and quick development of MetaTrader programs (part XV): Collection of symbol objects

Library for easy and quick development of MetaTrader programs (part XV): Collection of symbol objects

In this article, we will consider creation of a symbol collection based on the abstract symbol object developed in the previous article. The abstract symbol descendants are to clarify a symbol data and define the availability of the basic symbol object properties in a program. Such symbol objects are to be distinguished by their affiliation with groups.
Library for easy and quick development of MetaTrader programs (part XX): Creating and storing program resources
Library for easy and quick development of MetaTrader programs (part XX): Creating and storing program resources

Library for easy and quick development of MetaTrader programs (part XX): Creating and storing program resources

The article deals with storing data in the program's source code and creating audio and graphical files out of them. When developing an application, we often need audio and images. The MQL language features several methods of using such data.
Developing graphical interfaces for Expert Advisors and indicators based on .Net Framework and C#
Developing graphical interfaces for Expert Advisors and indicators based on .Net Framework and C#

Developing graphical interfaces for Expert Advisors and indicators based on .Net Framework and C#

The article presents a simple and fast method of creating graphical windows using Visual Studio with subsequent integration into the Expert Advisor's MQL code. The article is meant for non-specialist audiences and does not require any knowledge of C# and .Net technology.
Library for easy and quick development of MetaTrader programs (part I). Concept, data management and first results
Library for easy and quick development of MetaTrader programs (part I). Concept, data management and first results

Library for easy and quick development of MetaTrader programs (part I). Concept, data management and first results

While analyzing a huge number of trading strategies, orders for development of applications for MetaTrader 5 and MetaTrader 4 terminals and various MetaTrader websites, I came to the conclusion that all this diversity is based mostly on the same elementary functions, actions and values appearing regularly in different programs. This resulted in DoEasy cross-platform library for easy and quick development of МetaТrader 5 and МetaТrader 4 applications.
MQL5 Cookbook: Trading strategy stress testing using custom symbols
MQL5 Cookbook: Trading strategy stress testing using custom symbols

MQL5 Cookbook: Trading strategy stress testing using custom symbols

The article considers an approach to stress testing of a trading strategy using custom symbols. A custom symbol class is created for this purpose. This class is used to receive tick data from third-party sources, as well as to change symbol properties. Based on the results of the work done, we will consider several options for changing trading conditions, under which a trading strategy is being tested.