Daily Profit procedure

 
I'm looking for a procedure, mql4, that will tell me true or false, when I've hit the daily profit limit for a pair. I've tried the folloowing code but it always returns false.
bool funcGetTodaysProfit()
{
   int intDailyProfitPips=100;
   double dblReturnValue=0,dblDailyProfitPips=intDailyProfitPips*Point;
   for (int i=0; i<OrdersTotal(); i++)
   {//1 +cycle by orders search
      if (OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) break;
      if (OrderMagicNumber()!=intOrderMagicNumber) continue;
      if (TimeYear(Time[0])!=TimeYear(OrderOpenTime()) &&
          TimeDay(Time[0])!=TimeDay(OrderOpenTime()) &&
          TimeMonth(Time[0])!=TimeMonth(OrderOpenTime()))continue; //not todays profit.
      if (OrderType()==OP_BUY) {dblReturnValue=dblReturnValue+(OrderClosePrice()-OrderOpenPrice());}
      if (OrderType()==OP_SELL) {dblReturnValue=dblReturnValue+(OrderOpenPrice()-OrderClosePrice());}
   }
   Comment("Profit today so far: ",DoubleToStr(dblReturnValue,Digits),"\n","Profit target: ",DoubleToStr(dblDailyProfitPips,Digits));
   if (dblReturnValue>dblDailyProfitPips) {return(true);}
   return(false);
}
If anyone can help, I'd appreciate it.
 

You are looking only to the open trades

You have also take a look to the trades today closed

  EA Profits 1.0.mq4 (22.6 Kb) View

This indicator is like iExposure and I published it in  Code Base 

it can show the profits of several EA's for a CHOSEN PERIOD

You can find it at  Profits your EA(s) have made on your account

 
deVries:

You are looking only to the open trades

You have also take a look to the trades today closed

  EA Profits 1.0.mq4 (22.6 Kb) View

This indicator is like iExposure and I published it in  Code Base 

it can show the profits of several EA's for a CHOSEN PERIOD

You can find it at  Profits your EA(s) have made on your account

Good catch!  I made the change from OrdersTotal() to OrdersHistoryTotal().  Now I get the profit for the day.  But up comes up with a new problem.  When I loop through starting the new day, it shows I have a profit for the new day.  Even though I haven't opened or closed any orders yet on the new day.  In my code, it should be returning false, but it's returning true.  Any ideas?
 
deVries:

You are looking only to the open trades

You have also take a look to the trades today closed

  EA Profits 1.0.mq4 (22.6 Kb) View

This indicator is like iExposure and I published it in  Code Base 

it can show the profits of several EA's for a CHOSEN PERIOD

You can find it at  Profits your EA(s) have made on your account

deVries,

 YOU DID IT!  I found the problem thanks to your code!

I added these lines:

   string strCurrentDate=StringConcatenate(TimeYear(Time[0]),".",TimeMonth(Time[0]),".",TimeDay(Time[0]));
   datetime dtCurrentDate=StrToTime(strCurrentDate);

Replaced these lines:

      if (TimeYear(OrderOpenTime())!=TimeYear(Time[0]) &&
          TimeDay(OrderOpenTime())!=TimeDay(Time[0]) &&
          TimeMonth(OrderOpenTime())!=TimeMonth(Time[0]))continue; //not todays profit.

With this line:

      if (OrderOpenTime()<dtCurrentDate) continue;

And it WORKS! 

Thanks!!!!! 

 
nondisclosure:

deVries,

 YOU DID IT!  I found the problem thanks to your code!

I added these lines:

Replaced these lines:

With this line:

And it WORKS! 

Thanks!!!!! 

 

 

 


Great,  you found your solution, but do you realize now why your removed

   if (TimeYear(OrderOpenTime())!=TimeYear(Time[0]) &&
          TimeDay(OrderOpenTime())!=TimeDay(Time[0]) &&
          TimeMonth(OrderOpenTime())!=TimeMonth(Time[0]))continue; //not todays profit.

line did fail ??   and you did get a profit  even though you didn't opened or closed any orders yet on the new day. ???

Reason: