Detecting a New Bar by Comparing Its Timestamp
Summary
This programming note describes a method for detecting when a new market bar appears. It stores the latest bar timestamp in a static variable, retrieves the current latest-bar time through a series information function, and compares the current time with the stored value. On the first call, it initializes the stored timestamp and returns false; on later calls, a changed timestamp signals a new bar and returns true, after which the stored value is updated.
The note also describes checking the data-retrieval call’s result and reporting an error if the timestamp cannot be obtained. This is a utility pattern for event timing in trading software, not a trading signal or strategy. It provides no timing benchmarks, platform version details, or guidance on handling unavailable history beyond checking the error code, so implementations should account for data readiness and API behavior in their environment.
Key ideas
- The method stores the last observed bar timestamp in persistent state.
- It retrieves the latest bar time and compares it with the stored timestamp.
- The first call initializes the stored time and does not report a new bar.
- A changed timestamp updates the stored value and signals a new bar.
- The retrieval result should be checked for errors.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.