Handling DST transitions when backtesting a time-based strategy

Discussion in 'Automated Trading' started by rmu, Jun 16, 2025 at 10:59 AM.

  1. rmu

    rmu

    Hello,

    What's the best way to backtest a strategy using MT4/5 that requires the start/end time specified in the EA to match the correct time point in the chart/history, taking into account the winter/summer time changes and the discrepancies where New York and London DST are out of sync for one hour?

    For example the EA should trigger a trade at the start of the London Session (which is 8:00 AM London time throughout the year)

    Assuming I use historical data in GMT+0 from a broker that uses New York as the basis for its DST setting, would the backtest then really hit the right spot every day over an entire year (or longer) if "08:00" was specified as the "start time" in the EA settings?

    Thank you in advance for your support!
     
  2. Cam12

    Cam12

    inspect a few individual trades/days around the DLST shift to see if they triggered at the right time or an hour late
     
    rmu likes this.
  3. rmu

    rmu

    Thanks.

    I've now found a way to always have the London Open at the same time at 8:00 for my backtest. I do this by using GMT offset 0 and EU DST. This way, "8:00" will always match the real 8:00 AM London time.

    It would be even better, however, if I could have the historical data in a uniform format where ALL session opening/closing times throughout an entire year would always be at the same timestamp.
     
    Last edited: Jun 18, 2025 at 6:10 AM
  4. trismes

    trismes

    All brokers using MT4/5 do it differently. Some brokers vary by symbol. Unbelievable.

    If you want some sanity, MQ demo server works consistently on GMT+2, GMT+3 DST across all symbols. This script will tell you what a given price feed is running on: https://www.mql5.com/en/code/48650

    To incorporate US discrepancies, you'll have to run the backtest in batches accounting for this, and stitch results together. Ugly I know.

    MQ price feed is shaded however, and depending on times when you trade you may have issues in real life. Be warned.
     
    rmu likes this.
  5. rmu

    rmu

    Thanks. I don’t use the MQ price feed. I have the Tick Data Suite to export historical tick data from different brokers using a custom timezone / DST (NY/EU) but so far i haven’t found a way to get the data in a way where all session opening/closing times could be found at the same place / time stamp throughout the entire year / backtest period.
     
    trismes likes this.
  6. trismes

    trismes

    Good work - similar, I model off spot then add shading after.
    I gave up on MT5 for testing because of this and other anomalies, but if you can wrangle decent results then I admire your patience
     
  7. rmu

    rmu

    Not sure what you mean by „model off spot then add shading after“

    Well, i haven’t looked at MT4 yet but i guess even while it integrates directly with TDS, the 4 major session opening/closing times (Sydney, Tokyo, London, New York) couldn’t be found at the same bar‘s time stamps consistently throughout the year.

    Maybe you need to add code to the EA to automatically shift the session times based on the different countries timezones comparing it with GMT+0 to deliver accurate results when it comes to executing orders at the correct session open/closes bars.
     
  8. trismes

    trismes

     
  9. rmu

    rmu

    Ok. Well i didn’t say i was going to trade an EA but it could certainly help to backtest the strategy behind it. However this would at least require me to find out how to solve the timing/dst problematic without having to run multiple backtests on batches of historical data.
     
  10. trismes

    trismes

    Don't. MT is not suitable for live trading in any circumstances. The broker terminal has back-end shading functions to deliver you a 'special price' when live.

    Great for charting, for backtests it has its uses, but my suspicion is even those are tilted towards artificial success. Yes, you can easily script something to sort DST but it's not native... and then do you really trust the results of a program known for screwing over its client base?