why this code isn't working?

 

I want to check if total orders are not zero, then,

if buy order exists, I want to set the variable "buy_order_exists" to "1"

if sell order exists, I want to set the variable "sell_order_exists" to "1"

But my code doesn't update the variables when the orders are exist. 



 if (OrdersTotal () != 0)
 {

 for (int i = OrdersTotal()-1; i > 0; i--)
  {
      if ( OrderSelect(i, SELECT_BY_POS) )
     {
     
    
          if (OrderSymbol() == Symbol())
     {
        if (OrderType() == OP_BUY)
          {
           buy_order_exists = 1;
           }
           
        if (OrderType() == OP_SELL)
          {
           sell_order_exists = 1;
           }
                                
  }
           
     }
         
   }
  
  
  
 } 


 
  1. Nothing wrong with the code you posted. Oops, I missed the missing equals.
  2.  if (OrdersTotal () != 0){
    Unnecessary. If it's zero the for loop does nothing.
  3. buy_order_exists = 1;
    Don't use int and zero/one when you mean bool and true/false.
  4. no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
 
 for (int i = OrdersTotal()-1; i > 0; i--)

change to

 for (int i = OrdersTotal()-1; i >= 0; i--)