Metatrader 4 testing on historical data. How to backtest an Expert Advisor in MT4

Technology is evolving at an ever-increasing pace.

Previously, market analysis was carried out on quotes that came from the telegraph tape, charts, hand-drawn on millimeter paper. It was a long and laborious process, when the preparation for the analysis took more time than the analysis itself.

Computer technology has changed and continues to evolve, making it possible for everyone to have access to market data and trade right from their homes. At the same time, modern terminals have the widest range of tools for analyzing the market situation. And, if earlier there was a question of how to get access to the market in order to make at least some kind of overview of the market situation, now the main task is to choose from the available variety of analysis tools.

In addition, automated trading has become available to everyone. Modern trading terminals have development environments that allow even people who are not deeply familiar with programming to create trading robots. Therefore, the market of robots for automated trading is now replete with all sorts of offers of advisors.

Among them there are many who can bring really good results. But in order to understand how effective these robots are, you need to test them and make sure that they showed stable results at least on past historical data. After that, you can already proceed to testing in the real market and trading itself.

The MetaTrader terminal has a built-in strategy tester, on which you can test a forex advisor with detailed statistics on the results.

Training

You can read about how to install an adviser in the terminal in this article.

In order for testing to be correct, first of all, it must be carried out on high-quality quotes.

Most brokers do not have their own archive of quotes, they use quotes from MetaQuotes, the developer of the MetaTrader terminal. This is far from the highest quality data; their archive of quotes is full of gaps and inaccuracies. Data from testing on such data will not be of practical use and may differ greatly from the results that would be in the real market.

For example, brokers Ducascopy and Alpari have their own archive of quotes. For the second, in order to get it, you must have a real account, and access to such quotes is not provided on a demo account.

First of all, you need to make basic settings.

You need to press Ctrl + O or select the menu “Tools-> Settings” with the mouse.

In the "Settings" window that opens, select the "Charts" tab. In the items "Max. history bars" and "Max. bars in the window” we prescribe 1,000,000,000.

Then go to the menu item "Service->Quotes archive". It can be called by pressing the F2 key.

A window will open where you can select the desired currency pair and time interval. Select the period M1 and click "Load".

Once the quotes are loaded, you need to restart the terminal.

Then we go back to the Quotes Archive menu, again select the desired currency pair, click on the m1 period until the icon to the left of it lights up in yellow-green.

After that, you also need to go through all the other periods of this currency pair so that the quotes are calculated for them for everyone.

If testing will be carried out on several currency pairs, then these manipulations must be done for each of them.

That's all with preparation.

Strategy tester and its basic features

Pressing Ctrl+R opens the strategy tester panel. You can also call it by pressing the corresponding key in the top panel of the terminal.

The working panel of the strategy tester will open at the bottom of the terminal:

On the top left there is an item where, by clicking the mouse, a menu pops up and you can choose what you want to test: an adviser or an indicator in a visual view mode. In our case, select "Advisor". And opposite this item on the right in the drop-down menu, you can select the EA itself, which needs to be tested. But, of course, only those advisers that are installed on your terminal are available for selection.

In the "Symbol" field, you select a currency pair or any other financial instrument that is available in the terminal, and the broker provides its quotes. If suddenly you cannot find the pair you need, but you know for sure that it is, then go to the "Market Watch" window on the top panel of the terminal, and right-click in it, and then select "Show all symbols" in the menu.

In the "Model" item, you select the way how quotes will be issued, and how candles or bars will be drawn.

The following chart simulations are available for testing:

  1. Opening prices. With this method, the bars are drawn entirely in one tick at once. And there is no real-time information about how the price behaved during the formation of the candle. Candles are drawn quickly, this speeds up the process. But this method is suitable only for testing those Expert Advisors where you need to control the opening of bars.
  2. Control points. It's also a very rough way of estimating. To simplify, it takes data from the previous timeframe, namely OHLC prices (i.e. Open, High, Low and Close), and builds a bar based on them. Its readings can only be used for the evaluation run of the Expert Advisor, but not for full-fledged testing.
  3. All ticks. This method already uses prices not only from the nearest lower time frame, but also from all lower time intervals. If there is data from several timeframes for the formation of some period of time, then the smallest one is taken. If suddenly there is no data between the points, then interpolation is used based on the specified patterns. If suddenly quotes are duplicated, then filtering takes place, and the volume of the last quote is taken. This method is more demanding on resources, which can significantly load the terminal.

As it becomes clear, the latter method is the most reliable and accurate for testing most Expert Advisors, because it provides more accurate price data, as close as possible to market conditions.

Next, in the "Use date" item, you can select the testing period by time. If this item is not touched, the tester will test all the quotes that are available to him. If you check the box next to it, then fields will become available in which you can specify the beginning and end of the time interval for which you want to conduct testing.

On the right in the tester panel there are also several items for setting up testing.

In the "Period" item, select the timeframe on which the testing will take place. The maximum available for testing is D1. And it is necessary to download the history of quotes of exactly the time interval on which you are going to conduct testing.

In the "Spread" field, the current spread will be selected by default. If you need to test an adviser that, for example, trades at night, and your broker's spread is increased at this time, you can manually set its value of interest.

If you have access to an Expert Advisor file with the .mq4 extension, you can click the "Change Expert Advisor" button, thereby calling the code editor where you can make your own changes.

After the end of the test, the function of the "Open Chart" button becomes available. Pressing it opens the chart of the pair with the adviser's indicators and the deals that he made during the testing.

By clicking "Symbol Properties", you will open an information window with the specification of the financial instrument on which you are testing.

"Expert Properties" brings up a window with three tabs, as in the screenshot below.

In the "Testing" tab, you can change the size of the deposit and the currency of the account. You can also instruct the EA to open only buys, only sells, or both.

The "Inputs" tab displays the Expert Advisor's settings. If the Expert Advisor already comes with ready-made settings presets, for example, for certain pairs and time intervals, then they can be uploaded by clicking the “Load” button and selecting the settings file with the *.set extension.

The "Optimization" tab will not be analyzed, as well as the process of the Expert Advisor's optimization. This is a separate deep topic that is not retracted into the scope of this article.

The last thing to do before starting testing is to set the trading lot to 0.1 lots, so that each change of 1 pip in the old four decimal places equals $1. This will come in handy during the testing of the evaluation of the results.

Testing process and results analysis

Pressing the "Start" button starts the test.

When it ends, the sound signal of a children's rubber toy sounds.

To evaluate the results, the tabs at the bottom of the strategy tester panel will help us: "Settings", "Results", "Chart", "Report", "Journal".

In the Results you can find a list of all trades of the Expert Advisor for the testing period and the results for them.

In the Chart, a yield curve is drawn, according to which you can briefly assess the stability of the adviser's trading, the rate of deposit growth and other points.

The Log displays system messages about events during testing. If something is wrong with the adviser, and some kind of error has occurred, then just here you can find information about it.

The Report contains all the important statistics.

Bars in history— how many bars are taken for testing for the selected time period.

Simulated ticks— the number of recreated ticks, taking into account data on Open, High, Low and Close prices and on volume (volumes). This number may vary depending on the testing model, time interval and quality of quotes.

Simulation quality- Displays the quality as a percentage.

— shows whether there are errors when recreating ticks for different time intervals. There should be no mistakes, otherwise the results will be far from reality.

If there is at least one error, you need to update the quotes archive. And for starters, it's worth deleting the old archive. To do this, click "File -> Open data directory -> History -> select the folder of the current trading account -> close the terminal without closing the folder -> delete all .hst files".

Then we update the archive of quotes again, as described at the beginning of the article.

An example of how errors are displayed in the graph mismatch error panel is below.

Quotes that are missing are shown in gray, quotes from the current time interval are shown in red, quotes are shown in green that are available both on the current and on younger time intervals. Brighter green shows younger time intervals.

If there are no errors and quotes with m1 are available, then the entire scale will be bright green.

Initial deposit- initial starting amount.

Spread— the one on which the EA was tested.

Total profit- how much is earned.

Total loss- how much is lost.

Net profit is the difference between total profit and total loss. When testing 0.1 lots, each dollar of profit is equal to 1 point earned.

Profitability= total profit/total loss.

Expectation of winning- speaks for itself.

Absolute Drawdown- shows the difference by which the balance fell from the initial deposit.

Maximum drawdown— the maximum difference between the highest point of the Expert Advisor's yield curve and its lowest point.

Relative drawdown= maximum drawdown/value of the highest point of the EA's yield curve.

What the rest of the data shows is easy to understand by their names and readings.

Imaging mode

If this item is checked, then after pressing the "Start" button, a separate chart will open, on which candles will be drawn in accelerated mode according to previously downloaded quotes from the archive.

Such a visual mode is convenient if you need to see with your own eyes how the adviser worked out certain moments in the market, how he opens and closes deals. That is, it can be better understood there.

If you know what indicator the EA is based on, then you can put this indicator on the visualization chart and check the quality and accuracy of the EA's inputs.

In addition, you can watch live. how the adviser behaves at some turning points in the market or at the time of the release of important news.

In a word, by getting the ability to visualize, you get more control over the testing of any robot.

Conclusion

It is worth saying that this method of testing Expert Advisors is more suitable for robots that work on intervals from m30-h1 and higher.

For scalping robots that trade on smaller time intervals, other testing methods are needed, where the quality of modeling is much better, more precisely, closer to the real indicators of market quotes from a broker.

For those who need to test any manual trading systems on the tester in an accelerated mode, the tester is suitable TradeSystem2, which has a number of convenient advantages in comparison with the standard tester of the MetaTrader terminal.

With the advent of advisors, it became possible to trade in a fully automatic mode. All that is required of you is to launch it and collect profits after a certain period of time. But how to make sure that while you are drinking tea, the adviser will not drain your entire deposit? Before entrusting your money to the robot, it is recommended to test the adviser.

How to test on MT4 video:

Loading quotes

Before testing the EA, you will need to download the quote history. To do this, go to the address: "Service/Quotes archive".

After that, the following window should appear in front of you:

Now you need to choose the right currency pair and on which you plan to test the EA or indicator. I decided to test the adviser, and it is recommended to use it on the EUR/USD currency pair and on the M15 time frame. Therefore, in the left corner, I select the currency pair I need and the M15 time frame. I double-click on it with the mouse so that it lights up in yellow-green color, after which I click on the download button.

After that, a green bar will appear, as in the picture below, wait until it is fully loaded, as a rule, it takes 2-3 minutes.

Important: In order to access all Alpari quotes, you will need to open a live account. For everyone else, the broker company provides incomplete information, on the basis of which it is impossible to draw an accurate conclusion about the effectiveness of the adviser.

So, now you can restart the trading platform and proceed to the main actions.

To start testing the EA, click on the strategy tester.

After that, the following window should appear at the bottom of the chart:

So, let's see what settings are here. So, on the left we see such an icon, with which you can choose to test an adviser or indicator. I decided to test the EA, so I leave the EA here.

  1. In the setting labeled 1, you can select your Expert Advisor that you want to test. Please note that here you can only find tools that are already installed in your trading platform.
  2. In the line marked with the number 2, select the currency pair you need for testing.
  3. In the line marked with the number 3, select the required model for the test. There are 3 available options here:
    1. At opening prices, this is a quick way to test, but not entirely accurate. The only advantage of this evaluation is the high speed.
    2. Checkpoints are a rough way of testing, the results of which are not quite suitable for an objective evaluation of an Expert Advisor.
    3. All ticks is the most accurate way to test. To test an Expert Advisor, it is recommended to use this method of evaluation. Its only drawback is low speed.

    1. In the first tab "Testing" you can enter the estimated initial amount of money.
    2. Opposite the "Positions" line, you can instruct the Expert Advisor to open deals only for buying, for selling, or allow both, leaving the standard value.
    3. In the "Inputs" tab, you can see the standard settings of the Expert Advisor you are using. In order to download the file with the settings, click on the "download" button. I plan to test the EA with standard settings, so I won't change anything here.

So, after you have configured the parameters for the analysis, you can click on the "Start" button. After some time, the testing of the adviser will be completed, and you will be notified about this by a sound signal.

Test results

In the window you can see the following tabs:

  • With the settings tab, everything is clear, the settings used will be displayed there.
  • In the "Graph" window, you can see the Expert Advisor's performance graph.
  • If the adviser has not opened a single trade, then you should go to the "Journal" tab. Here you can find information about all the actions taken by the advisor.
  • In the "Report" tab, you can find the full statistics of the robot's work for the selected period of time. Everything is clearly written here, I think that you will not have any problems with reading the information.

Now you know how to test an Expert Advisor in MT4. I hope today's lesson will help in increasing profits in the Forex market.

Comrade traders, let's slowly move on to trading advisors (robots). Let's start the development of this topic from afar - with such concepts as a strategy tester and a quotes archive.

The MetaTrader 4 Strategy Tester is a familiar thing for the majority of traders, but
yet many do not know what it is, how it is called, and in general why this
strategy tester.

The MetaTrader4 (MT4) trading terminal allows not only writing Expert Advisors,
but also test them before use. This useful feature allows
check the performance and efficiency of the trading robot on
historical data. Testing allows you to start
auto trading, knowing about the behavior of the adviser in various
market situations. For these purposes, the trading terminal has a built-in
special window "Strategy Tester".

Recommend article
///////////////

Strategy tester options

How the "Strategy Tester" is called: View Strategy Tester or (CTRL + R).

After that, you will see the following picture in the terminal

Consider the parameters of the strategy tester:
Advisor

In this menu, select an adviser that we will backtest.
The drop-down menu displays advisors that are located in the navigator of the trading terminal.

///////////////
Read the article about Forex trading.
///////////////

2. Expert Advisor properties
After you have chosen an Expert Advisor for testing, you need to
carry out additional testing and input parameters adjustment according to
to your discretion. This can be done by clicking the "Properties" button.
expert." This will open a new window with three tabs:

a) Testing - in this tab general parameters are set
testing. These include the volume and currency of the initial deposit,
which are indicated in the respective fields. This deposit will be
operate the adviser during testing. This tab also selects
types of positions to be opened during testing: Only Long - open only
long positions; Only Short - only short; long and short
open positions in both directions. Whatever the trading algorithm
expert, he will open positions only in the specified directions.
You can also enable the genetic testing algorithm.

///////////////
You may be interested
///////////////

b) Input parameters - in this menu, in the form of a table,
list of all input parameters of the trading robot. Input parameters
are called variables that affect the work of an expert and can be
changed directly from the client terminal. To change these settings
there is no need to change the expert code. Number of input variables
may vary from advisor to advisor. When testing the input
Expert Advisor parameters are set in the "Value" field. Data written to
fields "Start", "Step" and "Stop", do not affect the testing of the adviser and
needed only to optimize its parameters.

c) Optimization
Expert Advisor settings in this tab allow you to manage the restrictions
test passes during optimization. Changes to the settings in this
The tab does not affect the one-time testing of the Expert Advisor.

3. Symbol.
In this menu, select a symbol - a trading instrument for which the adviser will test.

///////////////
I advise the article
///////////////

4. Model.
This menu offers three options, they are also located in
drop down list. Depending on the algorithms of your adviser
can choose

a) By opening prices (fast method on formed bars).
Some mechanical trading systems do not depend on features
intra-bar simulation, they trade on formed bars. ABOUT
that the current price bar is fully formed, you can find out by
appearance of the next. It is for such experts that this mode is intended.
modeling.

b) Checkpoints (the nearest smaller timeframe is used).
The checkpoint modeling method is intended to be a rough estimate
experts trading inside the bar. This method requires
historical data of the nearest smaller period (timeframe). I.e,
for example, if you are testing an EA on H1, the EA can take into account M30 prices,
but not M15.

///////////////
Learn how to work with
///////////////

c) All ticks (based on all the smallest periods available). This
mode allows you to most accurately simulate the price movement inside the bar. IN
unlike the "checkpoint" method, the tick method uses to
generating data not only for the nearest smaller timeframe, but for all
available smaller timeframes. At the same time, if for some temporary
range, there are data from more than one timeframe at the same time,
data of the smallest timeframe is used for generation. This method
the most accurate but also the slowest. This testing method is
most popular among Forex traders.

///////////////
Read also the article.
///////////////

5. Use the date.
The date range allows you to test Expert Advisors not on all available
data, but only on a selected time interval. This is convenient when
the need to examine a separate part of historical data

6. Visualization.
If you want to visually check the work of the adviser on history, then
check the box here, while testing is slower, but
detection of errors in the work of the adviser requires this. Playback speed
can be adjusted by moving the special slider to the right of the entry
"Visualization". You can pause playback by pressing the "||" button.
Pressing this button again resumes the flow of simulated
ticks. Pressing the F12 key causes an instant appearance
next tick even when paused. Visualization can be skipped until
certain date. After setting the desired date and pressing the button
"Skip until" rendering stops and resumes after
achievement by the tester of the specified date.

///////////////
Learn the right way
///////////////

7. Period.
Everything is very clear here, this is the timeframe on which you want to test the adviser in the strategy tester.
After clicking on the "Start" button, the adviser will start testing according to the parameters you specified

In the "Journal" menu, you can monitor the execution of trading commands
Expert Advisor, as well as to see errors that occur during testing.

You may be interested in the article "Forex".
///////////////

Features of the strategy tester in MT4

If you download the history of quotes for a long period of time, the test results for the last year or two will be the most accurate. Perhaps some of the data is lost over time, I can’t say why this happens (if someone knows, tell me in the comments, I’m interested). This nuance takes place even when using all ticks in testing. Therefore, it is worth giving more significant importance to the results in recent years, both for trend and counter-trend systems.

You might be interested in the article
///////////////

When should you not trust the results of the strategy tester in the metatrader?

1) When the trading strategy makes entries and exits "according to the market".
2) When the holding time of trades is very short (several minutes or even seconds)
3) When testing is carried out on the "current spread"

If a trading advisor (robot) falls under paragraphs 1 and 2, this is very dangerous. The fact is that there is a Forex broker factor. The broker can simply "cut off the oxygen" - increasing the time of execution of transactions. In this case, short-term systems will suffer greatly from poor trade execution.

///////////////
By the way, there is a very good article about trading costs (Forex commissions).
///////////////


Artur Bykov (Agudar project) was with you, thank you for your attention!

Watch the most detailed video on how to install and test a Forex advisor!

Hello Web Investors! In this article, we continue the topic of investment through Forex advisors. I hope you read? There you should have learned in general terms what an adviser is and how to search for them on the Internet.

In this article, you will learn how test the adviser in MT4.

So, you have downloaded a Forex advisor and want to know if it can generate income. First of all, you need to check it in the “Strategy Tester”:


It is widely believed among traders that tests cannot be trusted, only results on a real trading account are suitable. Is it so?

Alas, the strategy tester for mt4 does not provide high accuracy. Even using the best quotes and 99% testing accuracy, you cannot achieve close to real results, because the Forex strategy tester does not take into account some of the "chips" of real trading:

  • floating spread;
  • order execution speed;
  • slippage.

On the other hand, how much does all this affect the results of the trading robot? There is a simple rule here - the more deals and the smaller the timeframe, the higher the influence of "technical" moments. It is better to test Expert Advisors with long-term strategies, and it is better to put scalpers on real immediately.

In short, the MT4 Strategy Tester is a good tool for general evaluation of an EA, but not for predicting its performance. How to use it correctly - read on.

By the way, since I myself am actively looking for advisers, I have accumulated a lot of interesting finds. All of them are in a special network warehouse, which can be accessed using the form below:

As they say, use on health! Now let's move on to the article itself:

Setting up Metatrader and quotes

The quality test of an Expert Advisor directly depends on the quality of the quotes you use. Through some manipulations, it is realistic to get an accuracy of 99.9%, but this is the subject of a separate article.

In this article, you will learn about fast way get an accuracy of 90%, which is enough for a rough assessment of the advisor's capabilities.

Advice: store advisers and quotes found on the Internet in a separate Metatrader. For this it's simplecopy the program folder to another location and rename the folder. The new MT4 is launched as always via terminal.exe.

Where to download quotes for MT4? There are two ways:

  • directly from the broker's servers;
  • from the Internet as a file.

Method number 1. Download quotes via Metatrader.

Unfortunately, not every broker has such an opportunity. By default, the program offers to download quotes from the developers of Metatrader - Metaquotes, and they are not of very high quality.

Alpari has such an opportunity. Download Metatrader, open it, look for “Service” => “Quote archive”:


A window will appear in which you need to select a currency pair, for example, the Eurodollar. We press “Download” and in a couple of minutes we get more than 5 million records.


Click “Download” again to download the records that for some reason did not appear the first time. This should be done every time, and only when the message appears:


everything will be OK. For other couples, the procedure is no different.

Method 2. Quotes from the Internet.

In this case, we need Metatrader without connecting to the server.

To do this, download the program, open any account with the desired broker and go to the terminal. This is how we get the settings that are used in Expert Advisors.

When everything is done, log out and forget about the trading account. Metatrader will now always be disconnected from the server so that the quotes that we download further do not mix with the new ones.


Hst files you will find in history/ “Server name”, in our case it is Alpari-ECN1:


We clean the folder from all files with the name EURUSD.

You can most often download quotes on the broker's website, sometimes traders share their own on the forums. As an example, let's find them on the website of the (already deceased) broker RVD Markets:


Specify the minute timeframe and the period for which we need quotes. You can immediately download the .hst file (which we previously deleted), and let's do it. Download the quotes archive for MT4 and upload it back to history/ "Server name". We restart the terminal.

We downloaded the minutes, but to get the rest of the timeframes, you can use the useful script Period_Converter.


Before using the script, we need to open the chart we need, namely EURUSD M1. For this we go to File => Open offline:

Drag EURUSD M1 to the chart window, and then the script itself:


Period multiple factor- a variable that means the number of minutes in the timeframe we need. Here is a table for your convenience:

  • M5 - 5 minutes
  • M15 - 15 minutes
  • M30 - 30 minutes
  • H1 - 60 minutes
  • H4 - 240 minutes
  • D1 - 1440 minutes

Everything about everything will take a maximum of a quarter of an hour. By the way, if you haven't removed the extra .hst files, the script may not work.

When the quotes are ready for use, you can start testing the Expert Advisors. I will only add that if you are planning to install an adviser not in Alpari, it is better to use the second method and download quotes from your broker.

Well, when the data is ready, you can run the program to test trading strategies.

In this section of the article, we will analyze how to test an Expert Advisor in MT4. We will check Expert Advisors in this window:


Let's go over the interface a little, first the block “Test conditions”:


1. Advisor. Select an advisor from the list. If you don't have what you need, here it is.

2. Symbol. It is also the currency pair you are going to test. Usually the author of the adviser indicates which pairs to work with.

3. Model. There are three models for testing Forex strategies:

All ticks - the most accurate method, which uses the smallest available time period, i.e. M1.

Checkpoints - the nearest timeframe is used, which significantly reduces accuracy.

Opening prices - what happened to the price inside the candle is not important, Open = High = Low = Close. Worst accuracy.

Obviously, for tests it is worth using the model All ticks. But sometimes she spends hours getting results, in which case she has to switch to Control points.

4. Period. From minutes (M1) to daily (D1).

5. Spread. It is set automatically if you set “Current”, or manually. Please note that a 4-digit broker will have a spread in the region of 1-5 points, while a five-digit one will have this figure 10 times more - 10-50.

Advice: look at the EUR/USD pair - if the price looks like 1.3456, then you have a four-digit broker, if 1.23456 - a five-digit one.

In my experience it is better to set the spread yourself, and you can see it on myfxbook .

Block “Date selection”:


6. Use the date. We determine the test period, if you uncheck the box, the entire available history for the currency pair will be used.

What is the optimal period for the correct testing of an EA in MT4 is a moot point. Personally, 3.5 years is enough for me to evaluate the performance of the adviser.

However, if possible, it is worth setting a longer period. This is especially important for long-term Expert Advisors, because they rarely make deals. Use the rule, if there are less than 100 deals, you need to increase the testing period.

7. Visualization. A useful option that allows you to see the work of the adviser directly on the chart.

The speed is set by the slider, and the “Skip until” button is useful if you need to jump to a specific date.

“Test Settings”, another block of the Forex strategy tester:

8. Expert Advisor properties. Here are the main testing parameters and the parameters of the adviser itself:


On the "Testing" tab, we change only the initial deposit. The “Optimization” section will be considered in a separate article.

Usually you have to work with the “Input parameters” tab:


The LotSize parameter is very important for testing Expert Advisors. This is the size of the trading position that will be used by the EA. In order to compare the effectiveness of different Expert Advisors in the future, you should always set a lot of 0.1 and an initial deposit of $10,000. This is not taken from the ceiling - so 1 pip for a four-digit or 10 for a five-digit for dollar currency pairs equals $ 1.

One more important point- method of money management. For tests, always put fixed lot(Lot/LotSize/FixLot etc.).

9. Character properties. Information on the currency pair you have chosen for testing.

10. Open a chart. Visual display of the adviser's trades and indicators with which he worked:


11. Change the expert. Switching to the editor of MQL4 Expert Advisors.

And finally, "Optimization":


What kind of animal is this? In a nutshell, this is the Expert Advisor running over one and the same section of the chart using different sets of settings. Accordingly, the goal is to find the most successful sets (“sets” from .set). It’s not worth climbing into this steppe without a deep understanding, so let’s skip it.

Well, we figured out how to use the strategy tester in mt4. And there was only one thing left - to evaluate the received figures.

Analysis of test results

Let's make a small test of the Night Owl Expert Advisor, which feels pretty good in our . For example, let's find out how it works on the EURUSD currency pair with the M15 timeframe.

We will use the previously downloaded RVD quotes. According to Myfxbook, the average spread for Eurodollar is 5 pips.


We set the standard settings - $10,000 starting deposit, trading lot 0.1:


We start and wait for a while. When the test is over, three new tabs will appear:


RESULT. Information about purchases (buy) and sales (sell) made by the EA, as well as about modified orders settings (modify). Well, in addition, the volumes of transactions, opening prices with Stop Loss and Take Profit levels, profit and balance.


SCHEDULE. Here is what the Night Owl EA showed us:


It is not worth analyzing the chart especially, the main thing is that it grows smoothly to the upper right corner, without large drawdowns. This is what happens in the chart above, but it is clear that the last 10 trades were completely unsuccessful.

REPORT. The most important tab that gives the most information. However, keep in mind that the accuracy of the tests is only 90%, the numbers in real trading will be somewhat different.

So, the test report of the Expert Advisor on EURUSD:

I will focus on the most useful and important indicators.

Net profit. How much did the adviser earn. If this number is divided by the initial deposit, you get the yield.

Profitability. Calculated according to the formula Total Profit/Total Loss. If 1.6 or higher - the adviser works fine. We have 1.42 - the adviser is not so good.

Total transactions. Must be greater than 100 - otherwise the test cannot be used, the sample is too small. Extend the testing period.

Simulation quality. Using minute data, we will get a maximum of 90%. You can get confused and achieve 99% on tick data. If it is less than 90%, the test cannot be trusted at all.

Winning expectation. How much does a deal bring in on average?

That's all, finally you will learn where to store the received test results.

Saving tests for future use

It is desirable to save the results obtained somewhere so as not to test the same thing 10 times. For example, you can create a table in Excel and fill it with only the most necessary data:


The report can then be viewed in a browser:

Files can be stored in a folder on your computer, or you can upload them to myfxbook, in the “Systems” => “Strategies” menu:


Let's add here our test of the Night Owl trading robot:


In the “Strategy report” field, add the file that you saved earlier. We fill in the rest of the fields, do not touch the Forward Test.

Click "Add" and wait until everything is ready. The test report will appear in the list of strategies, where you can select it and go to the analytics window:


The indicators here are similar to those we have already seen in the metatrader reports. The rest are intuitive, except for the third column - but I don’t use them for analysis.

Preparing for forward testing

The minimum period for a high-quality forward test is 3 months, so the first step is to ensure the smooth operation of the adviser for this time. The easiest way to do this is by renting a VPS server, but if you can leave your computer running 24/5, you can save on this, why not.

You can “multiply” the Metatrader trading terminal like this: find the folder with the installed program (usually the name of the broker) and copy it. The new terminal is launched via terminal.exe, which can be found in the same folder. It is advisable to make a folder with shortcuts to metatraders on the desktop in order to quickly find the one you need in the future.

Requirements for trading accounts are usually indicated on the source site, if they are not, you can navigate through this list:

  • Trend long term: any option
  • Scalpers: ECN, low spreads
  • : any option
  • Nets: if grid orders hang for weeks/months - then only swap-free

Naturally, these should be cent accounts- the adviser will work in the same way as on a regular one, but the amounts will be 100 times less. Possible malfunctions of owls will not hit hard on your pocket.

Can demo accounts be used for forward testing? Only if the adviser is not picky about the type of account, otherwise the result will be inaccurate. From the list above, these are trenders and martingale robots.

When the terminals and accounts are ready, it's time to decide on which currency pairs to test advisers. The goal of forward testing Forex advisors is not to make money, but to check the performance of owls, so you should put them on all promising currency pairs:

  • Mandatory all pairs that are listed on the source site. The author set up and optimized the adviser specifically for them, it is foolish to miss it during tests.
  • super profitable, and just profitable, and those that work at 0, and even slightly draining. In short, any promising currency pairs - it is not known where the robot will perform best in the future.
  • It makes no sense to put seriously unprofitable pairs on a forward test, even for the big picture. Ideally, you will work with an adviser for more than one year, during which time he can lose a decent amount on an unsuccessful pair.


It often makes sense to test currency pairs on different timeframes and settings. After analyzing the data in the table, you will find the best adviser parameters for each currency pair - that's what you will need to check on a real account.

It is worth recalling that the installation of the adviser on several currency pairs is done at once through the parameter MagicNumber- an integer from 1 to somewhere 100000000:


The next important point is deposit amount And trading lot. In principle, it is not particularly important to make a profit when testing Expert Advisors (although it is also not worth constantly draining money) - any result is important. For this reason, the trading lot should be as small as 0.01.

The deposit must withstand several dozen unsuccessful transactions in a row, since a lot of currency pairs are tested at the same time. In principle, for these purposes it is enough 5-10$ on a cent account. A separate story with martin and grids - here you already need to follow the recommendations on the minimum deposit from the developer.

After preliminary preparation, you will only have to use the VPS server and set up real monitoring of Forex advisors using the Myfxbook service.

Everything works like clockwork? Great, now you need to wait 3 months and start analyzing the results.

Monitoring analysis on a real account

More or less significant results should be expected only three months after the launch of the forward test. For long-term advisors, the term is increased to six months. We go to the monitoring page of the Forex adviser on a real account and look at the first block of information:


You may be surprised, but an increase in % is absolutely not needed for analysis. With a different initial deposit, it could be 1.3% and 130%, these are the nuances of money management and now we are not interested. The main thing to pay attention to is the shape of the graph. It must move without major deviations. from the lower left to the upper right corner.

However, it is too early to analyze the chart, as it overall result for all currency pairs, and we are interested in individual results. Opening the block "Advanced statistics" => "Main"

It's not so good here, but still more than 70% of profitable trades with a profit factor of 2.70. The standard deviation is even lower, which means the EA is more stable on this currency pair. There was one large stop and several small ones.

GBPCAD



Many profitable trades, but only one loss-making one gave almost -2%. Apart from the lower profits, everything looks like a pair of GBPAUD, which is not surprising due to the common term in the form of a pound. It is not recommended to put one Expert Advisor on correlated pairs on a serious trading account, so GBPCAD flies by at this point.

Another important point is the analysis of currency pairs, on which the robot has just started to work well. It could be chance get additional profit.

To do this, you need to analyze the work of the adviser for the last month. Go to "Custom analysis" and set the desired settings:



We get this result:



The GBPAUD (281 pips, 6 trades, 100% profitable) and EURCAD (98 pips, 8 trades, 7 profitable) currency pairs stand out - many highly profitable trades. As we remember, GBPAUD brought a good profit for the entire test period, but EURCAD is 9th in the overall rating. Worth paying attention!

Knowing the specifics of the Asia scalper, the EURJPY and EURUSD pairs do not look so interesting, because. they took a lot of points for a small number of transactions, that is, they were just lucky.

We return to the full monitoring of the Forex advisor. There you can find a bunch of all sorts of charts and statistics, but for the purposes of a forward test, there are not so many useful ones. It's worth taking a look at the "History" tab:


Here you can learn a lot of interesting things - stop sizes, best and worst trades etc. By clicking on the "More" button, you can configure any information that interests you. It is useful to look at all transactions at once, and for specific pairs - in order to better understand how the adviser earned his points and percentages.

Do you have any unclear points about how to test an Expert Advisor in MT4? Ask questions in the comments to the article, we'll figure it out. And be sure to share the article on social networks:


Financial success!


(add me to friends

Testing the robot on history allows you to see the results of using the strategy without the risk of losing money, to assess the chances of making a profit when using the robot. However, to get more accurate results, you should correctly backtest the EA in the MetaTrader 4 terminal.

The previous article described.

It was already mentioned in passing that for testing trading advisors, a special “Strategy Tester” module built into the MetaTrader 4 trading terminal is used.

Launching the "Strategy Tester" module

To open a module, you can do any of the following:

1) Select the menu item "View" -> "Strategy Tester"

2) Click on the "Strategy Tester" icon

3) Press the key combination Ctrl + R

Settings for testing the robot on history

At this stage, you should already have a trading robot installed. You can read about how to install a trading robot.

In the tester window ("Settings" tab), you must select the test parameters:

— choose a tested adviser

— set expert properties (if necessary)

— select a symbol (currency pair)

— choose a period (timeframe)

— view symbol properties

— choose a spread

— select the period for which testing will be carried out (if the "Use date" checkbox is unchecked, then testing will be carried out on all historical data)

- select "Optimization" (if necessary)

- select the "Visualization" item (if necessary). This item will increase the testing time.

Optimization when testing a trading Expert Advisor.

This tool is designed to select the optimal parameters for maximum profit when testing a trading robot in one period of time (on the same historical data).

The optimization process consists of an automatic run various options testing. Moreover, for each such run, personal settings are selected, and as a result, the run that showed the optimal result will be selected.

Visualization when testing a trading Expert Advisor.

This tool is designed to visually represent the testing process.

If the "Visualization" checkbox is enabled, then when starting the testing process, a window with a chart will automatically open, which will display the moments of opening and closing positions by the adviser.

At the same time, you can adjust the speed of occurrence of events, stop the flow of quotes completely.

If you want to see a specific time period, you can use the "Skip until" button on the "Settings" tab of the strategy tester (the button will become available after you turn on the "Visualization" checkbox).

If the "Visualization" checkbox was turned off, the graph, however, can be viewed after testing. To do this, use the "Open chart" button of the "Settings" tab of the strategy tester.

Setting Expert Advisor Properties

Testing Tab

The "Expert properties" form is intended for setting additional testing parameters and robot settings.

1) In the "Deposit" field, you need to select the amount of the deposit.

2) In the drop-down list to the right of it, select the deposit currency.

3) Select positions that should be opened during testing (Long & Short - all transactions, Only Long - only buy orders, Only Short - only sell orders).

Setting Optimization Options

If the "Optimization" parameter was disabled in the "Strategy Tester" module,

then the optimization parameters in the expert properties can be left unchanged. Otherwise, on the Testing tab of the Expert Properties form, select the following values:

a) Optimized parameter. Usually the default value is "Balance".

b) Genetic algorithm. This option allows you to speed up the optimization procedure by using the results of previous runs. However, this method does not show the most accurate calculation results, and therefore, to obtain more accurate results, it is recommended to turn it off.

Input Parameters Tab

This tab contains the main settings that affect the operation of the Expert Advisor. Here you can also change the default settings of the robot (default values). Changed parameters can be saved to disk for further work with the same robot settings.

To restore the default values, use the "Reset" button.

If optimization is used during testing, then in order for any of the parameters to participate in this process, you must check the box next to it.

Optimization tab

This tab is for setting testing limits. If one of the parameters is checked, then the results matching the checked conditions will be rejected. Values ​​can be changed. To restore the default values, use the "Reset" button.

After setting the required settings, the "Start" button on the "Settings" tab of the strategy tester is used to start the process of testing the trading expert.

During testing, a progress bar will be displayed at the bottom of the tab showing the progress of testing.

The next article will consider.

The speedy implementation of your plans and ideas into reality,