Need Help with OrderSelect function.

 

Hi guys, The function works well with just one symbol but once adding the EA to more than one, the function becomes unable to select the pending order to be deleted.

I can't find the problem why it doesn't work with more than one symbol.

Thank you.

void PODelete()
   
      {
         
      int j;
         
      for (j = OrdersTotal()-1; j >= 0; j--)
      if (!OrderSelect(j, SELECT_BY_POS, MODE_TRADES))continue;
        
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() > 1)
      
         {
         Print ("Pending Order Successfully Selected", OrderTicket(), " ", OrderSymbol());
         if (!OrderDelete(OrderTicket()))
         Print("Faillure Deleting Order : ", OrderTicket(), " Error: ", GetLastError());
         RefreshRates();
         }
                  
      }
 

As you did not put correct {..} the loops ends right after OrderSelect:

   for (j = OrdersTotal()-1; j >= 0; j--)
   if (!OrderSelect(j, SELECT_BY_POS, MODE_TRADES))continue;

You should do (beside a proper indent):

{
         
      int j;
         
      for (j = OrdersTotal()-1; j >= 0; j--) 
      {
         if (!OrderSelect(j, SELECT_BY_POS, MODE_TRADES))continue;
         
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() > 1)
         {
            Print ("Pending Order Successfully Selected", OrderTicket(), " ", OrderSymbol());
            if (!OrderDelete(OrderTicket()))
            Print("Faillure Deleting Order : ", OrderTicket(), " Error: ", GetLastError());
            RefreshRates();
         }
      }      
}
 
Carl Schreiber:

As you did not put correct {..} the loops ends right after OrderSelect:

You should do (beside a proper indent):


Thank you so much, it did work but if I did not put correct {...} why the loop worked well for one symbol ?

 
Toufik:

Thank you so much, it did work but if I did not put correct {...} why the loop worked well for one symbol ?

Because, then you only had one pending order, so that order was selected.

If you have more than one, your loop goes through all orders, from OrdersTotal () -1 to 0, and at the end the order with index = 0 is selected (which will usually be the first one you executed). When you only had one order, that was the one selected, so the error was not important.

Without the {...} at the time when the EA analyzes the conditions (the symbol and the magic, etc) you will always have only that order (index = 0) selected, if they are met, it will be deleted and if not,  will not be executed.


Regards

 
Jose Francisco Casado Fernandez:

Because, then you only had one pending order, so that order was selected.

If you have more than one, your loop goes through all orders, from OrdersTotal () -1 to 0, and at the end the order with index = 0 is selected (which will usually be the first one you executed). When you only had one order, that was the one selected, so the error was not important.

Without the {...} at the time when the EA analyzes the conditions (the symbol and the magic, etc) you will always have only that order (index = 0) selected, if they are met, it will be deleted and if not,  will not be executed.


Regards


My problem's solved Thank you ;)

Reason: