Problem with retrieving open trades Count

 
Hello,

First return 0 and then return 2
int CountTrades()
{
int icnt, itotal, retval;

retval=0;
itotal=OrdersTotal();

   for(icnt=0;icnt<itotal;icnt++) // for loop
     {
      OrderSelect(icnt, SELECT_BY_POS, MODE_TRADES);
       // check for opened position, symbol & MagicNumber
       if (OrderSymbol()== "EURAUD")
        {
          if (OrderMagicNumber()==MagicNumber) 
            {
              if(OrderType()==1  || OrderType()==0) retval++;
            }       
        } // sOrderSymbol
     } // for loop

return(retval);
}

If I have (CountTrades()==1) {  //need to call something }   if (CountTrades()==2) {  //need to call something }  if (CountTrades()==3) {  //need to call something }  if (CountTrades()==4) {  //need to call something }
Files:
 
  1. Your image doesn't match your posted code. There are no such Print/Alert statements.
  2. Don't just keep calling your function. Call once, save to a variable.