A function to count trades on a certain bar :

Code:
int countbar(int ordertype, datetime time){
   int ordercount=0;
   for(int j=OrdersTotal()-1;j>=0;j--){
      if(!OrderSelect(j,SELECT_BY_POS))continue;
      if(OrderType()==ordertype)
         if(OrderMagicNumber()==Magic)
            if(OrderSymbol()==Symbol())
               if(OrderOpenTime()>=time)ordercount++;
   }
   return(ordercount);
}