An EA can print "order sent" and still have no position. That line usually proves only that the code reached its send branch. It does not settle what the server accepted or what the account holds now.
An Expert Advisor (EA) is a program that applies trading rules in MetaTrader 5. When it makes an order request, I keep three observations separate:
- Request: symbol, side, volume, intended order type and a local request ID.
- Result: the server return code (retcode), order/deal IDs if present, and the server's comment.
- Account state: the actual position on the intended symbol, matched by magic number or another agreed ownership key.
The MQL5 OrderSend() reference is explicit: a true return does not prove execution. It does not replace the retcode check. A successful result is still not a reason to infer the final position from the request alone. Query the account state and compare it with the intended transition. The PositionSelect() reference also says to select again before reading position fields, because earlier copied data may be stale.
For a reversal from SELL to BUY, the check has two parts: the old owned SELL is gone, and the new owned BUY exists at the expected volume. A log line for the BUY request cannot prove either part by itself.
Three acceptance cases
| Case | Request and result | Position check | Expected outcome |
|---|---|---|---|
| Normal entry | BUY request accepted | One owned BUY exists | Record the new position and its ticket |
| Rejection | BUY request rejected, with the actual return code | No new owned BUY | Preserve the error and do not mark an entry |
| Reversal | Owned SELL close accepted, then BUY accepted | SELL absent and BUY present | Mark reversal complete only after both checks |
There is a fourth useful edge case: the request times out or its result is uncertain. Blindly sending the same request again can create a duplicate if the first one eventually completed. Reconcile recent orders, deals and positions before retrying. Keep the original request ID in the trace so a second attempt can be related to the first.
I used this split in a small HolaPrime MT5 tester fixture. Its log records accepted test orders and a separate own-position check. That is evidence for those bounded test cases, not a claim about live fills or trading results.
The debugging question is simple: What did I request, what did the server return, and what position exists now? If those three facts are recorded separately, the first failing transition becomes visible.
Top comments (0)