Skip to content
All library documents

Building a Replay Timer That Follows Simulated Market Time

Article MQL5 articles

Summary

This installment explains how to make a chart timer behave consistently in live trading and historical replay. A live timer can use the platform’s current time to count down to the next bar, but that clock does not represent replay time, which can pause or advance at a different rate. The proposed design sends the replay service’s simulated timestamp to the timer through a terminal global variable, encoding the date-time value in a 64-bit numeric container.

The service initializes and removes the shared variable, while the replay loop updates it as ticks advance. The described logic also treats gaps longer than the shortest bar interval as inactive auction periods and adjusts the reported time accordingly. This is an implementation example for a particular MetaTrader replay system, not a general timing standard. The article supplies selected code fragments and describes the intended behavior, but provides no quantitative validation or evidence that the approach works across all platform configurations.

Key ideas

  • A replay timer must use simulated market time because the computer clock does not track pauses or accelerated playback.
  • A terminal global variable can carry the replay timestamp by reinterpreting its bits through a same-width numeric type.
  • The replay service creates and updates the shared time value, and removes it when the service closes.
  • The example detects long tick gaps and changes timer behavior to represent an inactive market period.
  • The design aims to keep timer behavior similar across live trading and replay, but is specific to the platform implementation.

Tags

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