MT5 how to get timezone shift for charts, EAs etc?

 

My broker has one timezone but I need it in a differnt one. In MT5 how to get timezone shift for charts, EAs etc?

Is it possible to create Custom symbols with a timezone adjustment?

 

You can . First get the server time (broker's time)

datetime server_time=TimeTradeServer();

 Then get the gmt/utc time

datetime gmt_time=TimeGMT();

The gmt time is the pivot around which you can project to other timezones

The following will return the offset in seconds of the server time to the gmt time.

So if a timezone is ahead from gmt this will return a positive reading.

int offset_in_seconds=((int)server_time)-((int)gmt_time);

To go back to that timezone you would add the offset to the gmt time. 

To go to another timezone you will add that timezone's shift in seconds 

There is an issue though that if you wanted to convert past dates you would have to factor in time adjustments of the server's timezone around the calendar.

There was an article with some code for doing time stuff in the past if i recall ,if i find it i'll post it here.

From then on yes if you have a function that turns server time to any other time you can process the ticks of a symbol and create a custom one with your own dates

 
Lorentzos Roussos #:

You can . First get the server time (broker's time)

 Then get the gmt/utc time

The gmt time is the pivot around which you can project to other timezones

The following will return the offset in seconds of the server time to the gmt time.

So if a timezone is ahead from gmt this will return a positive reading.

To go back to that timezone you would add the offset to the gmt time. 

To go to another timezone you will add that timezone's shift in seconds \

There is an issue though that if you wanted to convert past dates you would have to factor in time adjustments of the server's timezone around the calendar.

There was an article with some code for doing time stuff in the past if i recall ,if i find it i'll post it here.

From then on yes if you have a function that turns server time to any other time you can process the ticks of a symbol and create a custom one with your own dates

I am aware of this, however what I am looking for is to apply indicators on charts for various timeframes including 1H, 4H, 1D, 1W 1M etc., for example my broker uses UTC timezone, but with that I get candlesticks on Sundays, but I want no weekend candle sticks.

 
Faisal Mahmood: My broker has one timezone but I need it in a differnt one. In MT5 how to get timezone shift for charts, EAs etc?

Chart times are broker times.

  1. How can MetaQuotes know all brokers' (they come and go daily) Time zone and Daylight savings time (if they use it and including historical changes for back testing)? Do you have that information for just you and your broker? Only then, with code, can you convert session times to broker's time to UTC to local time. You can use offset inputs, but then you must maintain them correctly, through all three DST changes when they occur.
              When is the time zone problem going to be fixed? - General - MQL5 programming forum (2020)

  2. Foreign Exchange (FX) market opens 5 PM New York (NY)/Eastern Time (ET) Sunday and ends 5 PM NY Friday. Some brokers start after (6 PM is common) and end before (up to 15 minutes) due to low volatility.
              Checking for Market Closed - Expert Advisors and Automated Trading - MQL5 programming forum (2016)

    Swap is computed 5 PM ET. No swap if no open orders at that time.

  3. Brokers use a variety of time zones. Their local time, with or without Daylight Savings Time (DST), London, UTC, London+2, UTC+2, NY+7.

    Only with NY+7 does the broker's 00:00 equals 5 PM ET and the start of a daily bar (and H4) is the start of a new FX day.

    GMT/BST brokers, means there is a 1 or 2 hour D1/H4 bar on Sunday (depending on NY DST), and a short Friday bar. (Problems with indicators based off bars.)

    GMT+2 is close but doesn't adjust for NY DST.

    EET is closer, except when their DST doesn't match NY's. Last Sunday of March and 1:00 on the last Sunday of October vs second Sunday in March and return at 2:00 AM EDT to 1:00 AM EST on the first Sunday in November.

  4. Non-NY+7, means the chart daily bar overlaps the start, and converting broker time to NY time requires broker to UTC to NY timezone conversions.


  5. If you search the web, you will find differing answers. Those are all wrong (half the year) because they do not take DST into account (or that it changed for the US in 2007 [important when testing history.])


  6. Then there are (non-24 hour markets) with H4 candles that start on odd hours.
              Why My XAUUSD 4H candles start with 1 hour shift? - Currency Pairs - General - MQL5 programming forum (2019)
              H4 first opened candle - MT5 - General - MQL5 programming forum (2020)

    And H1 on the half hour.

  7. See also Dealing with Time (Part 1): The Basics - MQL5 Articles (21.10.01)
    and Dealing with Time (Part 2): The Functions - MQL5 Articles (21.10.08)

Reason: