EA runs during certain time period. How to disable it?

 

Hi.

I want to run it during 24 hours.

If I set it up as following, EA does not work.

Start time=24:00

End time=24:00

What should I change it?

If I remove these code, it does not compile it either.

Thanks in advanced.

bool sleepTime()
  {
   string dt    = TimeToString(TimeCurrent());
   string DTstr = TimeToString(TimeCurrent(),TIME_DATE);
   string start_time = DTstr + " " + starting_time;
   string end_time   = DTstr + " " + ending_time;
   StringToTime(start_time);
   StringToTime(end_time);
   StringToTime(dt);

   if((start_time<end_time && dt>=start_time && dt<end_time) || (start_time>=end_time && (dt>=start_time || dt<end_time)))
     {
      return(true);
     }
   return(false);
  }
 
  1.    StringToTime(start_time);
       StringToTime(end_time);
       StringToTime(dt);
    These lines do nothing. You are throwing the results away. Simplify:
       string start_time = StringToTime(starting_time);
       string end_time   = StringToTime(ending_time);

  2. There is no time 24:00. Converting to a string results in a wrong result. Replacing with 23:59:59 would work.

  3. Your start time is 00:00 not 24:00.

  4. Rename your function. It returns true if it is time to trade, not time to sleep.

  5. Stop using strings as inputs, you can't optimize them. Replacing the strings with a double start_hour simplifies everything.

    bool tradeTime()
      {
       int    begin = int( starting_hour * 3600);
       int    end   = int(   ending_hour * 3600);
       int    now   = time();
       return begin <= end ? begin <= now && now < end
                           : begin >= now || now < end;
      }
              Find bar of the same time one day ago - MQL4 programming forum (2017)
              Increase Order after stoploss - MQL4 programming forum #1.3 (2017)
 
William Roeder #:
  1. These lines do nothing. You are throwing the results away. Simplify:
  2. There is no time 24:00. Converting to a string results in a wrong result. Replacing with 23:59:59 would work.

  3. Your start time is 00:00 not 24:00.

  4. Rename your function. It returns true if it is time to trade, not time to sleep.

  5. Stop using strings as inputs, you can't optimize them. Replacing the strings with a double start_hour simplifies everything.

              Find bar of the same time one day ago - MQL4 programming forum (2017)
              Increase Order after stoploss - MQL4 programming forum #1.3 (2017)

Appreciate it!!!

 
William Roeder #:
  1. Stop using strings as inputs, you can't optimize them. Replacing the strings with a double start_hour simplifies everything.

      
  2. bool tradeTime()
      {
       int    begin = int( starting_hour * 3600);
       int    end   = int(   ending_hour * 3600);
       int    now   = time();
       return begin <= end ? begin <= now && now < end
                           : begin >= now || now < end;
      }

What a nice neat code. Hope I understood it correctly - the last line should be 

: begin <= now || now < end;

?