Only one trade per day

 

Hello everybody,

i'am new with mql5 and i have some problems to write the function, which check for me if the EA already have trade on this day. I will be very grateful if somebody can have a look at my code. Thank you very much!

bool DoWeHaveAlreadyOneTradeToday(){
   MqlDateTime today;
   datetime NullUhr;
   datetime now= TimeCurrent(today);
   int year = today.year;
   int month = today.mon;
   int day = today.day;
   NullUhr = StringToTime(string(year)+"."+string(month)+"."+string(day)+" 00:00");
   HistorySelect(NullUhr, now);
   uint total= HistoryDealsTotal();
   
   for(uint i=0;i<total;i++){
      ulong ticket=HistoryDealGetTicket(i);
      string symbol=HistoryDealGetString(ticket,DEAL_SYMBOL);
      datetime time =(datetime)HistoryDealGetInteger(ticket,DEAL_TIME);
      if(time>NullUhr){
            return true;
      }
      else{
            return false;
      }     
   }
   return false;
  }
 

Remove this:

      else{
            return false;
      }     
 
Thank You
 
Your code
   MqlDateTime today;
   datetime NullUhr;
   datetime now= TimeCurrent(today);
   int year = today.year;
   int month = today.mon;
   int day = today.day;
   NullUhr = StringToTime(string(year)+"."+string(month)+"."+string(day)+" 00:00");
Simplified
   datetime NullUhr = date();
          Find bar of the same time one day ago - MQL4 programming forum #1 & #6 (2017)
Reason: