How do i get coding to trade on specific time 08:00-20:00 on day of week - Tuesday to Thursday and from April to December on MQL5 - page 2

 
Israel Pelumi Abioye #: Specifying Trading Time
string start = "08:00";
string end = "20:00";


void OnTick()
  {

   datetime   start_time = StringToTime(start);
   datetime   end_time = StringToTime(end);
   datetime   current_time = TimeCurrent();

   if(current_time >= start_time && current_time <= end_time)
  1. That only works when start < end. It doesn't work like 2100 to 1000. Because of the less than or equal. The code stops at 20:00:59.

  2. When dealing with time, a lot of people use strings; they can not be optimized. Using (int) seconds or (double) hours and fraction can be inputs.
              Find bar of the same time one day ago - MQL4 programming forum #1 & #6 (2017)

    See also Dealing with Time (Part 1): The Basics - MQL5 Articles (2021.10.01)
    Dealing with Time (Part 2): The Functions - MQL5 Articles (2021.10.08)
    MQL5 Programming Basics: Time - MQL5 Articles (2013.04.26)