What are the MetaQuotes Time Specifications

 

I'm running a script on EURUSD with the default broker which is MetaQuotes. TimeCurrent() gives me the current broker time. Right now, its offset seems to be GMT+2. I want to export chart history to csv. iTime() function gives me the datetime of each historical bar in broker time offset. However, I want to convert the time to UTC.

I'm not sure if the offset is always GMT+2 historically. Also, I don't know if the broker adjusts for DST or not. I appreciate any helps.

 
It adjusts to DST, so its GMT+2 in the winter and GMT+3 in the summer.
 
Eleni Anna Branou #:
It adjusts to DST, so its GMT+2 in the winter and GMT+3 in the summer.

Thanks. I'm also struggling to find out what exact datetimes should be used for winter switch and summer switch. It seems to be different for different countries.

 
Mohammad Sh:

I'm running a script on EURUSD with the default broker which is MetaQuotes. TimeCurrent() gives me the current broker time. Right now, its offset seems to be GMT+2. I want to export chart history to csv. iTime() function gives me the datetime of each historical bar in broker time offset. However, I want to convert the time to UTC.

I'm not sure if the offset is always GMT+2 historically. Also, I don't know if the broker adjusts for DST or not. I appreciate any helps.

To detect timezones and DST on history you can use scripts/indicators from codebase made by @amrali, or mine.

But it's not so simple with MQ Demo ;-), because it's not a broker, and the "demo" means "unstable" or at least "experimental".

Indeed MQ demo server operates in GMT+2 timezone with DST enabled for summer time, that is GMT+3.

The problem is that different symbols change their timezones under different schedules (!), which is discovered by @amrali: EURUSD quotes adhere to US_DST schedule, whereas XAUUSD adhere to EU_DST schedule. This is weird!

 
Stanislav Korotky #:

To detect timezones and DST on history you can use scripts/indicators from codebase made by @amrali, or mine.

But it's not so simple with MQ Demo ;-), because it's not a broker, and the "demo" means "unstable" or at least "experimental".

Indeed MQ demo server operates in GMT+2 timezone with DST enabled for summer time, that is GMT+3.

The problem is that different symbols change their timezones under different schedules (!), which is discovered by @amrali: EURUSD quotes adhere to US_DST schedule, whereas XAUUSD adhere to EU_DST schedule. This is weird!

Thanks, I checked out your library: https://www.mql5.com/en/code/52557, does it account for the problem you mentioned? I'm currently adding my script to EURUSD, but I might want to add it to other MetaQuotes symbols in the future.

TimeServerDaylightSavings
TimeServerDaylightSavings
  • www.mql5.com
Time-related functions for empirical detection of server time zone and daylight savings mode (DST) from history of quotes
 
Mohammad Sh #:

Thanks, I checked out your library: https://www.mql5.com/en/code/52557, does it account for the problem you mentioned? I'm currently adding my script to EURUSD, but I might want to add it to other MetaQuotes symbols in the future.

The lib will only report different periods of DST switches depending from on which symbol you run the test (provided that symbols are unexpectedly misaligned in time).

This problem (with different time segmentation of different symbols) can not be solved without additional heuristics performed by a human. If someone is interested [s]he can delve into it, but this is an error in the quotes and server setup, and should never occur on a real broker. Actually it should be fixed on MQ demo as well.

 

I ended up using the following library: https://www.mql5.com/en/code/48291

In the library, I moved 'CTimeGMT::TimeServerGMTOffset()' from protected to public. Then I imported the library and used the following:

datetime timegmt = time - CTimeGMT::TimeServerGMTOffset(time);

Where 'time' is the output of 'iTime()' function.

As for testing, I used this script to find out MetaQuotes:EURUSD uses DST_UK convention, i.e. summer switch will be on last Sunday of March. I controlled 2024 summer switch and it captured UTC+3 to UTC+2 on the end of March correctly. I didn't control the exact time of switch though, as I'm fine with little discrepancies if any for now.

TimeGMT library for the strategy tester
TimeGMT library for the strategy tester
  • www.mql5.com
Static class to fix the TimeGMT() function during testing in the strategy tester.
 
Mohammad Sh #:

I ended up using the following library: https://www.mql5.com/en/code/48291

In the library, I moved 'CTimeGMT::TimeServerGMTOffset()' from protected to public. Then I imported the library and used the following:

Where 'time' is the output of 'iTime()' function.

As for testing, I used this script to find out MetaQuotes:EURUSD uses DST_UK convention, i.e. summer switch will be on last Sunday of March. I controlled 2024 summer switch and it captured UTC+3 to UTC+2 on the end of March correctly. I didn't control the exact time of switch though, as I'm fine with little discrepancies if any for now.

Great.
There is a little catch with the current version. The dst switch occurs exactly at 1:00 am (instead of 00:00) on the last Monday of March (appearance of the first H1 bar of the trading week on XAUUSD). I am planning to fix it in the next release.