A function to count the profit in the historic :

Code:
//----------------------------------------------------- count historical profit

int counthistbarprofit(datetime time){ // count(OP_BUY)
   int profit=0;
   for(int j=OrdersHistoryTotal()-1;j>=0;j--){
      if(!OrderSelect(j,SELECT_BY_POS,MODE_HISTORY))continue;
         if(OrderMagicNumber()==Magic)
            if(OrderSymbol()==Symbol())
               if(OrderOpenTime()>=time)
                  if(OrderProfit()>0)profit++;
   }
   return(profit);
}