4 nuances of testing Expert Advisors in the MetaTrader 4 terminal that not all traders know about
[info_block align="right"]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 advisor on accounts from different brokers[/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.
Then select the desired currency pair and time frame, click twice on them with the left mouse button and click "Load".
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).
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"]Test by all ticks, then by reference points, then by opening prices and see the difference.[/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="Making Money with Martingale! 8 rules for trading Expert Advisors with increased risk" 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"]Making money with a Martingale Expert Advisor is possible. 8 rules on how to reduce the risk of trading a "dangerous" robot.[/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.
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.
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.
How do you eliminate this discrepancy? There is a very simple way. You need to delete the history of quotes for the desired currency pair through the "File Menu" - "Open Data Folder" - History - "Trading server name". Erase all files EURUSD*.hst.
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.
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.
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?