Convert Server Time to Local

 

Hi, is there any way to get the Time Zone of a server?

I have an EA that I want to use on 2 different brokers who operate in different time zones.


I'd like it to only trade within a certain window of time each day, and would prefer to be able to set this time limit to my local time and have the EA convert to whatever time zone the server is in. (And also take care of adjusting for clock changes around BST)


I could subtract TimeLocal() from TimeCurrent(), but its highly unlikely that the Local Client time is at the same number of seconds as the Server, so this is not that accurate.


Thanks

 
  1. IronBadger: Hi, is there any way to get the Time Zone of a server?

    You can ask them.
    1. FX opens 5pm Eastern Time (NY) Sunday and ends 5pm NY Friday. Some brokers start after (6pm is common/end before (up to 15 minutes) due to low volatility.
                Checking for Market Closed - Expert Advisors and Automated Trading - MQL5 programming forum

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

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

      Only with NY+7 does the broker's 00:00 equals 5pm 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 a.m. EDT to 1:00 a.m. EST on the first Sunday in November.

    3. Non-NY+7, means the chart daily bar overlaps the start, and converting broker time to NY time requires broker to GMT to NY timezone conversions.
    4. 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.])
    5. Then there are H4 candles that start on odd hours.
                Why My XAUUSD 4H candles start with 1 hour shift? - Currency Pairs - General - MQL5 programming forum
    When does your broker change TZ because of DST? Do you have NY, London, and your broker's TZ and DST information, (including historical changes?) Only then, with code can you convert session times to UTC to broker's time. You can use offset inputs but then you must maintain them correctly, through all three DST changes when they occur.
  2. IronBadger: I could subtract TimeLocal() from TimeCurrent(), but its highly unlikely that the Local Client time is at the same number of seconds as the Server, so this is not that accurate.

    TZ = (TC - TL + 1800)/3600 + TZlocal.


              how can i detect that 10 seconds to bar close? MT4/EA - MQL5 programming forum 2020.04.24
              Indicators: Zero Lag Timer - Indices - Articles, Library comments - MQL5 programming forum
 

Very helpful, thank you.

I think I would prefer to go through option 2 as then I don't need to worry about any rework if I change a broker.

However I can test my EA out hard coded for now I guess, just to prove if my theory works!



William Roeder:
  1. You can ask them.
    1. FX opens 5pm Eastern Time (NY) Sunday and ends 5pm NY Friday. Some brokers start after (6pm is common/end before (up to 15 minutes) due to low volatility.
                Checking for Market Closed - Expert Advisors and Automated Trading - MQL5 programming forum

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

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

      Only with NY+7 does the broker's 00:00 equals 5pm 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 a.m. EDT to 1:00 a.m. EST on the first Sunday in November.

    3. Non-NY+7, means the chart daily bar overlaps the start, and converting broker time to NY time requires broker to GMT to NY timezone conversions.
    4. 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.])
    5. Then there are H4 candles that start on odd hours.
                Why My XAUUSD 4H candles start with 1 hour shift? - Currency Pairs - General - MQL5 programming forum
    When does your broker change TZ because of DST? Do you have NY, London, and your broker's TZ and DST information, (including historical changes?) Only then, with code can you convert session times to UTC to broker's time. You can use offset inputs but then you must maintain them correctly, through all three DST changes when they occur.
  2. TZ = (TC - TL + 1800)/3600 + TZlocal.


              how can i detect that 10 seconds to bar close? MT4/EA - MQL5 programming forum 2020.04.24
              Indicators: Zero Lag Timer - Indices - Articles, Library comments - MQL5 programming forum