MQL4 ERR_TRADE_TOO_MANY_ORDERS
MQL4 error 148: respect the broker order limit
MQL4 error 148 too many orders maps to ERR_TRADE_TOO_MANY_ORDERS: the amount of opened and pending orders has reached a broker limit. The server rejected a new order because existing market and pending orders already reached its configured limit. Capture GetLastError immediately after the failed call, correct the cause, and retry only when the condition can change.
Open the Coding Agent, then choose MQL4 from the language menu.
OrderLimitDiagnostic.mq4.mq4
#property strict
#property script_show_inputs
input double Lots = 0.10;
input int Slippage = 3;
void OnStart()
{
if(!IsTradeAllowed())
{
Print("Trading is not currently allowed or the trade context is busy.");
return;
}
RefreshRates();
double price = NormalizeDouble(Ask, Digits);
ResetLastError();
int ticket = OrderSend(Symbol(), OP_BUY, Lots, price, Slippage,
0, 0, "diagnostic", 0, 0, clrNONE);
if(ticket >= 0)
{
Print("Order opened. Ticket ", ticket);
return;
}
int error_code = GetLastError();
Print("OrderSend failed. error=", error_code,
" symbol=", Symbol(), " lots=", DoubleToString(Lots, 2),
" ask=", DoubleToString(price, Digits));
}