Handling partially filled orders in MQL5 code
Posted: Wed Oct 28, 2026 10:18 pm
Partial fills are rare on retail FX accounts, but they do happen, mostly with larger limit orders or on less liquid symbols. My EA didn't handle them, and I found out when a 2 lot limit on gold filled 1.4 lots and the EA treated the position as complete.
What I changed:
On netting accounts it's even messier, since a partial fill gets merged into an existing position.
Has anyone else had to deal with this? I'd like to know if some brokers partially fill market orders too, or only limits.
What I changed:
- In OnTradeTransaction, I check the deal volume against the order's requested volume, not just whether a deal happened.
- If the order is still active with remaining volume, the EA waits up to a set time, then cancels the rest.
- Stop and target are sized for the actual position volume, not the requested one. That matters for any logic that closes part of a position.
- The CSV log records requested and filled volume separately.
On netting accounts it's even messier, since a partial fill gets merged into an existing position.
Has anyone else had to deal with this? I'd like to know if some brokers partially fill market orders too, or only limits.