using magic number

 
i'm checking to see if there's no open trade at the same level (level is not price, just an int) using the magic number.
is there any case this shouldn't work that i didn't think of? i'm getting multiple trades at the same level, so i believe the problem is in this code section. help is much appreciated..

bool IsPositionBuy(int Level)
{
int totalorders = OrdersTotal();
for(int i=0;i<totalorders;i++) // scan all positions
{
OrderSelect(i, SELECT_BY_POS);
if ( OrderType() == OP_BUY && OrderMagicNumber()==Level ) return(true);
}
return(false);
}
 
Try
bool IsPositionBuy(int Level)
{
int totalorders = OrdersTotal();
for(int i=0;i<totalorders;i++) // scan all positions
   {
   if (!OrderSelect(i, SELECT_BY_POS)) continue;
   if ( OrderType() == OP_BUY && OrderMagicNumber()==Level ) return(true);
   }
return(false);
}
 
I tried it, didn't help. It seems the ea just opens duplicate trades within the same bar. is there a way to avoid it?
 
Show your code...