MQL4 ERR_TRADE_HEDGE_PROHIBITED
MQL4 error 149: hedging is prohibited on the account
MQL4 error 149 hedge prohibited maps to ERR_TRADE_HEDGE_PROHIBITED: an opposite order is prohibited when hedging is disabled. The account or server rules do not allow the new order to create opposite exposure on the same symbol. Capture GetLastError immediately after the failed call, correct the cause, and retry only when the condition can change.
HedgePolicyDiagnostic.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));
}