Bar time

 

double h = High[1];
int t = Time[1];
MessageBox("H=" + h + ", t=" + t);

The above returns the correct high for bar 1 but the time returned is 13335535200. What is the correct way of retrieving the bar time?

 
JAB:

double h = High[1];
int t = Time[1];
MessageBox("H=" + h + ", t=" + t);

The above returns the correct high for bar 1 but the time returned is 13335535200. What is the correct way of retrieving the bar time?

 

Let add what I though the return would have been is 1300 being this is a hour chart. Is 13335535200 the time of the last tick?

 

Review: https://docs.mql4.com/predefined/variables/time and https://docs.mql4.com/basis/types/datetime

A variable of datetime type "is a long integer number of 4 bytes. The value represents the amount of seconds elapse from 00:00 Jan 1, 1970."

You can use various conversion methods (including TimeToStr) to convert all or parts of a datetime variable type to another type (e.g., int, string, etc).

 

Time[] gives you the number of seconds "passed since 00:00 a.m. of 1 January, 1970". https://docs.mql4.com/predefined/variables/time

You are half way there. You just need to convert those seconds into a more meaningful format.

The info in the documentation is admittedly a bit oblique for this explanation, but what you need to do is input the "Time[]" predefined variable INSIDE the brackets of one of the time functions which begin with the word "Time" and then have a suffix - such as TimeHour().

Those functions take the data you put in brackets and repackage them in the selected time format. To recreate the conventional time from Time[] you can print TimeHour(Time[]), TimeMinute(Time[]), and TimeSeconds(Time[]) in series in a string.

The exceptions to this are TimeCurrent() and TimeLocal(). Like Time[], they also give a number of seconds since 1970, and therefore they mostly need to go inside another Time"xyz"() function to get something meaningful from them.

Remember that Time[] gives the number of seconds fixed at the open time of that bar, which are the same throughout the bar and are a consistent distance (in seconds) from the previous and subsequent bars - whereas TimeCurrent() (last known server time) is updated every tick and TimeLocal() (last known local time) is updated every second, and so they change during a bar.

EDIT:

You can use various conversion methods (including TimeToStr) to convert all or parts of a datetime variable type to another type (e.g., int, string, etc).

... or just use TimeToStr() - I forgot about that!

 
JAB:


Thank you very much the following gave me what I was looking for.

double h = High[0];
int t = TimeHour(Time[0]);
MessageBox("H=" + h + ", t=" + t);

The results was > H=1.1.325850000, t=16

Reason: