why do i get ordersend error 148 ??

 
//--- * short trade 




if  (trade_ok==true)

{

if ( ( Ask- SMA_10day  < buffer*Point*K ) && ( price_above==true))      
  
  {  
     ticket1=-1;
     ticket2=-1;
     while (MarketInfo(Symbol(),MODE_ASK)-MarketInfo(Symbol(),MODE_BID)<4*Point*K)  // spread < 4
     {
     Alert(MarketInfo(Symbol(),MODE_ASK)-MarketInfo(Symbol(),MODE_BID));
     RefreshRates();
     ticket1 = OrderSend(Symbol() , OP_SELL , 0.01*M , Bid , 3 , Ask+stoploss*Point*K , Ask-takeprofit*Point*K); 
     Sleep(2000);
     if (ticket1>0)  
     break;
     }
     
     if (AccountBalance()/max_account_balance>0.9) // no 10% drawdown
     {
     while (MarketInfo(Symbol(),MODE_ASK)-MarketInfo(Symbol(),MODE_BID)<4*Point*K) //spread < 4
     {
     Alert(MarketInfo(Symbol(),MODE_ASK)-MarketInfo(Symbol(),MODE_BID));
     RefreshRates();
     ticket2 = OrderSend(Symbol() , OP_SELL , 0.01*M , Bid , 5 , Ask+stoploss*9*Point*K , Ask-takeprofit*Point*K); 
     Sleep(2000);
     if (ticket2>0)  
     {
     entryprice=Ask;
     break;
     } 
     }
     }
trade_ok=false; 

  }
  
    //--- * end of short trade
     
     else 
     
       
//--- * long trade

if ( ( SMA_10day -  Bid < buffer*Point*K ) && (price_above==false))      
  
  {   
     ticket1=-1; 
     ticket2=-1;
     while (MarketInfo(Symbol(),MODE_ASK)-MarketInfo(Symbol(),MODE_BID)<4*Point*K) //spread < 4
     {
     Alert(MarketInfo(Symbol(),MODE_ASK)-MarketInfo(Symbol(),MODE_BID));
     RefreshRates();     
     ticket1 = OrderSend(Symbol() , OP_BUY , 0.01*M , Ask , 2 , Bid-stoploss*Point*K , Bid+takeprofit*Point*K);
     Sleep(2000);
     if (ticket1>0)
     break;
     } 
     if (AccountBalance()/max_account_balance>0.9) // no 10% drawdown
     {
     while (MarketInfo(Symbol(),MODE_ASK)-MarketInfo(Symbol(),MODE_BID)<4*Point*K) //spread < 4
     {
     Alert(MarketInfo(Symbol(),MODE_ASK)-MarketInfo(Symbol(),MODE_BID));
     RefreshRates();
     ticket2 = OrderSend(Symbol() , OP_BUY , 0.01*M , Ask , 3 , Bid-stoploss*9*Point*K , Bid+takeprofit*Point*K);
     Sleep(2000);
     
     if (ticket2>0)
     {
       entryprice=Bid;
       break;
     }
     }
     }
     trade_ok=false;    
  }

I seem to get Ordersend error 148

can anyone tell why ?

thanks

 
sergeyrar:

I seem to get Ordersend error 148

can anyone tell why ?

thanks


P.S - without the condition : " if (AccountBalance()/max_account_balance>0.9) " it works fine
 

nevermind I solved it.

 
How did you solved it Serge?
 

Presumably by restricting the number of orders. This is a limit set by your broker:

148

ERR_TRADE_TOO_MANY_ORDERS

The amount of open and pending orders has reached the limit set by the broker

 
bool IsNewOrderAllowed()
  {
//--- get the number of pending orders allowed on the account
   int max_allowed_orders=(int)AccountInfoInteger(ACCOUNT_LIMIT_ORDERS);

//--- if there is no limitation, return true; you can send an order
   if(max_allowed_orders==0) return(true);

//--- if we passed to this line, then there is a limitation; find out how many orders are already placed
   int orders=OrdersTotal();

//--- return the result of comparing
   return(orders<max_allowed_orders);
  }
  

This code check orders

 
if ( ( Ask- SMA_10day  < buffer*Point*K ) && ( price_above==true))  

You are looking at a signal (opening one order per tick). Act on a change of signal.
          Too many orders - MQL4 programming forum #1 (2017)

Reason: