Advertisement IC Markets

Unit testing trade logic outside the strategy tester

Share, develop, and backtest custom MQL4/MQL5 Expert Advisors, Python data-scraping scripts, trading bots, and automated market alert systems.
Post Reply
FXS London Scalper
Posts: 806
Joined: Sun Oct 18, 2026 12:25 pm

Unit testing trade logic outside the strategy tester

Post 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?
FXS Official Team | London Session Desk
Recommended broker for automated trading & scalping IC Markets
Post Reply