String comparison - page 2

 
ammer.jens #: MQL4 as this function does not exist in MQL5?

Doesn't exist in MQL4 either. When you see blue text with underlines, those are hyperlinks. You click on them to see other pages.

 
Obviously I am not very focused today.

I'll stop answering questions for now...


sinput int start_hr = 14;
sinput int start_mn = 35;
sinput int stop_hr = 20;
sinput int stop_mn = 55;

bool check_time(const int _start_hr, const int _start_mn, const int _stop_hr, const int _stop_mn)
{
        MqlDateTime curr_tm = {};
        TimeTradeServer(curr_tm);

        return(    (((curr_tm.hour == _start_hr) && (curr_tm.min >= _start_mn)) 
                        || (curr_tm.hour > _start_hr))
                && (((curr_tm.hour == _stop_hr) && (curr_tm.min < _stop_mn))
                        || (curr_tm.hour < _stop_hr))
        );
}


void OnTick()
{
        // Check for trading times
        if(!check_time(start_hr, start_mn, stop_hr, stop_mn))
        { return; }

        // Do trading stuff...

        // Return
        return;
}
 
ammer.jens #:

Thank you William for your suggested solution!


1. Hoever, is

MQL4 as this function does not exist in MQL5? What would be the MQL5 pendant?

2.Nevertheless, I would still like to understand/know if my provided solution would be correct or if it might lead to any false results?

You can just leave out the time statement. - (I think... ) :-)

 

Hi Dominik, just leaving out the time statement does not do the job because then it counts the seconds from 1970 to today and that is then compared to the time portion HR1435 and HR2055. I have checked the time function written in mql4 code again but I do not understand how it works so not able to translate it to mql5 code. 

Nevertheless, thank you for your provided solution but I think I will stick to the one I provided. I tested it for different timepoints and it seems to work and is much more readable/intuitive for me than comparing hour and mm separately.

 
I see. Just as I said, not focused....
 
ammer.jens #: but I do not understand how it works so not able to translate it to mql5 code.
  1. Read the code and you would.
  2. There is nothing to translate.
 

Hello William,

I had another look at your function:

#define HR2400 (PERIOD_D1 * 60)  // 86400 = 24 * 3600 = 1440 * 60
#define SECONDS uint
SECONDS     time(datetime when=0){        if(when == 0) when = TimeCurrent();
   return SECONDS(when % HR2400);
}

If I understand it correctly, when the function is called without any time, the function recalls itself using TimeCurrent() and then returns "TimeCurrent() % HR2400"

I would adjust your code provided as follows:

#define HR2400 (PERIOD_D1 * 60)  // 86400 = 24 * 3600 = 1440 * 60
#define HR1435 52500 // 14:35
#define HR2055 75300 // 20:55
int TOD = TimeTradeServer()%HR2400;
return HR1435 <= TOD && TOD < HR2055;

Is this correct?

Nevertheless, I spotted that the definition of HR2400 results in "984480" seconds. I would assume it to be "86400" as stated in the comment of the code as this is the number of seconds for 24h. Maybe this time it is MQL4 related?

Thank you!