Download MetaTrader 5

why this code isn't working?

To add comments, please log in or register
shermilden5000
46
shermilden5000  

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;
           }
                                
  }
           
     }
         
   }
  
  
  
 } 


whroeder1
15902
whroeder1  
  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.)
Keith Watford
Moderator
10652
Keith Watford  
 for (int i = OrdersTotal()-1; i > 0; i--)

change to

 for (int i = OrdersTotal()-1; i >= 0; i--)
To add comments, please log in or register