
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
Ok, so let's create datetime in UTC time zone.
This will output:
So closing price at 15:16 (UTC+3, Cyprus-time) = 14:16 (UTC+2, my local time) should be 94048.45.
But it's not true. 14:16 is right now, and prices on that candle at the moment:
The only way to fetch the current, latest prices, is by adding 3 hours of offset. Why?
to_datetime = utc_now + timedelta(hours=3)
where utc_now is:
UTC time now: 2025-04-27 12:19:36.873149+00:00
So I'm not able to fetch the correct, up-to-date price values if I use UTC, only if I use broker's local time.
Even better, I fetched the broker time (for safety, without timezone information):
Broker time without timezone: 2025-04-27 15:43:40.261526
and input it into the data fetcher formula:
Even this doesn't return the correct, current prices:
But expected last row is:
The only way to fetch the current, latest prices, is by adding 3 hours of offset. Why?
where utc_now is:
UTC time now: 2025-04-27 12:19:36.873149+00:00
So I'm not able to fetch the correct, up-to-date price values if I use UTC, only if I use broker's local time.
Do you take it into account that different programming languages use different notations for UTC offset?
MQL5's built-in functions such as as TimeGMTOffset() and other time-related, use the offset notation, that positive time zones, such as GMT+3, are denoted by negative offsets, such as -10800, and vice versa. This notation is used by some other programming languages, like JaveScript, but there is also other languages (like Python), which denote positive time zones by positive offsets, and negative time zones by negative offsets.
Привет @Stanislav Korotky
I didn't take it into account but I still fail to understand how the +/- sign affects my calculations. If I subtract the timedelta of 3 hours, I won't get the correct candle values even close.
Furthermore, I know that my broker is located in Cyprus, so the time there is well-known: UTC+3.
Yet, I don't understand that if I want to fetch data till 10:34 AM according to my local time (UTC+2), why do I have to input 13:34 in the command, when the difference between me and my broker is supposedly only 1 hour?
Hello Levente,
Most brokers set their timezone for price data which is somehow linked to US time. Say my broker is situated in Australia but its server time (which you will get along with prices are returned) to GMT+3 while US Daylight saying is in effect, else it is set to GTM+2.
So brokers location does not matter, but what time he is following is matter.
Check these links for details on timezone https://www.mql5.com/en/users/amrali and https://www.mql5.com/en/users/gooly. Both of them have created library to handle time zones.
Check this link https://www.mql5.com/en/docs/python_metatrader5/mt5copyratesrange_py on how to adjust time zone (provided you know time zone followed by Broker) while retrieving data into Python.
You can also ask your Broker which time zone they follow.
Hope this helps you man.
The only way to fetch the current, latest prices, is by adding 3 hours of offset. Why?
where utc_now is:
UTC time now: 2025-04-27 12:19:36.873149+00:00
So I'm not able to fetch the correct, up-to-date price values if I use UTC, only if I use broker's local time.
Yes, it looks like the documentation is incorrect, and the timestamps in the quotes are returned in the timezone of the server, the same way as on charts and in MT5 history.
Forum on trading, automated trading systems and testing trading strategies
python api does not return UTC times
Fernando Carreiro, 2022.02.02 16:47
It seems that the "Python" documentation is in conflict with the "MQL5" documentation. You probably should take the MQL version as being the most correct, and in that case it will always be in Broker server time and not UTC.