Modify Order Close procedure

 

Hello folks,

I have a code to close orders:

      TotalOrders = OrdersTotal();
      for(int i=TotalOrders-1;i>=0;i--)
         {
         OrderSelect(i, SELECT_BY_POS);
         if(OrderSymbol() != Symbol()) continue;
         
         bool test = true;
         int type   = OrderType();
         bool result = false;
         
        
          switch(type)
            {
            case OP_BUY:
            case OP_SELL  : result = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 5,CLR_NONE);
            break;
            case OP_BUYLIMIT:
            case OP_BUYSTOP:
            case OP_SELLLIMIT:
            case OP_SELLSTOP: result = OrderDelete( OrderTicket() );
            break;
            }
     
         if(result == false)
            {
            Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );
            Sleep(3000);
            }  
         }


I would like to execute this code only on tickets where the following condition is met:

if (OrderOpenTime() + 7200 < ClosingTime) 

I just don't know where and how to insert the additional code to make it work as I need it.


I'd appreciate some help.

Thanks. WorstCases

 

you can add more code after a case using following syntax:

switch(type){
  case 1: {

   break;
  }
  case 2: {

   break;
  }

}
i am not shure about mql but in other languages the break; is not optional. Instead if not used also the code in the following cases will be executed without checking the case again.
 
Got it. Thanks for the help!
Reason: