4 nuances of testing Expert Advisors in the MetaTrader 4 terminal that not all traders know about

[info_block align=”right”]Обратите внимание, что качество истории котировок у разных брокеров отличаются, что может вызвать серьезные расхождения в результатах тестирования одного советника на счетах от разных брокеров[/info_block]

In today's trading environment, the use of Advisors It's no longer an exotic experience. Almost every day new free and paid trading robots appear, which impress with their profitability and make you want to make a quick profit. However, putting an Expert Advisor into a trading account without testing is a dubious venture that leads to "unexpected" losses in potential. Therefore, we recommend you to start working with the robot with testing.

All you need to know about how to properly test a trading advisor in the strategy tester of the MetaTrader 4 terminal - in the instructions from the experts of Fortrader magazine.

How do I start testing an Expert Advisor?

The trading robot is checked on the history, so first of all it is necessary to download the quotes of the currency pair you need. For this purpose it is necessary in the menu "Service" to find a tab "Archive of quotations" or simply to press key F2.

Fig. 1. Quotes archive in the "Tools" menu of the MetaTrader 4 terminal.
Fig. 1. Quotes archive in the "Tools" menu of the MetaTrader 4 terminal.

Then select the desired currency pair and time frame, click twice on them with the left mouse button and click "Load".

Fig. 2. Selecting a currency pair and a timeframe.
Fig. 2. Selecting a currency pair and a timeframe.

Please note that the quality of quotes history varies from broker to broker, which can cause serious discrepancies in the results of testing the same Expert Advisor on accounts from different brokers.

In the strategy tester, select the trading robot (1), the currency pair (2), the type of simulation (3), the time frame (4), the spread (5) and the settings of the Expert Advisor (6).

Fig. 3. Setting up the Strategy Tester for testing.
Fig. 3. Setting up the Strategy Tester for testing.

Do not forget about the spread, which is set for the currency pair by your broker. The thing is that in the strategy tester the current spread is set by default. spread. If you don't, you can get absolutely fantastic results, especially if you test the expert on a day off.

What type of modeling should I choose?

[info_block align=”right”]Тестируете по всем тикам, потом по контрольным точкам, потом по ценам открытия и смотрите разницу.[/info_block]

The Strategy Tester offers three types of simulation to choose from:

  • All tics;
  • Checkpoints;
  • On opening prices.

"All ticks." - is the most accurate of the standard types of modeling available, but it is also the longest. Some Expert Advisors can be tested without loss of accuracy by control points or by opening prices. To do this, the algorithm must contain conditions for opening a deal, starting from a new bar.

If you do not know much about the Expert Advisor you are testing, then it makes sense to approach the question in an experimental way. You test by all ticks, then by check points, then by open prices and see the difference. If the difference is small, then you can optimize the Expert Advisor by the fastest method and then check it on all ticks. If the difference is considerable, the coarse optimization can be carried out by the fast method, and the fine one - by all ticks. If the difference is quite big, there is nothing to do and you have to optimize long and persistently by all ticks.

There is a class of advisors in which The working timeframe is prescribed in the settingsThe test results do not depend on the period selected in the tester. Such robots, as a rule, can be tested almost without loss of accuracy on control points. It turns out much faster than on all ticks, and the result is almost the same.

Again, we optimize by the fast method, check the best variant by all ticks and make sure everything is OK.

What parameters should be paid attention to when optimizing an Expert Advisor?

Number of transactions

First of all we pay attention to the number of deals. It is desirable to have at least 150, otherwise the optimization is meaningless, because there is an effect of "fitting" the results.

If the trades are less than 150, it is necessary to increase the period of testing to get a complete picture.

Profit and drawdown

[info_block align=”right” linkText=”Зарабатываем с Мартингейлом! 8 правил торговли экспертами с повышенным риском” linkUrl=”https://mr-trader.com/learn/forex-trader/zarabatyvaem-s-martingejlom-8-pravil-torgovli-foreks-ekspertami-s-povyshennym-riskom” imageUrl=”http://files.fortrader.org/uploads/2016/11/invest-money.jpg”]Заработок на советнике по принципу Мартингейла возможен. 8 правил о том, как снизить риск от торговли “опасным” роботом.[/info_block]

Secondly, we will be interested in the ratio of profit to drawdown.

A popular parameter for selecting results optimization is the recovery factor, which is a simple ratio: profit / maximum drawdown. It is easy to calculate by dividing the "Profit" column by the "Drawdown" column in dollars. But the tester does not allow to sort the optimization results by this parameter.

Fortunately, it is not difficult to fix, if you have access to the source code of the Expert Advisor. Just add the following lines to the end of the code of any robot:

double GetRecoveryFactor( void ) {

  double Res = 0;

  double MaxDD = TesterStatistics(STAT_EQUITY_DD);

  if (MaxDD != 0)

      Res = TesterStatistics(STAT_PROFIT) / MaxDD;

  return(Res);

}

double OnTester( void ) {

  return(GetRecoveryFactor());

}

and recompile it. After that, a new column "Result OnTester" will appear in the tester during optimization. It will contain the recovery factor. By clicking on the header of this column, you can sort the optimization results by this parameter.

Fig. 4. Sorting optimization results by recovery factor.
Fig. 4. Sorting optimization results by recovery factor.

What to do with mismatch errors?

It often happens that in the test report of the trading Expert Advisor, the strategy tester indicates n/a value in the "Modeling quality" line and reports errors of chart mismatch.

Fig. 5. Errors of graph mismatch.
Fig. 5. Errors of graph mismatch.

Where do these errors come from? The most common reason is the discrepancy between the quotes received from the broker directly and the quotes downloaded from the archive.

Как устранить это расхождение? Существует очень простой способ. Необходимо удалить историю котировок по необходимой валютной паре через  «Меню Файл» – «Открыть каталог данных» – History – «Имя торгового сервера». Стираем все файлы EURUSD*.hst.

Fig. 6. Deleting the file with the archive of quotes.
Fig. 6. Deleting the file with the archive of quotes.

After deleting the files, restart the terminal and reload the quotes, as described above.

After these procedures, in most cases, the mismatch errors will disappear and the simulation quality will increase to 90%.

Total

So, testing and optimizing trading Expert Advisors is not difficult at all, although it requires a lot of time and knowledge of subtleties. We hope that this article will allow you to be "on your own" with strategy tester, effectively test Expert Advisors and make profit on the foreign exchange market.

Related articles

Комментарии ( 2 )

  1. Hello! Thank you for the information about the tick test of the robot. However, I have a question. If I downloaded ticks from the MQL4 quotes archive and performed a test in H1 (hourly) timeframe, would the bar open time be different from the broker's server time? This is important for me to know, as the order opening in my robot is tied to the bar opening time and to the start time of the trading session.
    Thank you in advance if I can get some clarification on my question.
    PS: maybe you have a description of the code that can be put in the body of the EA to fix the problem, if it certainly exists.

  2. Is it okay that the quotes after deletion will be downloaded from the methaquot server and will be very different from the data obtained from the broker and after the re-fill this tester can safely be thrown in the trash?

Leave a Reply

Back to top button