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)
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.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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:
Where
However, this just gives me compilation errors, so its wrong!
Suggestions would be most welcome! Thanks.