Trade server return code
10006 TRADE_ RETCODE_ REJECT
Request rejected by the trade server
What it means
The trade server, or the broker's dealing system behind it, refused the request without a more specific code. Which rule refused it depends on the broker, and the comment field of MqlTradeResult usually carries the reason the server gave.
Common causes
- A broker or prop-firm rule on the server side, for example no new trades around high-impact news or a cap on orders per minute.
- A request the dealer refuses in the current market conditions, such as a very large lot on a thin symbol.
- An account state the broker restricts, for example an account under review or in margin call.
A real scenario
An EA runs on a prop-firm account whose server blocks new positions in a window around high-impact news. Every request in that window comes back as 10006. The EA only printed "OrderSend failed", so the trader thought the EA was broken; once it logged result.comment, the server's own reason was in the journal, and the EA was changed to skip that window.
How to fix it
- Log the retcode and
result.commenttogether with the symbol, volume and price of the request. - Do not resend in a loop: a rejection repeated every tick can get the account flagged. Back off for a few minutes.
- Send the journal line to the broker; only they can say which rule refused the request.
- Check the request with
OrderCheck()first, so the rejections that remain are the broker's own rules.
Fixed MQL5 code
datetime g_pauseUntil = 0;
bool SendLogged(MqlTradeRequest &req)
{
if(TimeCurrent() < g_pauseUntil)
return false; // still backing off after a rejection
MqlTradeResult res;
ZeroMemory(res);
if(OrderSend(req, res) && (res.retcode == TRADE_RETCODE_DONE || res.retcode == TRADE_RETCODE_PLACED))
return true;
PrintFormat("OrderSend %s %.2f lots at %.5f: retcode %u, comment \"%s\"",
req.symbol, req.volume, req.price, res.retcode, res.comment);
if(res.retcode == TRADE_RETCODE_REJECT)
g_pauseUntil = TimeCurrent() + 300; // do not hammer the server: wait five minutes
return false;
}
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
- 4756Trade Request Sending FailedERR_TRADE_SEND_FAILEDTrade request sending failed: read the retcode, not 4756
- 10024Too Frequent RequestsTRADE_RETCODE_TOO_MANY_REQUESTSToo frequent requests: the EA sends faster than the server allows
- 10017Trade DisabledTRADE_RETCODE_TRADE_DISABLEDTrade is disabled for the symbol or the account
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.
Sources
Get your EA fixed
Still failing with 10006? 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.