Unit testing the boring bits of your EA before they touch money
Posted: Thu Oct 15, 2026 8:46 pm
Unit testing the boring bits of your EA before they touch money
Most EA bugs I've seen weren't in the clever part. They were in the plumbing. Lot size rounding, pip size on JPY pairs vs everything else, a stop calculated on the wrong side for shorts, a session check that breaks across midnight.
These are exactly the kind of things you can test without the market. Pull the helper functions out so they take inputs and return outputs, then feed them known cases and check the answers. Lot size for a given balance, risk and stop on EURUSD, USDJPY and gold. Stop price for a long and a short. Session check at 23:59 and 00:01. That sort of thing.
In MQL it's a bit clunky, there's no proper test framework built in, but a script that calls your functions with fixed inputs and prints pass or fail does the job. In Python it's easy with pytest.
I'd add a test every time you find a bug. Then that bug can't quietly come back after you change something else.
It sounds like overkill for a small EA. It isn't, honestly. The stuff that blows up accounts is usually one wrong sign or one wrong multiplier, and tests catch those in seconds.
Most EA bugs I've seen weren't in the clever part. They were in the plumbing. Lot size rounding, pip size on JPY pairs vs everything else, a stop calculated on the wrong side for shorts, a session check that breaks across midnight.
These are exactly the kind of things you can test without the market. Pull the helper functions out so they take inputs and return outputs, then feed them known cases and check the answers. Lot size for a given balance, risk and stop on EURUSD, USDJPY and gold. Stop price for a long and a short. Session check at 23:59 and 00:01. That sort of thing.
In MQL it's a bit clunky, there's no proper test framework built in, but a script that calls your functions with fixed inputs and prints pass or fail does the job. In Python it's easy with pytest.
I'd add a test every time you find a bug. Then that bug can't quietly come back after you change something else.
It sounds like overkill for a small EA. It isn't, honestly. The stuff that blows up accounts is usually one wrong sign or one wrong multiplier, and tests catch those in seconds.