Unit Testing MQL5 Expert Advisors with Strategy Tester Suites
Summary
The document presents MQLUnit, a small framework for organizing unit tests for more complex MQL5 programs such as expert advisors. A test suite registers setup functions, individual test functions, and teardown functions, with assertions used to check expected behavior. The example tests whether data can be copied from a moving-average indicator buffer. Tests run as expert advisor scripts in the Strategy Tester, where cases can be assigned to particular chart candles and results appear in the tester journal and chart.
The proposed workflow is to compose tests around program components, prepare any shared test state, run the suite in the debugger, and repeat tests with consistent data settings after changes. This supports interface design, debugging, and regression checks during development. The document offers an implementation example and feature descriptions, but no comparative evidence that the framework improves code quality or catches particular classes of defects. It also does not discuss testing market assumptions, execution realism, or whether a trading strategy is profitable; its focus is software behavior and maintainability.
Key ideas
- MQLUnit structures tests into setup, test, and teardown functions.
- Assertions can check component behavior, with an indicator buffer copy shown as an example.
- Test suites run in the MetaTrader 5 Strategy Tester and can assign cases to chart candles.
- Repeatable test data supports regression checks after code changes.
- Unit tests check software behavior, not the profitability or realism of a trading strategy.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.