
An automated strategy can issue a perfectly formed order and still receive a response that prevents the intended transaction. MetaTrader 5 trade servers return numerical codes describing what happened to a request, from an invalid price to a completed partial fill. Treating every unsuccessful response as the same failure can make an Expert Advisor more dangerous than the original market signal.
For meta trader 5 developers, the distinction is operational: a return code determines whether to correct an input, wait for new conditions, inspect an existing order or stop trading. Five situations require different responses.
Invalid Stops Reveal a Contract-Specification Conflict
A server may return TRADE_RETCODE_INVALID_STOPS when requested stop-loss or take-profit levels violate the instrument’s permitted distances or other applicable rules. An EA that calculates stops solely from a chart’s price scale can overlook the broker’s current stop-level requirements.
The remedy is not to widen every stop automatically. Doing so changes the intended monetary risk. The program should retrieve the relevant symbol properties, validate the proposed levels against the correct bid or ask and decline the order when compliant protection would exceed its risk budget.
Price Changes Make Blind Resubmission Expensive
TRADE_RETCODE_REQUOTE and TRADE_RETCODE_PRICE_CHANGED can arise when the requested price is no longer acceptable under the applicable execution method. Their relevance depends on the instrument’s execution settings, so retry logic should not assume that all brokers process price requests identically.
Imagine a hypothetical platinum CFD where one lot represents 50 troy ounces. An EA requests two lots at $1,045, but the server rejects the price after the available quote moves to $1,048. Automatically resubmitting at the new price adds $3 per ounce across 100 ounces, or $300 to the entry cost. If the strategy’s original target was $1,052, its anticipated gross price gain falls from $700 to $400 before spreads and fees. A retry limit expressed in dollars can be more informative than a fixed number of attempts.
Partial Fills Leave Exposure That Still Needs Managing
TRADE_RETCODE_DONE_PARTIAL means only part of the requested volume was executed. Whether the remaining quantity stays active or is cancelled depends on the order’s filling policy and execution conditions.
A strategy expecting five contracts must not assume it holds all five after receiving this code. Nor should it automatically submit another five. Reconcile the executed deals, outstanding order quantity and current position first. The chart can show the correct entry direction while the actual portfolio remains underfilled or unexpectedly doubled.
Timeouts Do Not Prove That Nothing Happened
TRADE_RETCODE_TIMEOUT is especially awkward because the final outcome may require further investigation. A response delay does not establish that the server never processed the instruction. Sending a replacement immediately can create duplicate exposure if the first request subsequently appears in transaction history.
An EA built for meta trader 5 should retain the request details and inspect orders, deals and position changes before deciding whether another submission is justified. Where available, transaction events provide a stronger basis for reconciliation than a timer that merely waits several seconds.
Insufficient Funds Require a New Position Decision
TRADE_RETCODE_NO_MONEY indicates that the requested operation cannot proceed with the available funds under the server’s checks. Existing exposure, changing margin requirements or a larger-than-expected contract value may explain the refusal.
Repeatedly sending the identical volume cannot repair a funding shortfall. The program should recalculate affordable size, respect minimum volume increments and check whether reducing quantity would still meet the strategy’s intended risk profile. Before opening a CFD position, test the EA with deliberate invalid-stop, price-change and partial-fill conditions, and require every server response to reconcile against actual orders and positions before another request is sent.
