• Home
  • Forex For Beginners
  • Forex Brokers
    • Binary Options Brokers
  • Forex Robots
  • All Posts
  • Trading Tools
    • Economic Calendar
    • Forex Market Hours
    • Online Quotes
    • Forex Charts
    • Lot Size Calculator
    • Margin Calculator
Forex Trader Portal

Forex - Trading Strategies, Robots, Indicators, Lessons

How to test Expert Advisor in MT4 strategy tester. Detailed instructions

October 19, 2024 by Michael Leave a Comment

how-to-test-expert-advisor-in-mt4-strategy-tester-detailed-instructions

Hello, everyone! Mechanical trading systems are as old as the markets are. With a development of computer technologies and the Internet in the 20th century it became possible to trade without leaving home, and in the early 21st century, with an advent of the MetaTrader platform, we can trade in automatic mode. The resources of modern desktop computer allow you to realize any, even the most sophisticated algorithms, and the built-in MetaEditor allows even a man, not familiar with programming, to write the program for the robot. As a result of the market, associated with Forex, is filled with various offers to buy miracle-advisers and some of them are really worthy of our attention.

But how can you understand that one or the other particular Forex EA can be applied on real accounts? Today I will show you how to test a trading robot on historical data using MetaTrader 4 program.

Preparation for testing

preparation-for-testing

Today we are not going to discuss how to install the EA in your terminal– there is a relevant article on my blog for this. We assume that we have already installed the EA. Now you need to think about the quotes that you will use. Most brokers do not have their own historical databases, with the exception of Ducascopy and Alpari, while the other brokers use the quotes provided by MetaQuotes. These quotes have slightly lower quality (there are gaps, errors, and inaccuracies). How to download the quotes from Ducascopy company is a topic for another article, moreover, it is not so easy to do it for a beginner. For tests of EAs, I chose the terminal from Alpari.

First, we need to configure some things, so we go to the tab Tools -> Settings or click Ctrl+O

how-to-test-ea-in-metatrader-terminal-1

A window with settings of the terminal will appear:

how-to-test-ea-in-metatrader-terminal-2

Select the tab “Charts” and fill the cells “Max. bars in history” and “Max. bars in the window” as I did it in the above picture (there are 65000 bars in each cell by default).

To make the quotes for a needful currency pair available in the terminal to test it, open the tab Tools -> History center or press F2.

how-to-test-ea-in-metatrader-terminal-3

The following window opens:

how-to-test-ea-in-metatrader-terminal-4

Select the desired currency pair and time period M1 and clicks the button “Download”. After a while, the quotes will be loaded, and then you switch off the terminal and turn it on again. Go back to the archives, click the left mouse button several times on the M1 period of the currency pair we need, until the gray battery that is depicted near the period glows yellow-green. Then you have to click with the mouse the other periods to calculate the quotes for them also. If you want to test the EA on several currency pairs, download quotes of the required currency pairs. Close the terminal and turn it on again. Then log back into the history and enter all the timeframes of the pair you need and press left button of the mouse on each of them several times. You should do all of these shamanic actions in the latest versions of the terminal because often the quotes are loaded incorrectly. The preliminary stage is completed now.

Tester of the terminal. The main functionality

tester-of-the-terminal-the-main-functionality

So, to start testing of your Expert Advisor, open the Strategy tester or press Ctrl+R.

how-to-test-ea-in-metatrader-terminal-5

Such panel will appear below in the terminal:

how-to-test-ea-in-metatrader-terminal-6

Let’s look at each function in more detail.

The first thing you will see on the left top of the panel is selector from the EA to the indicator:

how-to-test-ea-in-metatrader-terminal-7

In the new builds of the terminal, there is an opportunity to look at the work of the indicator in visual mode (which will be discussed below). I must say that it was possible to look at it before, but unofficially. Now there is a separate button for testing indicators.

So, we select the adviser.

how-to-test-ea-in-metatrader-terminal-8

Under figure 1 there is a drop-down list with the expert advisors available for testing. Here you will find only the advisors that are loaded in your terminal. Figure 2 — a drop-down list of currency pairs, choose the needed. Do not forget to upload quotes for this pair in the quotes archive. If suddenly you are unable to find the needed pair in the list, although you are sure that it is available for trading from this broker, open market overview or press Ctrl+M:

how-to-test-ea-in-metatrader-terminal-9

Next, click in the window of the navigator with the right mouse button and click “Show All“:

how-to-test-ea-in-metatrader-terminal-10

We will consider item 3 in more details. Here we can select the necessary model of testing. It is important to choose an adequate way of modeling price bars for quality testing of the strategy. Three options are available here:

— Open prices only (quick method on completed bars only for expert advisors that explicitly control bar opening)

The coarse evaluation strategy is used. Each candle generates only one tick. The fastest way of verifying is the advantage of this option. In this mode, we simulate the opening of the bar (Open = High = Low = Close, Volume=1) that allows the expert to identify the completion of the previous price bar. Testing of the EA starts on this incipient bar. The next step we have already fully formed the current bar.

— Control points (a very crude method based on the nearest less timeframe, the results cannot be taken into account).

A method of modeling of control points is intended for a crude estimate of expert advisors trading inside the bar. For this method, you must have historical data of the nearest less timeframe. In some cases, the available data of the less timeframe do not completely cover the time span of the testing timeframe. If there is no data of a smaller timeframe, the development of the bar is generated on the basis of predefined wave templates.

As soon as the historical data of a smaller timeframe appears, interpolation is applied to these data. However, the really existing OHLC prices of the less timeframe appear as control points. In most cases, the results of testing experts by method of control points can be considered only as estimates, not final. Such results have intermediate estimates.

— Every tick (the most precise method based on all available least timeframes)

This mode allows modeling price movement within the bar. Unlike “control points” the method of every tick is used for a generation not only data of the nearest less timeframe but also all available least timeframes. Thus, if at some time range there is more than one timeframe at the same time, data of the less timeframe are used to generate. As in the previous method, control points are generated on the basis of OHLC data of the least available timeframe. To generate price movements between control points, interpolation based on predefined templates is also used; it is, therefore, desirable to have a one-minute data covering the full range of testing. It is possible that several similar ticks are generated in a row. In this case, duplicated quotes are filtered, and the volume of the last of these quotes is fixed.

When testing on all ticks the volume of all generated ticks can be quite large, so the terminal can consume quite lot resources.

To test the EA you should always choose “every tick” method. Yes, this is the slowest but the most reliable method. Many people use in their EA the control of bar closing, that is, they especially wait for the opening of the new candle and open their orders only at this point. But Expert Advisors often use Stops, Takes, Trailing Stops, which may be triggered at any moment inside the candle. So you can use the method for price opening only for EAs that do not use trailing stop, stop loss and take profit, and open and close positions at the time of the opening of a new candle, but there are very few such Expert Advisors.

Item 4 – Use date. Put a tick and select the desired start and end dates of testing. If the option is not selected, testing is conducted throughout the history of the quotes loaded into the terminal. The tester will not be able to do testing of the period if there are no quotes in the archive, so you will not be able to do a test since 1300 if you don’t have quotes for this period.

Item 5 – Visualization, we will discuss it later.

The settings on the panel of the tester on the right:

how-to-test-ea-in-metatrader-terminal-11

Period – select the period for testing the Advisor. Frames are available up to D1. W1 and MN1 are not available for testing. Also, if you haven’t downloaded the price history of the period, you will not be able to perform the test.

Spread – you can specify any value or use the current spread on the pair. This is done for convenience – for example, at night and on the weekend the current spread is usually too high and if you test the EA at this time, there is a sense to set the spread manually. If you selected the current spread, results of tests may differ depending on the time of day and day of the week, especially when testing on all ticks.

Button - Modify expert is only available if you have a source code of the EA (file with mq4 extension). It opens the editor of the code, where you will be able to make necessary changes in the EA.

Button Open chart opens the chart with the applied indicators and transactions the EA performed during the test (click it after the test is performed).

Button Symbol properties

how-to-test-ea-in-metatrader-terminal-12

You can’t change anything here, it’s just background information on the currency pair that you use.

Button Expert properties

how-to-test-ea-in-metatrader-terminal-13

Clicking the button, you will see the window shown above. There are three available tabs: “Testing”, “Inputs” and “Optimization”.

Tab Testing

Here you can set deposit and deposit currency used for the test. Also, if you wish, you can choose the direction, for example, to allow the expert to trade only buy or only sell. Optimization settings will not be considered in this article. As well as the tab “Optimization”.

Tab Inputs

how-to-test-ea-in-metatrader-terminal-14

Here are all of the control variables of the EA and its settings. By the way, the window is scalable – if you pull the mouse over the bottom right corner, you can enlarge or reduce it in sizes. Together with experts configuration files with the extension *.set are supplied usually. And most often each pair has its own file with settings. To download the correct settings for the desired pairs, click the “Load” button and select the needful file. Often after you install the Expert Advisors in the terminal, they get not in the correct folder. After clicking on the button “Load” we find ourselves in the tester folder (mine is C:\Users\Michael\AppData\Roaming\MetaQuotes\Terminal\F8B0CF1E1FEED3B00D2D7E193237B799\tester. If there are no files there, go into the folder F8B0CF1E1FEED3B00D2D7E193237B799\MQL4\Presets, most likely, the files are there. So, select and download the desired configuration file. After downloading we need to find the parameters of money management of the EA and set a fixed lot of 0.1 – in this case, each dollar of gain or loss will be equal to 1 old pip. I will explain below what it is for.

Testing of the EA. Test results

testing-of-the-ea-test-results

Now we’re ready for the test. Check the settings once again and press “Start” button. After some time, the test will be performed and we will be notified about it with the help of the audio signal similar to the sound of a children’s rubber toy with squeaker.

It is time to look to the bottom left corner of the tester:

how-to-test-ea-in-metatrader-terminal-15

Here we may notice such tabs as “Settings”, “Results”, “Graph”, “Report” and “Journal”.

The list of all transactions made by the adviser during the test is available in the tab “Results“.

how-to-test-ea-in-metatrader-terminal-17

On the tab “Graph” you can admire at the yield curve of the EA.

how-to-test-ea-in-metatrader-terminal-16

If the EA didn’t make any transaction, you should look in the tab “Journal“.

how-to-test-ea-in-metatrader-terminal-18

There you will find a description of everything that happened during the test. It is likely that there is some kind of error in the EA. Decoding of the error number can be found in the section Error codes.

In the tab “Report” all the statistics of the expert’s work for the selected period of time is available:

how-to-test-ea-in-metatrader-terminal-19

Bars in test— number of bars in history, shows the depth of history on which the modeling was performed.

Ticks modeled — number of simulated ticks shows the size of the modeled sequence. Each entry of the sequence represents the state of bars (OHLCV) for a particular point of time. Depending on the timeframe, the modeling method and availability of historical data of smaller timeframes, a different number of statuses of the bar can be modeled within the bar.

Modeling quality — quality of modeling.

Mismatched chart errors - errors of the charts disagreement are the errors that occur in the simulation of ticks on different timeframes. If there is one such error, delete all the history from the terminal and re-load it. You can delete it this way: File -> Open data folder -> a window with the terminal folder opens — > History folder-> Select the required account type (the one you’re currently using) -> Close the terminal and delete all files with extension *.hst. Then upload quotes to the quotes archive again.

Here is the panel with the indicator of quality of quotes (I have it green, so I’ve found one on the Internet to show it as an example):

how-to-test-ea-in-metatrader-terminal-20

Grey– missing quotes, red - quotes for the current period only, green – affordable quotes and quotes of the previous periods, and the brighter the green color is, the earlier periods are available. If the period M1 is available, the indicator will be bright green, like mine.

Initial deposit – the deposit that was used in testing.

Spread – the spread that was used in testing.

Total net profit – net profit is the profit that was earned by the expert within a specific period. If the test is done on 0.1 lots, then the profit in the deposit currency is equal to the number of old earned pips. The same is true for all other parameters listed in the currency. Net profit = Total profit — Total loss.

Gross profit - how much was earned during the working of the EA.

Gross loss – how much was lost.

Profit factor — profitability, shows the relationship between total profit and total loss. It is calculated by the formula: Profitability = Total profit/ Total loss.

Expected payoff — mathematical expectation of a win.

Absolute drawdown is the difference between the initial deposit and the smallest value of balance within testing process.

Maximal drawdown is the highest difference between one of the local upper extremums of the chart of changes in balance and the following lower extremums.

In the following picture, figures show the main stages of changing the magnitude of the maximum drawdown during the testing process. The value of the maximum drawdown is shown with bold arrows.

how-to-test-ea-in-metatrader-terminal-21

Relative drawdown shows the ratio of maximal drawdown and the value of respective local upper extremum.

I think the other test data, such as average profitable trade, the maximum number of consecutive losses and so on, are quite clear and I don’t need to explain it here.

If you click on the report with the right mouse button, you can save this report as HTML file:

how-to-test-ea-in-metatrader-terminal-22

At the top of the report are the main data on the conditions of the test – a period, a currency pair, model of testing, parameters of the EA and so on. Below are the statistics of the test and chart of the yield curve. Later in the form of a table is a list of all executed trades.

The visualization mode

the-visualization-mode

This mode provides the ability to literally see in an accelerated mode how the Advisor would work with the changes of quotes, which took place. For example, if the signals for the entries and exits of the EA are based on the signals of any indicator, then you can set the desired indicator on the chart of visualization and so the emergence of transactions and closing deals will be even more visually.

In other words, visualization helps to understand and appreciate the logic of the EA algorithm, since everything will happen in front of your eyes. In addition, visualization is also used when you want to see the nature of the origin of any particular section in the work of the EA (the moment you start draining the deposit, on the contrary, the most profitable period).

An operation of the robot in visualization mode can help you to understand how it works and will know what to expect from it in the future. This is a very useful tool, especially for EA developers.

Conclusion

conclusion-how-to-test-ea

In this article, we have described the main functionality of strategy tester of MetaTrader 4 terminal and features of quotes downloading. We also met with the test results of the EA and visual mode of testing. I want to note that this is only the basics of working with EAs. The method of testing, discussed in the article, is suitable for advisers on timeframes from H1 and above. For scalpers, who works on shorter timeframes, this method of testing is relatively suitable, it is of a purely informative nature. If you are going to earn with the help of advisors, it is also necessary to master the optimization of expert advisors. Also, it is useful to gain a deeper knowledge about testing and optimizing of expert advisors with higher modeling quality that is unavailable, unfortunately, in the standard version of the terminal.

Take care, Michael

Forextraderportal.com

Related Posts:

  • Best Forex Robots 2021
    Best Forex Robots 2021
  • Montag Expert Advisor - Profit on Mondays
    Montag Expert Advisor - Profit on Mondays
  • Five Signs of a Useless Forex Indicator
    Five Signs of a Useless Forex Indicator
Posted in: Forex Robots Tagged: expert advisors, strategy tester, testing mt4
« Price Action: Inside Bar Lesson 1 - Believe in Yourself and Change Your Life! »
← Price Action: Inside Bar
How to take into account the spread in Forex when opening and closing trades →

Categories

  • Binary Options
  • Currency Pairs
  • For Traders
  • Forex for Beginners
  • Forex Indicators
  • Forex Robots
  • Forex Trading Psychology
  • Forex Trading Strategies
  • Price Action

Recommended Forex Broker

Have To Look

  • The 5 Steps to becoming a trader
  • How to install a Forex Robot?
  • The whole truth about leverage in Forex
  • What is difference between old and new pips in Forex?
  • Trading Strategies Installation Instructions
  • My VPS choice

    About This Site

    This blog mission is to teach people about Forex trading, including trading strategies, robots (EA), and indicators. We provide newcomers with lessons, reviews, tutorials, and more.

    Join us on Facebook!

    Random Posts

    • Where To Invest Money in November?
    • Lesson 9 - Trading Psychology
    • Repainting indicators - is it always bad thing?
    • Montag Expert Advisor - Profit on Mondays
    • Forex Tester 2 - Secret Weapon of a Trader

    Copyright © 2023 Forex Trader Portal.

    Omega WordPress Theme by ThemeHall

    Home | Forex Robots Laboratory | For copyright holders | All posts |
    Risk Warning. There is a high level of risk involved when trading leveraged products such as Forex. You should not risk more than you can afford to lose. All posts published on this portal are only recommendatory and all responsibility for decisions lies on readers.
    (c) 2015-2021 All rights reserved