Does the "for" operator always work in test mode?

 

Hi

I have been trying to get an EA working but for some reason when i go thru a for loop to close all my trades it only gets half of them. I have 12 trades and only 6 are closed. Is it a problem with my testing at every tick(only 2 days trading)? This is the non working routine

// This routine closes all open trades
int closeall()

{ Print(" oooot +++++++++++++++++++++ ",OrdersTotal());
for (int i=0;i<OrdersTotal();i++)
{int err;
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol()
&&OrderMagicNumber()==Magic)
{ Print(" ono ",OrderTicket()," i ",i);
if(OrderType()==OP_BUY)
{if(OrderClose(OrderTicket(),OrderLots(),Bid,0,Pink))
{continue;
}
else
{err =GetLastError();
Print("error ",err);
continue;
}
}//end of buy
if(OrderType()==OP_SELL)
{if(OrderClose(OrderTicket(),OrderLots(),Ask,0,Pink))
{continue;
}
else
{err = GetLastError();
Print("error ",err);
continue;
}
}//end of sell
}
else Print(" OrderSymbol ",OrderSymbol(), " om ",OrderMagicNumber());
}//end for
Print(" closed em all ",AccountEquity()," acb ",AccountBalance(), " i ",i);
return(0);
}

noranross@tadaust.org.au

Can someone please help???

Ross Darwin Australia

 
for (int i=0;i<OrdersTotal();i++)


i==6 and OrdersTotal()==6 => end of loop

 
mql_coder:


i==6 and OrdersTotal()==6 => end of loop

Thanks very much. I have been programming for 40 years but the brain must be wearing out. Ross

 

R

> ...I have been programming for 40 years...

Time for a break dude :)

-BB-

 

Change

for (int i=0;i<OrdersTotal();i++)
to

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

Reason: