TesterBenchmark - MetaTrader 5 Library | MT5 EA Download - MetaTrader 5 Resources
When writing different code versions, you may want to measure their impact on the overall performance of the Expert Advisor in the tester. This allows you to understand how optimal the code is compared to other programs and provides prerequisites for further rapid optimization of Expert Advisors. This approach allows us to identify the "bottleneck" in the EA performance.
The MetaTrader 5 provides an excellent function for profiling Expert Advisors on historical data. But it has some disadvantages: it is slow (in visual mode) and the final results are presented in relative units, i.e. performance cannot be compared in absolute values.
Furthermore, in MetaTrader 5, the EA is executed on the local broker even during a single run without visualization. Sometimes it takes a large part of the test time to synchronize the terminal with the corresponding local agent. Therefore, the time data for the following rows
Core 1 EURUSD, M1: 3387955 ticks, 52608 generated bar chart. Environment sync at 0 : 00 : 01.389 . Test passed at 0 : 00 : 09.422 (including scale preprocessing 0 : 00 : 00.187 ). Core 1 EURUSD,M1: Total time from login to stop test 0 : 00 : 10.811 (including 0 : 00 : 01.389 for historical data synchronization)
The net performance of the EA/tester is not a good representation and can vary significantly from run to run.
The net running time of the strategy tester is the time from the first Tick event (first OnTick) to the last Tick in the test interval. Immediately after this interval, the tester calls OnTester (and subsequently OnDeinit).
The library allows to add a line to the EA code
#include
And get data about the net performance of the tester in the log.
Core 1 2017.07 . 21 23:59:59 Interval = 8.842 s ., Count = 3387955 , 383166.1 units/second Core 1 EURUSD, M1: 3387955 ticks, 52608 generated bar chart. Environment sync at 0 : 00 : 01.389 . Test passed at 0 : 00 : 09.422 (including scale preprocessing 0 : 00 : 00.187 ). Core 1 EURUSD,M1: Total time from login to stop test 0 : 00 : 10.811 (including 0 : 00 : 01.389 for historical data synchronization)
Furthermore, if you switch from single run to optimization mode in the tester (without specifying the optimization range for MetaTrader 5), the library will run the EA the specified number of times and generate tester performance statistics, from which you can understand the pure performance of the tester.
------ Tester initialization i= 0 Pass= 0 Tester = 8.687 s.: Count= 3387955 , 390002.9 units/second, Agent=C:\Program Files\Alpari Limited MT5\Tester\Agent- 127.0 . 0.1 - 3000i = 1 pass = 1 tester = 8.702 s.: Count = 3387955 , 389330.6 units/second, Agent = C:\Program Files\Alpari Limited MT5\Tester\Agent- 127.0 . 0.1 - 3000 iMin = 0 Result[iMin] = 8.687 s. Max = 1 Result[iMax] = 8.702 s. amount = 2 average = 8.694 s. - 83.89 % OnTesterDeinit ------ Interval = 20.729 s., Count = 0 , 0.0 units/second
In this case, it is clear that there are two starts on the same local agent. Shows minimum, maximum and average calculation times. The total time for optimization (interval) is also shown. The percentage feature (83.89%) shows how much of the total optimizer time is taken up on average by pure operations of the tester (taking into account the time required to synchronize with the agent).
Add another line
#Define PROFILER_OnTick // Measure the net time of all OnTick executions, may slightly slow down the overall operation #include
You can see the time spent executing OnTick, regardless of the time spent on simulated trading environment, performance, etc.
------ Tester initialization i= 0 Pass= 0 Tester = 9.540s : Profiler checked : Count= 3387955 , Interval= 8.079 s., 419359.4 units/sec , Agent=C:\Program Files\Alpari Limited MT5\Tester\Agent- 127.0 . 0.1 - 3000 i = 1 pass = 1 tester = 9.471 s: Tick profiler: count = 3387955 , interval = 8.029 s, 421956.9 units/second , agent = C:\Program Files\Alpari Limited MT5\Tester\Agent- 127.0 . 0.1 - 3000 iMin = 1 Result[iMin] = 9.471 s. Max = 0 Result[iMax] = 9.540 s. Amount = 2 Average = 9.505 s. - 98.86 % OnTesterDeinit ------ Interval = 19.231 s., Count = 0 , 0.0 units/second
The library provides a sample EA (MQL4/5) with headers, which helps to understand one of the practical applications of the library.
Attachment download
📎 testerbenchmark.mqh (5.17 KB)
📎 testerbenchmark_example.mq5 (5.29 KB)
Source: MQL5 #18804
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •