Operation of Programs in the Strategy Tester
The Strategy Tester in MetaTrader 4 trading terminal allows you to test Expert Advisor's performance on historical data.
The features of program testing and optimization in the Strategy Tester should be considered when testing a trading robot:
There are operation limitations for some functions in the client terminal's Strategy Tester. Calling that functions leads to error 4059 (Function is not allowed in testing mode).
The Sleep() function does not cause any delays in the Strategy Tester.
To increase performance, Print() and PrintFormat() functions are not executed when optimizing the trading robot's parameters. The exception is the use of these functions inside the OnInit() handler. This allows you to easily find the cause of errors when they occur.
The Alert(), MessageBox(), PlaySound(), SendFTP, SendMail(), SendNotification(), WebRequest() Functions
Trade operations are not performed on the symbols that are different from the tested one.
Since the tester is the part of the client terminal, they share the common global variables. Thus, their names should not overlap with the names of the global variables of working applications. This may lead to incorrect operation of programs and inaccurate test results.
When testing, the time is simulated according to the historical data. TimeLocal() local time is always equal to TimeCurrent() server time. In turn, the server time is always equal to the time corresponding to the GMT - TimeGMT(). This way, all of these functions display the same time during testing.
The absence of the difference between GMT, local and server time in the tester is provided deliberately in case connection to the server is lost. The test results should always be the same, regardless of whether or not there is a connection. Information about the server time is not stored locally, and is taken from the server.
During visualization, the Expert Advisor interacts with a real chart. In case there is no visualization, the Expert Advisor works with a "virtual" chart that is not displayed. The former case has some peculiarities. During optimization, working with graphical objects is not supported.
The following events are handled in the Strategy Tester: initializing an Expert Advisor before a single run of OnInit(), deinitializing an Expert Advisor after a single run of OnDeInit() and simulating a new tick OnTick().
In addition, Tester event handled in OnTester() function is generated before calling OnDeInit() deinitialization function after testing a trading robot on historical data. The value returned by this function is used as a Custom max criterion when optimizing the input parameters.