Download MetaTrader 5
To add comments, please log in or register
Download documentation as one file. It is easy!
jmb1
86
jmb1 2014.07.12 22:04 

I'd be very grateful for a little help.  I'm trying to extract the hours:minutes close time of the previous bar.

Looking at the help here https://docs.mql4.com/convert/timetostring, I think I need something like this: 

HrsMinsTime TimeToString(
       datetime LastMarketCloseTime,
       int mode=TIME_MINUTES
        );

Where

HrsMinsTime is the variable to store the hh:mm extracted value

LastMarketCloseTime is the variable to store the datetime value of the close of the previous bar (elapsed time since 00:00 a.m. of 1 January, 1970) 

However, this just gives me compilation errors, so its wrong!

Suggestions would be most welcome!  Thanks.

qjol
3243
qjol 2014.07.12 22:39  
jmb:

I'd be very grateful for a little help.  I'm trying to extract the hours:minutes close time of the previous bar.



there isn't such a command/function built in in MQL4

may i ask

for what purpose do you need that

in case you really want it

you'll have to build your own function

honest_knave
968
honest_knave 2014.07.12 23:10  

If you are happy to accept the open of the current bar (rather than the close of the previous) you can use: 

   string HrsMinsTime = TimeToStr(Time[0],TIME_MINUTES);

 

Or you can try this, which takes the open of the previous bar and adds the chart period to it:

   string HrsMinsTime = TimeToStr(Time[1]+(Period()*60),TIME_MINUTES);

 (you may want to subtract 1 from the above... depends on your preference)

Drazen Penic
2406
Drazen Penic 2014.07.13 09:24  

If you want that as a string you can do something like this:

 

string HourMinuteString(datetime time)
{
  return (StringFormat("%02d:%02d", TimeHour(time), TimeMinute(time)));
}

 

 This returns string in format "hh:mm" with leading zeroes if hour and minute are less than 10.

/
To add comments, please log in or register