counting buy oeders

 

Hello everyone.

I am trying to close remaining pending orders when OP_BUY==0

void Check3()
{

bool result;
int cmd,error;
int OpenBuyOrders=0;



cmd=OrderType();

int total = OrdersTotal();

  for (int i5 = OrdersTotal() - 1; i5 >= 0 ; i5--)
{
    if((OrderSelect(i5,SELECT_BY_POS,MODE_TRADES))&&OrdersTotal()<14 )
{
//+------------------------------------------------------------------+
if (OrderType()==OP_BUY) OpenBuyOrders++ ;
if (OpenBuyOrders==0)
{

     
if((OrderType()==OP_SELLLIMIT) || (OrderType()==OP_BUYSTOP))
{
      while(true)
    {
           result=OrderDelete(OrderTicket());
           
      if(result!=TRUE) { error=GetLastError(); Alert("LastError = ",error); }
      else break;
    }
}



}
//+------------------------------------------------------------------+


//+------------------------------------------------------------------+
}
else { Print( "Error when order select ", GetLastError()); break; }
}

}

using that code but it dose not work and closes orders when op buy is greater than 0. could someone help me on that.

 
rafal85: I am trying to close remaining pending orders when OP_BUY==0
  1. OP_BUY is defined as zero. OP_BUY==0 will always be true.
  2. if (OrderType()==OP_BUY) OpenBuyOrders++ ;
    if (OpenBuyOrders==0){
         if((OrderType()==OP_SELLLIMIT) || (OrderType()==OP_BUYSTOP))
    You need to loop through all orders and then if there is an open buy, loop and close all pendings. Code as written only works when the buy is in the highest order position.