DateTime() - page 2

 
cameofx:

True.

To my knowledge StrToTime(04:00) will return last compile date with time(hh:mm) (consequently local time) that's what I meant.

It will return local computer time if you happen to compile it & call your indicator not long after it. But not local computer as in TimeLocal()*.

Try leaving your terminal on for an hour or until next day; detach that particular EA/Indy but don't close your MT4 -- closing it will recompile the indy on MT4 restart* -- and reattach it later. It will churn out the same compile date/time not current local time despite the StrToTime() is freshly called. FWIW.

*Edited.

I've made the following test: I call StrToTime("14:00") for example and then change the date on my computer clock. Then call StrToTime("14:00") again without recompiling. The results were quite obvious.
 
robofx.org:
I've made the following test: I call StrToTime("14:00") for example and then change the date on my computer clock. Then call StrToTime("14:00") again without recompiling. The results were quite obvious.
Not necessary to use StrToTime at all
double  Tokyo.channel.high, Tokyo.channel.low,                  // openNew
        HH.value[2],        LL.value[2]={999999,0}; 
void    TokyoChannel(){                                                 datetime
    TimeUTC             = Time[0] + Server.Time.To.UTC,
    TimeUTC0000         = TimeUTC - (TimeUTC) % 86400,              // 24*60*60
    TimeWellingtonOpen  = TimeUTC0000 + 79200 - Server.Time.To.UTC, // 22*60*60
    TimeNYmidnight      = TimeWellingtonOpen + 21600; /*6Hr 22..4 GMT*/
    while(                TimeNYmidnight      > Time[0]     // In the past only.
         || TimeDayOfWeek(TimeNYmidnight)     > 5           // Market is closed
         || TimeDayOfWeek(TimeWellingtonOpen) > 5 ){        // Saturdays
            TimeWellingtonOpen -= 86400;    TimeNYmidnight -= 86400;    }
    int TKcPeriod       = MathMin( PERIOD_H1, Period() ),
        TKcStart        = iBarShift(NULL,TKcPeriod, TimeWellingtonOpen),
        TKcEnd          = iBarShift(NULL,TKcPeriod, TimeNYmidnight-1),
        TKcLength       = TKcStart - TKcEnd + 1;
    Tokyo.channel.high  = High[Highest(NULL,TKcPeriod, MODE_HIGH, TKcLength, TKcEnd)];
    Tokyo.channel.low   =  Low[ Lowest(NULL,TKcPeriod, MODE_LOW,  TKcLength, TKcEnd)];
 
WHRoeder:
Not necessary to use StrToTime at all
Your contribution is much appreciated WHRoeder. Thanks. My opinion as well, arithmetic operations on datetime is much more convenient & robust.
 
robofx.org:
I've made the following test: I call StrToTime("14:00") for example and then change the date on my computer clock. Then call StrToTime("14:00") again without recompiling. The results were quite obvious.

I haven't the time to verify, but did you made sure nothing on MetaEditor is compiled while MT is on? And have you tried my test. Leave MT on through midnight & call it again 'the next day'. 

That documentation & my experience proving it a while back is what I have. I'll cross check if I have the time. I'm not ruling anything out yet.  

 
cameofx:

I haven't the time to verify, but did you call it through a script/indy and made sure MT isn't restarted or nothing on MetaEditor is compiled?

That documentation & my experience proving it a while back is what I have. I'll cross check if I have the time. I'm not ruling anything out yet.

Yes I used a simple script, nothing was restarted or recompiled during tests, just changed the windows clock date.

I attach the script I used.

Files:
timetest.mq4  1 kb
 
QUOTE:
Datetime constants can be represented as a literal line consisting of 6 parts for values of year, month, date, hours, minutes, and seconds.
The constant is enclosed in single quotes and starts with D. Either date (year, month, date) or time (hours, minutes, seconds), or both can be skipped.
Datetime constant can vary from Jan 1, 1970 to Dec 31, 2037.
Examples:
D'2004.01.01 00:00' // New Year
D'1980.07.19 12:30:27'
D'19.07.1980 12:30:27'
D'19.07.1980 12' //equal to D'1980.07.19 12:00:00'
D'01.01.2004' //equal to D'01.01.2004 00:00:00'
D'12:30:27' //equal to D'[compilation date] 12:30:27'
D'' //equal to D'[compilation date] 00:00:00'

Its internal representation is a long integer number of 4 bytes.
The value represents the amount of seconds elapse from 00:00 Jan 1, 1970. -UNQUOTE.
  ------------------------------------------------------------------------------------------------------

The documentation is using/talking about datetime constants. While neither of our code (yours, bluesman & mine) is doing that. 

// bluesman snippets -----------------------------------------------

extern int RangeStart=04; // btw this variable should be string-type to be safe
extern int RangeEnd=08;

string sts = StringConcatenate(RangeStart, ":00"); // else it will concatenate to 4:00
string ste = StringConcatenate(RangeEnd, ":00");   // may or may not effect end result
datetime ts = StrToTime(sts);
datetime te = StrToTime(ste);

// your test script ------------------------------------------------

string t = "10:00";
Print(TimeToStr(StrToTime(t),TIME_DATE|TIME_MINUTES)); 

// my indy ---------------------------------------------------------

extern string sAsiaBegin = "02:00";
extern string sAsiaEnd = "11:00";
string sTIME_BEGIN = "1970.01.01" ;
datetime t_Begin_Asia, t_End_Asia;
datetime t_TIME_BEGIN;
  
t_TIME_BEGIN = StrToTime(sTIME_BEGIN); // the amount of seconds at beginning of MQL time = '0'
t_Begin_Asia = StrToTime(StringConcatenate(sTIME_BEGIN," ",sAsiaBegin));

Not the same thing. I realize that as soon as I saw your script. 
So I take it, whenever we need compilation date & specified time; we can safely use D'HH:MM:SS' or D'HH:MM' or D' ' constants.  FWIW.

 
WHRoeder:
Not necessary to use StrToTime at all
The code I posted above doesn't work correctly.
    /* Wellington opens at 22 GMT or Sunday 23 GMT during Daylight Savings Time.
     * NY midnight is 4 GMT. Channel size is 5-6 hrs.
     * Also have to handle the case were the market is closed for Christmas, the
     * bars jump from 2008/12/24 18:59 to 2008/12/26 07:00 (No channel at all.)
     */
    int NYMidNight      = (4-Server.Time.To.UTC +24)%24;
    for (int barNYmid = 0; true; barNYmid++){
        datetime TimeNYmid = iTime(NULL, PERIOD_H1, barNYmid);
        if (TimeHour(TimeNYmid) == NYMidNight)  break;  }

    int WellingtonOpen  = 22-Server.Time.To.UTC;
    for (int barWell = barNYmid+6; barWell>barNYmid; barWell--) {
        datetime TimeWellington = iTime(NULL, PERIOD_H1, barWell);
        if ((TimeHour(TimeWellington)-WellingtonOpen+24)%24 <= 1) break;
    }
    int TKcSize     = barWell - barNYmid,
        TKc.high    = Highest(NULL, PERIOD_H1, MODE_HIGH, TKcSize, barNYmid+1),
        TKc.low     =  Lowest(NULL, PERIOD_H1, MODE_LOW,  TKcSize, barNYmid+1);
    Tokyo.channel.high  = iHigh(NULL, PERIOD_H1, TKc.high);
    Tokyo.channel.low   =  iLow(NULL, PERIOD_H1, TKc.low);
Reason: