Time on Charts is Different to my Local Time

 

Good afternoon forum!

First time post here so please be kind lol, nice to meet you! I have attached a screenshot to highlight my problem:

It was just after 4pm here in the UK (and I'm looking at GBP/USD) so I would imagine the time on the chart should match. However, as you can see on my chart, the time was two hours ahead. Could somebody either 1) explain how to change this to match, or, 2) Inform me why it is the way it is please.

I have an EA I was trying to run that will only work between a certain time window and it stopped at 5pm. I thought I had just under an hour left to explore but nothing happened and that is when I realised the time on the chart didn't match so I assume it was using that to enforce the parameter which, understandably, is not ideal.

Thank you in advance for your help! PercivalP. 

Files:
 

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 of 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)

 
PercivalP:

Good afternoon forum!

First time post here so please be kind lol, nice to meet you! I have attached a screenshot to highlight my problem:

It was just after 4pm here in the UK (and I'm looking at GBP/USD) so I would imagine the time on the chart should match. However, as you can see on my chart, the time was two hours ahead. Could somebody either 1) explain how to change this to match, or, 2) Inform me why it is the way it is please.

I have an EA I was trying to run that will only work between a certain time window and it stopped at 5pm. I thought I had just under an hour left to explore but nothing happened and that is when I realised the time on the chart didn't match so I assume it was using that to enforce the parameter which, understandably, is not ideal.

Thank you in advance for your help! PercivalP. 

It's normal.

1) You can't.

2) The charts are using the broker server time, which can be anything in theory.

 
PercivalP:

Could somebody either 1) explain how to change this to match, or, 2) Inform me why it is the way it is please.

More information for you... What you are expecting to be able to do, (1), is arguably the most frequently requested missing feature in the MT4 and MT5 platforms. Two [EDIT] Three main reasons why it's the case:

  • Changing the time zone would change the candle data on all periods above H1. There can no longer be a single set of daily candles etc; they would vary depending on your chosen time zone. That should in theory not pose a huge problem in MT5, but MT4 is heavily based around pre-prepared candle data for each separate timeframe.
  • While the MT5 application might be able to create candles quite easily based on a user's choice of time zone, the MQL5 programming environment contains no support for the idea that charts can have varying time zones, and no support for requesting data with caller-configurable time zones. 
  • Brokers like the lack of ambiguity. It's easier to resolve support queries if everyone is using the same zone when they quote times at each other.

Even more detail: if you are in the UK, it's probably the case that your chart will not always be two hours ahead. There will be a brief period twice a year when it's three hours ahead. That's because your broker almost certainly changes their times based on the US daylight savings schedule rather than the European one. The US summer time extends before and after the European window, and during those periods your broker will [probably] operate at GMT+3 while you are at GMT+0.

And for information about why that's the case, there's been a very recent discussion of it from a different perspective.

 

Thank you, all three of you!

I'll do some further reading with the links you have supplied before bed but just quickly, so i'm ready to tinker with my bot in the morning...

I assume EA's follow the broker's timezone so (now being aware I need to also remember and account for when the clocks change) in this case:

If I only want my bot to trade between 7am and 5pm UK time and the clock is currently two hours ahead, will I need to change my code to between 5am and 3pm OR does the code within an EA use my machine's CORRECT local time in it's calculations?

//--- Parameter settings (This is my current snippet of code)

      input int            i_nTradeStart         = 0700,              // Trade Start Time ("hhmm" format)

                           i_nTradeDuration     = 1000;              // Trade Duration Time ("hhmm" format)

 

PercivalP #: Thank you, all three of you! I'll do some further reading with the links you have supplied before bed but just quickly, so i'm ready to tinker with my bot in the morning... I assume EA's follow the broker's timezone so (now being aware I need to also remember and account for when the clocks change) in this case: If I only want my bot to trade between 7am and 5pm UK time and the clock is currently two hours ahead, will I need to change my code to between 5am and 3pm OR does the code within an EA use my machine's CORRECT local time in it's calculations?

//--- Parameter settings (This is my current snippet of code)

      input int            i_nTradeStart         = 0700,              // Trade Start Time ("hhmm" format)

                           i_nTradeDuration     = 1000;              // Trade Duration Time ("hhmm" format)

This is very important — Where did you get that snippet of code?
 

ChatGPT.

Does my EA use my machine's local time or the brokers?

 
PercivalP #:

ChatGPT.

Does my EA use my machine's local time or the brokers?

ROFL.

Your question is impossible to answer without seeing the full code because it depends on what ChatGPT has copied and re-arranged in order to create your EA. It will probably be broker time - to the extent that the code actually carries out any coherent trading actions.

The mentions of ChatGPT on this forum are getting quite funny (and MetaQuotes are pouring kerosene on the fire by adding ChatGPT integration into MetaEditor). As an admittedly naive experiment, I've just asked ChatGPT to write code for trading Bollinger Band breakouts, and what it gave me has the following characteristics:

  • Doesn't actually compile
  • If it did compile, then it would have a number of major bugs - because, of course, ChatGPT doesn't actually understand what it's re-writing. For example, it has a stop-loss distance in pips as a configurable parameter, it converts that to a price amount, but that block of code which it's copied is redundant because it then submits the original number in pips as the stop-loss price on the order.
  • Even if I fixed those problems, the code would still contain a critical shortcoming: it would continually trade the same breakout over and over again on each successive tick
  • And if I fixed that, then...  I've got a strategy where the code works, but is never going to be profitable because simply trading Bollinger Band breakouts is not profitable
There are some things which ChatGPT is brilliant for. A friend of mine is regularly using it to write policy documents for banks and regulators. But ChatGPT isn't doing the "intelligent" part. That lies in my friend knowing what question to ask, and what needs to be changed in the template which ChatGPT produces. What ChatGPT is doing is removing the drudgery of writing routine prose, comparable to Excel saving you from having to add up numbers yourself. That is not, in the immediate future, readily translatable to writing computer code.
 
PercivalP #: ChatGPT.

That would be impossible unless you put it there yourself, CPerry. Please note that having more than one account is against Terms of Use of MQL5 community ( 12.11 ).

PercivalP #: Does my EA use my machine's local time or the brokers?

Your EA (the one I coded for you back in December) uses the trade server time.

 
PercivalP #:

ChatGPT.

Does my EA use my machine's local time or the brokers?

  1. What part of “Chart times are broker times” was unclear to you? #1

  2. Stop using ChatGPT.
              Help needed to debug and fix an AI EA - Trading Systems - MQL5 programming forum (2023)

    ChatGPT (the worst), “Bots Builder”, “EA builder”, “EA Builder Pro”, EATree, “Etasoft forex generator”, “Forex Strategy Builder”, ForexEAdvisor (aka. ForexEAdvisor STRATEGY BUILDER, and Online Forex Expert Advisor Generator), ForexRobotAcademy.com, forexsb, “FX EA Builder”, fxDreema, Forex Generator, FxPro, Molanis, Octa-FX Meta Editor, Strategy Builder FX, Strategy Quant, “Visual Trader Studio”, “MQL5 Wizard”, etc., are all the same. You will get something quick, but then you will spend a much longer time trying to get it right, than if you learned the language up front, and then just wrote it.

    Since you haven't learned MQL4/5, therefor there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into yours.

    We are willing to HELP you when you post your attempt (using Code button) and state the nature of your problem, but we are not going to debug your hundreds of lines of code. You are essentially going to be on your own.

    ChatGPT
    1. Even it says do not use it for coding.*
    2. Mixing MT4 and MT5 code together.
    3. Creating multiple OnCalculate/OnTick functions.
    4. OnCalculate returning a double.
    5. Filling buffers with zero in OnInit (they have no size yet). Setting buffer elements to zero but not setting Empty Value to correspond.
    6. Calling undefined functions.
    7. Sometimes, not using strict (MT4 code).
    8. Code that will not compile.
    9. Creating code outside of functions.*
    10. Creating incomplete code.*
    11. Initialization of Global variables with non-constants.*
    12. Assigning a MT5 handle to a double or missing the buffer and bar indexes in a MT4 call.*
    13. Useing MT4 Trade Functions without first selecting an order.*
    14. Uses NULL in OrderSend.*
    bot builder Creating two OnInit() functions.*
    EA builder
    1. Counting up while closing multiple orders.
    2. Not useing time in new bar detection.
    3. Not adjusting for 4/5 digit brokers, TP/SL and slippage.*
    4. Not checking return codes.
    EATree Uses objects on chart to save values — not persistent storage (files or GV+Flush.) No recovery (crash/power failure.)
    ForexEAdvisor
    1. Non-updateing global variables.
    2. Compilation errors.
    3. Not checking return codes.
    4. Not reporting errors.
    FX EA Builder
    1. Not checking return codes.
    2. Loosing open tickets on terminal restart. No recovery (crash/power failure.)
    3. Not adjusting stops for the spread .*
    4. Using OrdersTotal directly.
    5. Using the old event handlers.

Reason: