Here is a production-grade asynchronous trade executor class (CAsyncTradeExecutor) that dispatches orders without blocking and tracks them via request IDs and trade transactions:
To hook the asynchronous executor into your main EA structure, wire HandleTransaction directly into the terminal's global OnTradeTransaction event listener:
Race Conditions in Multi-Symbol EAs: Because OnTradeTransaction is asynchronous, your transaction handler may fire milliseconds or seconds later while your EA is already processing ticks for a completely different symbol. Ensure your data structures and position-state variables are thread-safe or properly locked/synchronized.
Request ID Correlation: Always capture result.request_id upon dispatch. When OnTradeTransaction triggers TRADE_TRANSACTION_REQUEST, match the incoming ID against your internal state machine to verify whether your limit order was successfully placed or rejected.
Queue Overflows: Avoid flooding OrderSendAsync() in a tight loop without rate-limiting; if you push hundreds of requests per second faster than the terminal's IPC queue can process them, the terminal will return trade queue congestion errors.
Preserve your own money. Scale with the market's money. Exponential growth is the ultimate key.
Good topic, and it's one of those costs that hides in plain sight because each individual instance looks tiny. Half a pip of slippage doesn't feel like much until you multiply it by a few hundred trades a month on a strategy whose average winner is only four or five pips.
One practical point to add for people who don't code EAs: you can measure your own slippage without any special tools. Most platforms record the requested price and the filled price, or at least you can note the price on the screen when you click and compare it with the fill in the history. Do that for a few weeks and split it by time of day. It's common to find that slippage is close to zero in the middle of the London session and noticeably worse around the open, the close and news, which is useful information in itself because it tells you which hours your edge is actually paying for.
The other thing worth checking is whether slippage is symmetrical. On a fair execution it should sometimes go in your favour as well. If every single deviation is against you, that's a question to ask the broker, and it matters more than the advertised spread.
For backtesting, adding a fixed slippage figure per trade is a decent start, but a better approach is to add it as a random value within a range that matches what you've actually measured, and to make it larger in the minutes around scheduled news. If the strategy's results collapse with a realistic slippage model, it's better to find that out in the tester than on a live account.