Skip to content

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 checking result.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

  1. Log result.retcode and result.comment with every failed request, together with the error code.
  2. Check result.retcode (and retcode_external if needed) even when OrderSend() returns true.
  3. Look up the retcode in this library: each one has its own cause and fix.

Fixed MQL5 code

MQL5
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.

EA Doctor rules that catch it

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.