I need answer please !

 

I have a pending order, and I want to check if it's opened or not, for the reason to delete an other one.

I tryed to use the fact that OrderType() change value when Order is open from OP_BUYLIMIT ( for example ) to OP_BUY but this is not working, it chang value only if the oreder is closed by stoploss or takeprofit.

if any one coulde helpe me i woud be thankful. 

 

PS : this is for mql4. Thanks ! 

 
Yassine: I tryed to use the fact that OrderType() change value when Order is open from OP_BUYLIMIT ( for example ) to OP_BUY but this is not working,
We can't see your broken code
 

Count all types of orders.

int buys_,sells_,buys_S,sells_S,buys_L,sells_L,Orders_Total;
...
////////////////////////////////////////////////////////////////////////////////////
void CountOpenedPositions_f()
{
buys_=0;
sells_=0;
  buys_S=0;
sells_S=0;
  buys_L=0;
sells_L=0;
Orders_Total=0;


for (int i=OrdersTotal()-1; i>=0; i--)
{
   if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
   if(OrderMagicNumber()!=Magic || OrderSymbol()!=Symbol()) continue;
      
     int type=OrderType();
    
   if(type==OP_BUY)      buys_++;
    else
   if(type==OP_SELL)     sells_++;
    else
   if(type==OP_BUYSTOP)      buys_S++;
    else
   if(type==OP_SELLSTOP)     sells_S++;
    else
   if(type==OP_BUYLIMIT)      buys_L++;
    else
   if(type==OP_SELLLIMIT)     sells_L++;
}

Orders_Total=buys_+sells_+buys_S+sells_S+buys_L+sells_L;
}


 Than(for example)

if(buys_>buys_S) delete sellStop 

Reason: