Could someone please explain the following code and whether this is the best way to write this For instance why is the for loop different when dealing with open orders and pending orders I am not sure why cnt is set to OrdersTotal()-1 in the first loop
Also why is there a return(0) after the order has been closed/deleted Is it not possible to issue all the closures whilst in the loop
Many thanks
for(cnt=OrdersTotal()-1;cnt>=0;cnt--)
{
if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
{
mode=OrderType();
if ((OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber) || AllSymbolsProtect)
{
if (mode==OP_BUY || mode==OP_SELL)
{
OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),slippage,ArrowsColor);
return(0);
}
}
}
}
for(cnt=0;cnt<OrdersTotal();cnt++)
{
if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
{
mode=OrderType();
if ((OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber) || AllSymbolsProtect)
{
if (mode==OP_SELLLIMIT || mode==OP_BUYLIMIT || mode==OP_BUYSTOP || mode==OP_SELLSTOP)
{
OrderDelete(OrderTicket());
return(0);
}
}
}
}
Also why is there a return(0) after the order has been closed/deleted Is it not possible to issue all the closures whilst in the loop
Many thanks
for(cnt=OrdersTotal()-1;cnt>=0;cnt--)
{
if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
{
mode=OrderType();
if ((OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber) || AllSymbolsProtect)
{
if (mode==OP_BUY || mode==OP_SELL)
{
OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),slippage,ArrowsColor);
return(0);
}
}
}
}
for(cnt=0;cnt<OrdersTotal();cnt++)
{
if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
{
mode=OrderType();
if ((OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber) || AllSymbolsProtect)
{
if (mode==OP_SELLLIMIT || mode==OP_BUYLIMIT || mode==OP_BUYSTOP || mode==OP_SELLSTOP)
{
OrderDelete(OrderTicket());
return(0);
}
}
}
}