Articles on strategy testing in MQL5

icon

How to develop, write and test a trading strategy, how to find the optimal system parameters and how to analyze the results? The MetaTrader platform offers developers of trading robots rich functionality for fast and accurate testing of trading ideas. Read these articles to learn how to test multi-currency robots and how to use MQL5 Cloud Network for optimization purposes.

Developers of automated trading systems are recommended to start with the testing fundamentals and tick generation algorithms in the strategy tester.

Add a new article
latest | best
preview
Continuous Walk-Forward Optimization (Part 2): Mechanism for creating an optimization report for any robot

Continuous Walk-Forward Optimization (Part 2): Mechanism for creating an optimization report for any robot

The first article within the Walk-Through Optimization series described the creation of a DLL to be used in our auto optimizer. This continuation is entirely devoted to the MQL5 language.
Color optimization of trading strategies
Color optimization of trading strategies

Color optimization of trading strategies

In this article we will perform an experiment: we will color optimization results. The color is determined by three parameters: the levels of red, green and blue (RGB). There are other color coding methods, which also use three parameters. Thus, three testing parameters can be converted to one color, which visually represents the values. Read this article to find out if such a representation can be useful.
Mini Market Emulator or Manual Strategy Tester
Mini Market Emulator or Manual Strategy Tester

Mini Market Emulator or Manual Strategy Tester

Mini Market Emulator is an indicator designed for partial emulation of work in the terminal. Presumably, it can be used to test "manual" strategies of market analysis and trading.
preview
Continuous Walk-Forward Optimization (Part 7): Binding Auto Optimizer's logical part with graphics and controlling graphics from the program

Continuous Walk-Forward Optimization (Part 7): Binding Auto Optimizer's logical part with graphics and controlling graphics from the program

This article describes the connection of the graphical part of the auto optimizer program with its logical part. It considers the optimization launch process, from a button click to task redirection to the optimization manager.
preview
Combinatorics and probability theory for trading (Part I): The basics

Combinatorics and probability theory for trading (Part I): The basics

In this series of article, we will try to find a practical application of probability theory to describe trading and pricing processes. In the first article, we will look into the basics of combinatorics and probability, and will analyze the first example of how to apply fractals in the framework of the probability theory.
preview
Continuous Walk-Forward Optimization (Part 3): Adapting a Robot to Auto Optimizer

Continuous Walk-Forward Optimization (Part 3): Adapting a Robot to Auto Optimizer

The third part serves as a bridge between the previous two parts: it describes the mechanism of interaction with the DLL considered in the first article and the objects for report downloading, which were described in the second article. We will analyze the process of wrapper creation for a class which is imported from DLL and which forms an XML file with the trading history. We will also consider a method for interacting with this wrapper.
Using indicators for optimizing Expert Advisors in real time
Using indicators for optimizing Expert Advisors in real time

Using indicators for optimizing Expert Advisors in real time

Efficiency of any trading robot depends on the correct selection of its parameters (optimization). However, parameters that are considered optimal for one time interval may not retain their effectiveness in another period of trading history. Besides, EAs showing profit during tests turn out to be loss-making in real time. The issue of continuous optimization comes to the fore here. When facing plenty of routine work, humans always look for ways to automate it. In this article, I propose a non-standard approach to solving this issue.
Optimization management (Part I): Creating a GUI
Optimization management (Part I): Creating a GUI

Optimization management (Part I): Creating a GUI

This article describes the process of creating an extension for the MetaTrader terminal. The solution discussed helps to automate the optimization process by running optimizations in other terminals. A few more articles will be written concerning this topic. The extension has been developed using the C# language and design patterns, which additionally demonstrates the ability to expand the terminal capabilities by developing custom modules, as well as the ability to create custom graphical user interfaces using the functionality of a preferred programming language.
LifeHack for trader: "Quiet" optimization or Plotting trade distributions
LifeHack for trader: "Quiet" optimization or Plotting trade distributions

LifeHack for trader: "Quiet" optimization or Plotting trade distributions

Analysis of the trade history and plotting distribution charts of trading results in HTML depending on position entry time. The charts are displayed in three sections - by hours, by days of the week and by months.
preview
Dealing with Time (Part 1): The Basics

Dealing with Time (Part 1): The Basics

Functions and code snippets that simplify and clarify the handling of time, broker offset, and the changes to summer or winter time. Accurate timing may be a crucial element in trading. At the current hour, is the stock exchange in London or New York already open or not yet open, when does the trading time for Forex trading start and end? For a trader who trades manually and live, this is not a big problem.
TradeObjects: Automation of trading based on MetaTrader graphical objects
TradeObjects: Automation of trading based on MetaTrader graphical objects

TradeObjects: Automation of trading based on MetaTrader graphical objects

The article deals with a simple approach to creating an automated trading system based on the chart linear markup and offers a ready-made Expert Advisor using the standard properties of the MetaTrader 4 and 5 objects and supporting the main trading operations.
preview
Useful and exotic techniques for automated trading

Useful and exotic techniques for automated trading

In this article I will demonstrate some very interesting and useful techniques for automated trading. Some of them may be familiar to you. I will try to cover the most interesting methods and will explain why they are worth using. Furthermore, I will show what these techniques are apt to in practice. We will create Expert Advisors and test all the described techniques using historic quotes.
Finding Errors and Logging
Finding Errors and Logging

Finding Errors and Logging

MetaEditor 5 has the debugging feature. But when you write your MQL5 programs, you often want to display not the individual values, but all messages that appear during testing and online work. When the log file contents have large size, it is obvious to automate quick and easy retrieval of required message. In this article we will consider ways of finding errors in MQL5 programs and methods of logging. Also we will simplify logging into files and will get to know a simple program LogMon for comfortable viewing of logs.
preview
Practical application of neural networks in trading. It's time to practice

Practical application of neural networks in trading. It's time to practice

The article provides a description and instructions for the practical use of neural network modules on the Matlab platform. It also covers the main aspects of creation of a trading system using the neural network module. In order to be able to introduce the complex within one article, I had to modify it so as to combine several neural network module functions in one program.
MQL5 Cookbook: Using Indicators to Set Trading Conditions in Expert Advisors
MQL5 Cookbook: Using Indicators to Set Trading Conditions in Expert Advisors

MQL5 Cookbook: Using Indicators to Set Trading Conditions in Expert Advisors

In this article, we will continue to modify the Expert Advisor we have been working on throughout the preceding articles of the MQL5 Cookbook series. This time, the Expert Advisor will be enhanced with indicators whose values will be used to check position opening conditions. To spice it up, we will create a drop-down list in the external parameters to be able to select one out of three trading indicators.
Visualizing optimization results using a selected criterion
Visualizing optimization results using a selected criterion

Visualizing optimization results using a selected criterion

In the article, we continue to develop the MQL application for working with optimization results. This time, we will show how to form the table of the best results after optimizing the parameters by specifying another criterion via the graphical interface.
Processing optimization results using the graphical interface
Processing optimization results using the graphical interface

Processing optimization results using the graphical interface

This is a continuation of the idea of processing and analysis of optimization results. This time, our purpose is to select the 100 best optimization results and display them in a GUI table. The user will be able to select a row in the optimization results table and receive a multi-symbol balance and drawdown graph on separate charts.
Resolving entries into indicators
Resolving entries into indicators

Resolving entries into indicators

Different situations happen in trader’s life. Often, the history of successful trades allows us to restore a strategy, while looking at a loss history we try to develop and improve it. In both cases, we compare trades with known indicators. This article suggests methods of batch comparison of trades with a number of indicators.
Custom Walk Forward optimization in MetaTrader 5
Custom Walk Forward optimization in MetaTrader 5

Custom Walk Forward optimization in MetaTrader 5

The article deals with the approaches enabling accurate simulation of walk forward optimization using the built-in tester and auxiliary libraries implemented in MQL.
preview
Custom symbols: Practical basics

Custom symbols: Practical basics

The article is devoted to the programmatic generation of custom symbols which are used to demonstrate some popular methods for displaying quotes. It describes a suggested variant of minimally invasive adaptation of Expert Advisors for trading a real symbol from a derived custom symbol chart. MQL source codes are attached to this article.
Studying candlestick analysis techniques (Part II): Auto search for new patterns
Studying candlestick analysis techniques (Part II): Auto search for new patterns

Studying candlestick analysis techniques (Part II): Auto search for new patterns

In the previous article, we analyzed 14 patterns selected from a large variety of existing candlestick formations. It is impossible to analyze all the patterns one by one, therefore another solution was found. The new system searches and tests new candlestick patterns based on known candlestick types.
Modeling time series using custom symbols according to specified distribution laws
Modeling time series using custom symbols according to specified distribution laws

Modeling time series using custom symbols according to specified distribution laws

The article provides an overview of the terminal's capabilities for creating and working with custom symbols, offers options for simulating a trading history using custom symbols, trend and various chart patterns.
MQL5 Cookbook: How to Avoid Errors When Setting/Modifying Trade Levels
MQL5 Cookbook: How to Avoid Errors When Setting/Modifying Trade Levels

MQL5 Cookbook: How to Avoid Errors When Setting/Modifying Trade Levels

In continuation of our work on the Expert Advisor from the previous article of the series called "MQL5 Cookbook: Analyzing Position Properties in the MetaTrader 5 Strategy Tester", we will enhance it with a whole lot of useful functions, as well as improve and optimize the existing ones. The Expert Advisor will this time have external parameters that can be optimized in the MetaTrader 5 Strategy Tester and will in some ways resemble a simple trading system.
MQL5 Cookbook: Saving Optimization Results of an Expert Advisor Based on Specified Criteria
MQL5 Cookbook: Saving Optimization Results of an Expert Advisor Based on Specified Criteria

MQL5 Cookbook: Saving Optimization Results of an Expert Advisor Based on Specified Criteria

We continue the series of articles on MQL5 programming. This time we will see how to get results of each optimization pass right during the Expert Advisor parameter optimization. The implementation will be done so as to ensure that if the conditions specified in the external parameters are met, the corresponding pass values will be written to a file. In addition to test values, we will also save the parameters that brought about such results.
preview
Multibot in MetaTrader: Launching multiple robots from a single chart

Multibot in MetaTrader: Launching multiple robots from a single chart

In this article, I will consider a simple template for creating a universal MetaTrader robot that can be used on multiple charts while being attached to only one chart, without the need to configure each instance of the robot on each individual chart.
MQL5 Cookbook: Developing a Framework for a Trading System Based on the Triple Screen Strategy
MQL5 Cookbook: Developing a Framework for a Trading System Based on the Triple Screen Strategy

MQL5 Cookbook: Developing a Framework for a Trading System Based on the Triple Screen Strategy

In this article, we will develop a framework for a trading system based on the Triple Screen strategy in MQL5. The Expert Advisor will not be developed from scratch. Instead, we will simply modify the program from the previous article "MQL5 Cookbook: Using Indicators to Set Trading Conditions in Expert Advisors" which already substantially serves our purpose. So the article will also demonstrate how you can easily modify patterns of ready-made programs.
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.
preview
Dealing with Time (Part 2): The Functions

Dealing with Time (Part 2): The Functions

Determing the broker offset and GMT automatically. Instead of asking the support of your broker, from whom you will probably receive an insufficient answer (who would be willing to explain a missing hour), we simply look ourselves how they time their prices in the weeks of the time changes — but not cumbersome by hand, we let a program do it — why do we have a PC after all.
MQL5 Cookbook: The History of Deals And Function Library for Getting Position Properties
MQL5 Cookbook: The History of Deals And Function Library for Getting Position Properties

MQL5 Cookbook: The History of Deals And Function Library for Getting Position Properties

It is time to briefly summarize the information provided in the previous articles on position properties. In this article, we will create a few additional functions to get the properties that can only be obtained after accessing the history of deals. We will also get familiar with data structures that will allow us to access position and symbol properties in a more convenient way.
MQL5 Cookbook: Writing the History of Deals to a File and Creating Balance Charts for Each Symbol in Excel
MQL5 Cookbook: Writing the History of Deals to a File and Creating Balance Charts for Each Symbol in Excel

MQL5 Cookbook: Writing the History of Deals to a File and Creating Balance Charts for Each Symbol in Excel

When communicating in various forums, I often used examples of my test results displayed as screenshots of Microsoft Excel charts. I have many times been asked to explain how such charts can be created. Finally, I now have some time to explain it all in this article.
preview
The correct way to choose an Expert Advisor from the Market

The correct way to choose an Expert Advisor from the Market

In this article, we will consider some of the essential points you should pay attention to when purchasing an Expert Advisor. We will also look for ways to increase profit, to spend money wisely, and to earn from this spending. Also, after reading the article, you will see that it is possible to earn even using simple and free products.
MQL5 Cookbook: Developing a Multi-Currency Expert Advisor with Unlimited Number of Parameters
MQL5 Cookbook: Developing a Multi-Currency Expert Advisor with Unlimited Number of Parameters

MQL5 Cookbook: Developing a Multi-Currency Expert Advisor with Unlimited Number of Parameters

In this article, we will create a pattern that uses a single set of parameters for optimization of a trading system, while allowing for unlimited number of parameters. The list of symbols will be created in a standard text file (*.txt). Input parameters for each symbol will also be stored in files. This way we will be able to circumvent the restriction of the terminal on the number of input parameters of an Expert Advisor.
Visualizing trading strategy optimization in MetaTrader 5
Visualizing trading strategy optimization in MetaTrader 5

Visualizing trading strategy optimization in MetaTrader 5

The article implements an MQL application with a graphical interface for extended visualization of the optimization process. The graphical interface applies the last version of EasyAndFast library. Many users may ask why they need graphical interfaces in MQL applications. This article demonstrates one of multiple cases where they can be useful for traders.
preview
Continuous Walk-Forward Optimization (Part 6): Auto optimizer's logical part and structure

Continuous Walk-Forward Optimization (Part 6): Auto optimizer's logical part and structure

We have previously considered the creation of automatic walk-forward optimization. This time, we will proceed to the internal structure of the auto optimizer tool. The article will be useful for all those who wish to further work with the created project and to modify it, as well as for those who wish to understand the program logic. The current article contains UML diagrams which present the internal structure of the project and the relationships between objects. It also describes the process of optimization start, but it does not contain the description of the optimizer implementation process.
Using the TesterWithdrawal() Function for Modeling the Withdrawals of Profit
Using the TesterWithdrawal() Function for Modeling the Withdrawals of Profit

Using the TesterWithdrawal() Function for Modeling the Withdrawals of Profit

This article describes the usage of the TesterWithDrawal() function for estimating risks in trade systems which imply the withdrawing of a certain part of assets during their operation. In addition, it describes the effect of this function on the algorithm of calculation of the drawdown of equity in the strategy tester. This function is useful when optimizing parameter of your Expert Advisors.
LifeHack for trader: four backtests are better than one
LifeHack for trader: four backtests are better than one

LifeHack for trader: four backtests are better than one

Before the first single test, every trader faces the same question — "Which of the four modes to use?" Each of the provided modes has its advantages and features, so we will do it the easy way - run all four modes at once with a single button! The article shows how to use the Win API and a little magic to see all four testing chart at the same time.
Market math: profit, loss and costs
Market math: profit, loss and costs

Market math: profit, loss and costs

In this article, I will show you how to calculate the total profit or loss of any trade, including commission and swap. I will provide the most accurate mathematical model and use it to write the code and compare it with the standard. Besides, I will also try to get on the inside of the main MQL5 function to calculate profit and get to the bottom of all the necessary values from the specification.
preview
Brute force approach to pattern search (Part IV): Minimal functionality

Brute force approach to pattern search (Part IV): Minimal functionality

The article presents an improved brute force version, based on the goals set in the previous article. I will try to cover this topic as broadly as possible using Expert Advisors with settings obtained using this method. A new program version is attached to this article.
Separate optimization of a strategy on trend and flat conditions
Separate optimization of a strategy on trend and flat conditions

Separate optimization of a strategy on trend and flat conditions

The article considers applying the separate optimization method during various market conditions. Separate optimization means defining trading system's optimal parameters by optimizing for an uptrend and downtrend separately. To reduce the effect of false signals and improve profitability, the systems are made flexible, meaning they have some specific set of settings or input data, which is justified because the market behavior is constantly changing.
Practical Use of Kohonen Neural Networks in Algorithmic Trading. Part II. Optimizing and forecasting
Practical Use of Kohonen Neural Networks in Algorithmic Trading. Part II. Optimizing and forecasting

Practical Use of Kohonen Neural Networks in Algorithmic Trading. Part II. Optimizing and forecasting

Based on universal tools designed for working with Kohonen networks, we construct the system of analyzing and selecting the optimal EA parameters and consider forecasting time series. In Part I, we corrected and improved the publicly available neural network classes, having added necessary algorithms. Now, it is time to apply them to practice.