XAGUSD EA: unit-testing the order-send wrapper before going live
Posted: Wed Oct 28, 2026 8:28 pm
Building a small silver scalping EA, I learned the hard way that the trading logic is often fine while the order-sending code fails in ways the backtester never shows.
So before anything goes live I now test the order wrapper on its own, separately from the strategy. The wrapper is one function that takes direction, volume, stop, target and returns a result code.
Tests I run on a demo account:
It took an afternoon. It also caught two bugs: a rounding error that produced invalid stop prices on XAGUSD, and a retry loop that would have spammed the server.
Does anyone use a proper testing framework for MQL5, or is everyone doing manual demo tests like me?
So before anything goes live I now test the order wrapper on its own, separately from the strategy. The wrapper is one function that takes direction, volume, stop, target and returns a result code.
Tests I run on a demo account:
- Volume normalisation: does 0.013 become 0.01 (or rejected) according to the symbol's volume step?
- Stop and target too close: does it respect the stops level, adjust, or refuse cleanly?
- Price normalisation to tick size. Silver has its own digits.
- Requote and off-quotes: does it retry with a fresh price, and how many times?
- Market closed: does it log and stop, or loop endlessly?
- Insufficient margin: does it reduce size or abort?
It took an afternoon. It also caught two bugs: a rounding error that produced invalid stop prices on XAGUSD, and a retry loop that would have spammed the server.
Does anyone use a proper testing framework for MQL5, or is everyone doing manual demo tests like me?