Function to count all trades :

Code:
//----------------------------------------------------- count all

int countall(){
   int ordercount=0;
   for(int j=OrdersTotal()-1;j>=0;j--){
      if(!OrderSelect(j,SELECT_BY_POS))continue;
         if(OrderMagicNumber()==Magic)
            ordercount++;
   }
   return(ordercount);
}