Articles with examples of trading robots developed in MQL5

icon

An Expert Advisor is the 'pinnacle' of programming and the desired goal of every automated trading developer. Read the articles in this section to create your own trading robot. By following the described steps you will learn how to create, debug and test automated trading systems.

The articles not only teach MQL5 programming, but also show how to implement trading ideas and techniques. You will learn how to program a trailing stop, how to apply money management, how to get the indicator values, and much more.

Add a new article
latest | best
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.
Guide to Testing and Optimizing of Expert Advisors in MQL5
Guide to Testing and Optimizing of Expert Advisors in MQL5

Guide to Testing and Optimizing of Expert Advisors in MQL5

This article explains the step by step process of identifying and resolving code errors as well as the steps in testing and optimizing of the Expert Advisor input parameters. You will learn how to use Strategy Tester of MetaTrader 5 client terminal to find the best symbol and set of input parameters for your Expert Advisor.
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.
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.
Functions for Money Management in an Expert Advisor
Functions for Money Management in an Expert Advisor

Functions for Money Management in an Expert Advisor

The development of trading strategies primarily focuses on searching for patterns for entering and exiting the market, as well as maintaining positions. If we are able to formalize some patterns into rules for automated trading, then the trader faces the question of calculating the volume of positions, the size of the margins, as well as maintaining a safe level of mortgage funds for assuring open positions in an automated mode. In this article we will use the MQL5 language to construct simple examples of conducting these calculations.
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.
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.
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.
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: 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.
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.
Plotting trend lines based on fractals using MQL4 and MQL5
Plotting trend lines based on fractals using MQL4 and MQL5

Plotting trend lines based on fractals using MQL4 and MQL5

The article describes the automation of trend lines plotting based on the Fractals indicator using MQL4 and MQL5. The article structure provides a comparative view of the solution for two languages. Trend lines are plotted using two last known fractals.
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.
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.
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?
Creating Active Control Panels in MQL5 for Trading
Creating Active Control Panels in MQL5 for Trading

Creating Active Control Panels in MQL5 for Trading

The article covers the problem of development of active control panels in MQL5. Interface elements are managed by the event handling mechanism. Besides, the option of a flexible setup of control elements properties is available. The active control panel allows working with positions, as well setting, modifying and deleting market and pending orders.
preview
Learn Why and How to Design Your Algorithmic Trading System

Learn Why and How to Design Your Algorithmic Trading System

This article shows the basics of MQL for beginners to design their Algorithmic trading system (Expert Advisor) through designing a simple algorithmic trading system after mentioning some basics of MQL5
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.
Developing a cross-platform grid EA: testing a multi-currency EA
Developing a cross-platform grid EA: testing a multi-currency EA

Developing a cross-platform grid EA: testing a multi-currency EA

Markets dropped down by more that 30% within one month. It seems to be the best time for testing grid- and martingale-based Expert Advisors. This article is an unplanned continuation of the series "Creating a Cross-Platform Grid EA". The current market provides an opportunity to arrange a stress rest for the grid EA. So, let's use this opportunity and test our Expert Advisor.
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.
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.
Using limit orders instead of Take Profit without changing the EA's original code
Using limit orders instead of Take Profit without changing the EA's original code

Using limit orders instead of Take Profit without changing the EA's original code

Using limit orders instead of conventional take profits has long been a topic of discussions on the forum. What is the advantage of this approach and how can it be implemented in your trading? In this article, I want to offer you my vision of this topic.
MQL for "Dummies": How to Design and Construct Object Classes
MQL for "Dummies": How to Design and Construct Object Classes

MQL for "Dummies": How to Design and Construct Object Classes

By creating a sample program of visual design, we demonstrate how to design and construct classes in MQL5. The article is written for beginner programmers, who are working on MT5 applications. We propose a simple and easy grasping technology for creating classes, without the need to deeply immerse into the theory of object-oriented programming.
Application of the Eigen-Coordinates Method to Structural Analysis of Nonextensive Statistical Distributions
Application of the Eigen-Coordinates Method to Structural Analysis of Nonextensive Statistical Distributions

Application of the Eigen-Coordinates Method to Structural Analysis of Nonextensive Statistical Distributions

The major problem of applied statistics is the problem of accepting statistical hypotheses. It was long considered impossible to be solved. The situation has changed with the emergence of the eigen-coordinates method. It is a fine and powerful tool for a structural study of a signal allowing to see more than what is possible using methods of modern applied statistics. The article focuses on practical use of this method and sets forth programs in MQL5. It also deals with the problem of function identification using as an example the distribution introduced by Hilhorst and Schehr.
Simple Trading Systems Using Semaphore Indicators
Simple Trading Systems Using Semaphore Indicators

Simple Trading Systems Using Semaphore Indicators

If we thoroughly examine any complex trading system, we will see that it is based on a set of simple trading signals. Therefore, there is no need for novice developers to start writing complex algorithms immediately. This article provides an example of a trading system that uses semaphore indicators to perform deals.
Creating Multi-Expert Advisors on the basis of Trading Models
Creating Multi-Expert Advisors on the basis of Trading Models

Creating Multi-Expert Advisors on the basis of Trading Models

Using the object-oriented approach in MQL5 greatly simplifies the creation of multi-currency/multi-system /multi-time-frame Expert Advisors. Just imagine, your single EA trades on several dozens of trading strategies, on all of the available instruments, and on all of the possible time frames! In addition, the EA is easily tested in the tester, and for all of the strategies, included in its composition, it has one or several working systems of money management.
The Indicators of the Micro, Middle and Main Trends
The Indicators of the Micro, Middle and Main Trends

The Indicators of the Micro, Middle and Main Trends

The aim of this article is to investigate the possibilities of trade automation and the analysis, on the basis of some ideas from a book by James Hyerczyk "Pattern, Price & Time: Using Gann Theory in Trading Systems" in the form of indicators and Expert Advisor. Without claiming to be exhaustive, here we investigate only the Model - the first part of the Gann theory.
Price velocity measurement methods
Price velocity measurement methods

Price velocity measurement methods

There are multiple different approaches to market research and analysis. The main ones are technical and fundamental. In technical analysis, traders collect, process and analyze numerical data and parameters related to the market, including prices, volumes, etc. In fundamental analysis, traders analyze events and news affecting the markets directly or indirectly. The article deals with price velocity measurement methods and studies trading strategies based on that methods.
Creating MQL5 Expert Advisors in minutes using EA Tree: Part One
Creating MQL5 Expert Advisors in minutes using EA Tree: Part One

Creating MQL5 Expert Advisors in minutes using EA Tree: Part One

EA Tree is the first drag and drop MetaTrader MQL5 Expert Advisor builder. You can create complex MQL5 using a very easy to use graphical user interface. In EA Tree, Expert Advisors are created by connecting boxes together. Boxes may contain MQL5 functions, technical indicators, custom indicators, or values. Using the "tree of boxes", EA Tree generates the MQL5 code of the Expert Advisor.
Change Expert Advisor Parameters From the User Panel "On the Fly"
Change Expert Advisor Parameters From the User Panel "On the Fly"

Change Expert Advisor Parameters From the User Panel "On the Fly"

This article provides a small example demonstrating the implementation of an Expert Advisor whose parameters can be controlled from the user panel. When changing the parameters "on the fly", the Expert Advisor writes the values obtained from the info panel to a file to further read them from the file and display accordingly on the panel. This article may be relevant to those who trade manually or in semi-automatic mode.
MQL5 Cookbook - Trading signals of moving channels
MQL5 Cookbook - Trading signals of moving channels

MQL5 Cookbook - Trading signals of moving channels

The article describes the process of developing and implementing a class for sending signals based on the moving channels. Each of the signal version is followed by a trading strategy with testing results. Classes of the Standard Library are used for creating derived classes.
preview
Continuous Walk-Forward Optimization (Part 4): Optimization Manager (Auto Optimizer)

Continuous Walk-Forward Optimization (Part 4): Optimization Manager (Auto Optimizer)

The main purpose of the article is to describe the mechanism of working with our application and its capabilities. Thus the article can be treated as an instruction on how to use the application. It covers all possible pitfalls and specifics of the application usage.
MQL5 Wizard: New Version
MQL5 Wizard: New Version

MQL5 Wizard: New Version

The article contains descriptions of the new features available in the updated MQL5 Wizard. The modified architecture of signals allow creating trading robots based on the combination of various market patterns. The example contained in the article explains the procedure of interactive creation of an Expert Advisor.
Building an Automatic News Trader
Building an Automatic News Trader

Building an Automatic News Trader

This is the continuation of Another MQL5 OOP class article which showed you how to build a simple OO EA from scratch and gave you some tips on object-oriented programming. Today I am showing you the technical basics needed to develop an EA able to trade the news. My goal is to keep on giving you ideas about OOP and also cover a new topic in this series of articles, working with the file system.
Optimization management (Part II): Creating key objects and add-on logic
Optimization management (Part II): Creating key objects and add-on logic

Optimization management (Part II): Creating key objects and add-on logic

This article is a continuation of the previous publication related to the creation of a graphical interface for optimization management. The article considers the logic of the add-on. A wrapper for the MetaTrader 5 terminal will be created: it will enable the running of the add-on as a managed process via C#. In addition, operation with configuration files and setup files is considered in this article. The application logic is divided into two parts: the first one describes the methods called after pressing a particular key, while the second part covers optimization launch and management.
Cross-Platform Expert Advisor: Money Management
Cross-Platform Expert Advisor: Money Management

Cross-Platform Expert Advisor: Money Management

This article discusses the implementation of money management method for a cross-platform expert advisor. The money management classes are responsible for the calculation of the lot size to be used for the next trade to be entered by the expert advisor.
MQL5 Cookbook - Pivot trading signals
MQL5 Cookbook - Pivot trading signals

MQL5 Cookbook - Pivot trading signals

The article describes the development and implementation of a class for sending signals based on pivots — reversal levels. This class is used to form a strategy applying the Standard Library. Improving the pivot strategy by adding filters is considered.
preview
An attempt at developing an EA constructor

An attempt at developing an EA constructor

In this article, I offer my set of trading functions in the form of a ready-made EA. This method allows getting multiple trading strategies by simply adding indicators and changing inputs.