The language is called "MQL". It is not called "C++". Just because MQL is based on C/C++, does not mean that you can use pure C++ code.
If you wan to convert or use zone based time functions, then use the MQL functions for it — Documentation on MQL5: Date and Time
Please note that some of these functions are not supported in the Strategy Tester.
Function
Action
Returns the last known server time (time of the last quote receipt) in the datetime format
Returns the current calculation time of the trade server
Returns the local computer time in datetime format
Returns GMT in datetime format with the Daylight Saving Time by local time of the computer, where the client terminal is running
Returns the sign of Daylight Saving Time switch
Returns the current difference between GMT time and the local computer time in seconds, taking into account DST switch
Converts a datetime value into a variable of MqlDateTime structure type
Converts a variable of MqlDateTime structure type into a datetime value
- www.mql5.com
Hi Lorentzos, thank you for your interest! I don't use tester. In real time, I would like to print such an output "14/12/2022 14:12:38.207", but I need to set the UTC time zone.
Then they have such a provision already
TimeGMT()
It returns the local time , and , in mt5 if you want the estimated server time (of the broker) they have also provided
TimeTradeServer()
Which does not stop on friday unlike
TimeCurrent()
In Mt4 some ninja stuff must be done to find the live broker time .
With:
https://www.mql5.com/en/articles/9926
https://www.mql5.com/en/articles/9929
you can detect even in the tester GMT (=UTC) as well as the time in EU and USA and then you can use these time stamps instead of TimeCurrent():
void OnTick() { ... tC = TimeCurrent(); checkTimeOffset( tC ); tGMT = tC + OffsetBroker.actOffset; // GMT tNY = tGMT - (NYShift+DST_USD); // time in New York tLon = tGMT - (LondonShift+DST_EUR); // time in London tEU = tGMT - (FfmShift+DST_EUR); // time in FFm ...
- www.mql5.com
With:
https://www.mql5.com/en/articles/9926
https://www.mql5.com/en/articles/9929
you can detect even in the tester GMT (=UTC) as well as the time in EU and USA and then you can use these time stamps instead of TimeCurrent():
Excellent work @Carl Schreiber 👏 👏
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Since it seems it is not possible to convert to UTC time zone, I thought of putting a C++ method in a .mqh file. But apparently there is a compilation problem. Can anyone give me some help?