Building a Fast Custom Strategy Tester with MetaTrader 5 Math Mode
Summary
The article explains how to build a self-contained strategy tester around MetaTrader 5’s math calculations mode. This mode runs an expert’s OnTester function without normal trading environment access, reducing overhead while retaining optimization features such as genetic search, cloud agents, and custom results. The proposed tester stores compressed historical bars inside the expert, reconstructs them for simulation, and adds virtual positions, trade management, and result analysis.
The article walks through a moving average strategy prototype, custom optimization output, and a strategy analyzer that can receive saved position histories through tester frames. These examples illustrate how optimization can test simplified trading ideas and aggregate custom reports. The approach is aimed at fast approximate research, including calculations that omit spread, commission, or slippage. It requires substantial implementation work and does not reproduce realistic execution by default. The author identifies missing symbol and strategy metadata, controls against future data leakage, and fuller reporting as important areas for further development.
Key ideas
- Math calculations mode can run self-contained simulations through OnTester with low tester overhead.
- Historical bar data can be compressed into a byte array and embedded with the testing expert.
- A custom tester needs virtual position management and a system for analyzing results.
- Tester frames can carry optimization results and position histories into a separate analyzer.
- The prototype omits realistic costs and needs safeguards against future data leakage.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.