Runtime error
4756 ERR_ TRADE_ SEND_ FAILED
Trade request sending failed: read the retcode, not 4756
What it means
GetLastError() returns 4756 when OrderSend() did not succeed, whatever the reason. The reason is in the result: the reference's examples show "OrderSend error 4756" followed by "retcode=10018" on a closed market, and MetaQuotes' article on Market checks shows 4756 with retcode 10016 for invalid stops. The reference also warns that OrderSend() returning true "is not a sign of successful execution".
Common causes
- Any refused trade request: the specific cause is the retcode (see the codes linked below).
- Code that prints only
GetLastError()after a failed trade, so the journal shows 4756 and nothing useful. - Code that treats
OrderSend()returning true as a filled order without checkingresult.retcode.
A real scenario
A client reports "the EA gives error 4756". The EA printed only GetLastError(). With the retcode added to the log line, the same journal showed retcode 10016: the broker's stops level was larger than the EA's stop. One more field in the log turned an unexplained error into a known fix.
How to fix it
- Log
result.retcodeandresult.commentwith every failed request, together with the error code. - Check
result.retcode(andretcode_externalif needed) even whenOrderSend()returns true. - Look up the retcode in this library: each one has its own cause and fix.
Fixed MQL5 code
bool Send(MqlTradeRequest &req, MqlTradeResult &res)
{
ZeroMemory(res);
ResetLastError();
bool ok = OrderSend(req, res);
bool done = res.retcode == TRADE_RETCODE_DONE || res.retcode == TRADE_RETCODE_PLACED
|| res.retcode == TRADE_RETCODE_DONE_PARTIAL;
if(!ok || !done)
{
// GetLastError() says 4756 ("sending failed"); the reason is the server's retcode.
PrintFormat("OrderSend error %d, retcode %u, comment \"%s\" (%s %.2f lots)",
GetLastError(), res.retcode, res.comment, req.symbol, req.volume);
return false;
}
return true;
}
A focused example for MetaTrader 5: adapt names, magic number and limits to your EA, and test it on a demo account first.
Related codes
- 10016Invalid StopsTRADE_RETCODE_INVALID_STOPSInvalid stops: SL or TP too close to the price or on the wrong side
- 10018Market ClosedTRADE_RETCODE_MARKET_CLOSEDMarket is closed: the request was sent outside a trading session
- 10013Invalid RequestTRADE_RETCODE_INVALIDInvalid request: a field of the trade request is wrong or missing
EA Doctor rules that catch it
- HighOrderSend() result not checkedOrderSend() is called as a plain statement, so a refused or requoted order goes unnoticed and the EA carries on as if it traded.
- HighCTrade call result not checkedA CTrade method such as Buy(), Sell() or PositionClose() is called as a plain statement, so its failure is never seen.
- MediumPending orders judged by TRADE_RETCODE_DONE onlyThe EA places pending orders but treats every answer except TRADE_RETCODE_DONE as a failure, and an accepted pending order answers TRADE_RETCODE_PLACED.
Sources
Get your EA fixed
Still failing with 4756? Send us the EA and the journal lines: we find the cause in the code and fix it. Or check it yourself first with the EA Doctor.