Skip to content
All library documents

Aligning Multi-Hour Bars to Fixed Exchange Time Boundaries

Article vn.py community

Summary

The discussion examines why VeighNa’s BarGenerator can produce multi-hour bars whose boundaries depend on when a strategy starts. It attributes the issue to windows being counted from the first hourly bar received, rather than from a fixed exchange-time anchor. That can shift two-, four-, or six-hour bars relative to the exchange’s schedule, while shorter intervals may be unaffected according to the original question.

Three possible approaches are presented: extend the generator with a fixed anchor hour, aggregate hourly bars in strategy code, or delay startup until an aligned time. The examples illustrate the intended designs, but should be treated as sketches rather than verified drop-in fixes. In particular, time zones, trading sessions, overnight boundaries, missing bars, and the exact timestamps used by the data feed all affect alignment. The discussion offers no tests or comparison against exchange data, and its sample aggregation and waiting logic may need adaptation before live use.

Key ideas

  • The described misalignment arises when multi-hour windows are counted from the first bar received after startup.
  • A fixed exchange-time anchor can make generated bar boundaries independent of strategy launch time.
  • The proposed options are a customized generator, strategy-level aggregation, or waiting for an aligned start.
  • Trading sessions, time zones, missing bars, and timestamp conventions need to be handled in a real implementation.
  • The code is illustrative and the document provides no validation against exchange bar data.

Tags

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