Profiling MQL5 Expert Advisors and Unit Testing Trading Rules
Summary
This article presents two lightweight diagnostics for MQL5 projects: a profiler that records timing for named code sections and a small assertion-based test harness for pure trading calculations. The profiler aggregates call counts and elapsed time, including minimum, maximum, average, and slow-call counts, then writes a CSV report for comparison. The test harness checks functions such as point conversion, volume normalization, stop validation, and signal classification against fixed expected results.
The recommended workflow keeps platform-dependent work in the EA, extracts deterministic calculations into testable functions, runs those tests, and profiles event-driven paths in the Strategy Tester. Logs, tests, and timings answer different questions, so the article recommends retaining baseline reports and repeating the same checks after changes. Its examples are diagnostic scaffolding, not a trading strategy; passing tests cover only selected cases, and stable timings do not establish market performance. Broader coverage is needed for areas such as spread filters, risk sizing, and multi-symbol processing.
Key ideas
- A profiler can measure named code sections and export aggregated timings to CSV.
- A unit-test harness can check deterministic trading calculations with repeatable inputs and expected outputs.
- Platform-dependent operations belong in the EA, while pure rules are easier to test in isolated functions.
- Logging, profiling, and unit testing provide observation, performance measurement, and correctness checks respectively.
- Saved baseline reports enable comparison after changes, but neither passing tests nor stable timings prove profitability.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.