Which design is correct?

 

Like this

void Close_All()
{
  int Total = OrdersTotal();
  for (int i=0; i < Total; i++)   //требует уточнения эта строка                                                     
  {                                                                                          
    if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
    {
      switch(OrderType())
      {
        case OP_BUY : OrderClose(OrderTicket(),OrderLots(),Bid,5); break;
        case OP_SELL: OrderClose(OrderTicket(),OrderLots(),Ask,5); break;
        default     : break;
      }        
    }
  }  
} 

or like this...

void Close_All()
{
  int Total = OrdersTotal();
  for (int i=1; i <= Total; i++)                                                        
  {                                                                                          
    if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
    {
      switch(OrderType())
      {
        case OP_BUY : OrderClose(OrderTicket(),OrderLots(),Bid,5); break;
        case OP_SELL: OrderClose(OrderTicket(),OrderLots(),Ask,5); break;
        default     : break;
      }        
    }
  }  
}

and will this function close all orders?

I have only one order closed for some reason, I can't figure out the reason.

 
Both of them are a waste of time.
 
TheXpert:
Both of them are a waste of time.


Why?
 
valenok2003:


Why?


Because it's better this way:

int Total = OrdersTotal();
  for (int i=Total; i>=1; i--)
   if(OrderSelect(i-1,SELECT_BY_POS,MODE_TRADES)==true)
...
 
valenok2003:


PATHY Why?
PATAMU that none of your options will close ALL orders if there are more than 1.
 

even one single order... may not close...

 

OrdersTotal() - Returns the total number of open and pending orders

For OrderSelect() - Does the numbering start with one or zero?

 
valenok2003:

OrdersTotal() - Returns the total number of open and pending orders

For OrderSelect() - does the numbering start with one or zero?

Think about what happens to the numbering after at least one order is closed.

The numbering starts from zero.

 
The first one is basically correct, it will close all the orders, but the closing prices should be normalized. The second fails, not all orders will close (the cycle is not correct)
 

Yep, got it, lots of holidays are bad for the brain. ))))

Thank you!

 
Techno:
The first one is basically correct, it will close all orders, but we have to normalize the closing prices. The second one fails, not all orders will be closed (the loop is not correct)


It will not.

If you don't believe me, do an experiment on a demo.

Reason: