Download MetaTrader 5

Calculate Daily profit

To add comments, please log in or register
8tango
112
8tango  

Hello,

I would like to calculate the daily profit of one of my EA, my code is:

double DailyProfit()
{
double profit = 0;
int i,hstTotal=OrdersHistoryTotal();
  for(i=0;i<hstTotal;i++)
    {
     if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==TRUE)
       {
         if(TimeToStr(TimeCurrent(),TIME_DATE) == TimeToStr(OrderCloseTime(),TIME_DATE))
         {
            profit += OrderProfit() + OrderSwap() + OrderCommission();
         }
       }
    }
   return(profit);
}

But this code return the equity of my account, what is wrong into my code?

Thank you for your help.

honest_knave
Moderator
2326
honest_knave  
double DailyProfit()
{
double profit = 0;
int i,hstTotal=OrdersHistoryTotal();
  for(i=0;i<hstTotal;i++)
    {
     if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==TRUE)
       {
         if(OrderType()>1) continue;
         if(TimeToStr(TimeCurrent(),TIME_DATE) == TimeToStr(OrderCloseTime(),TIME_DATE))
         {
            profit += OrderProfit() + OrderSwap() + OrderCommission();
         }
       }
    }
   return(profit);
}
 
whroeder1
15902
whroeder1  
if(OrderType()>1) continue;
Deleted orders have zero OrderCloseTime, and wouldn't be selected.
But there are other entries in history deposits/withdrawals and adjustments (6/7)
8tango
112
8tango  
Thank you very much it work fine.
To add comments, please log in or register