Page 1 of 1

Unit testing trade logic outside the strategy tester

Posted: Sat Oct 31, 2026 1:56 pm
by FXS London Scalper
The strategy tester is useful but slow for checking small pieces of logic. Testing functions in isolation catches bugs faster.

Good candidates for unit tests:
  • Position size calculation, with edge cases: very small balance, minimum lot, volume step, metals.
  • Pip size and point conversions for 2, 3, 4 and 5 digit symbols.
  • Time filter logic around clock changes.
  • Stop distance validation against stop level.
How to do it in MQL5: write a script that calls the function with known inputs and compares the output with expected values, printing pass or fail. Keep the functions in an include file shared by the EA and the test script.

Example test case: balance 2,000, risk 1%, stop 7 pips, EURUSD, volume step 0.01. Expected lots around 0.28 to 0.31, depending on the exchange rate.

Run the tests after every change to the include file.

Over time, a small test suite becomes a safety net that makes changes less risky, especially when the code is shared between several EAs.

Does anyone write tests for their MQL code?