Skip to content
All library documents

Correcting Economic Calendar Timestamps for Historical Backtests

Article MQL5 code base

Summary

The document explains why economic calendar events can become misaligned with historical price bars in backtests. Bars retain the server time zone and timestamps used when they were formed, while calendar records may be shown in the server’s current time zone. Daylight saving changes, broker time-zone changes, and differing national schedules can shift event times relative to the quotes, potentially undermining news-based strategy tests.

The described workflow exports calendar records to a cache, optionally correcting timestamps by comparing them with historical hourly quotes for a selected symbol. The corrected cache can then be loaded for testing or optimization; the correction is intended to run online after filling a cache from the built-in calendar, not on an already adjusted cache or in the tester. Logged adjustment boundaries help inspect the changes. This is an implementation guide rather than evidence of improved strategy performance. Its accuracy depends on suitable quote history and correct use of the correction step, since applying adjustments twice can produce erroneous times.

Key ideas

  • Historical bars keep their original server timestamps while calendar event times can reflect a later server time zone.
  • Daylight saving differences and broker time-zone changes can misalign news events and historical quotes.
  • The workflow caches calendar records and can adjust event times using historical hourly quotes for a chosen symbol.
  • Corrections should be applied online to a freshly populated cache, because repeating them can corrupt timestamps.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.