daily profit

 
Hi,

maybe someone can help me.
My EA has to stop trading if a certain daily profit amount is reached and starts trading on the next day again. How can I program this? I have problems with "daily profit"

Thx
 
double DailyProfit()
{
  double profit = 0;
 
  int cnt = OrdersHistoryTotal();
  for (int i=0; i < cnt; i++) {
    if (!OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) continue;
 
    if (TimeDayOfYear(OrderCloseTime()) == DayOfYear() && TimeYear(OrderCloseTime()) == Year()) profit += OrderProfit();
  }
 
  return (profit);
}
 
if that's the only thing trading on your terminal then watch balance vs equity.

opentradesprofit=AccountEquity()-AccountBalance();
 
Thx for your answers
Reason: