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!
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.

- www.mql5.com
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.

- www.mql5.com
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.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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.