Skip to content
All library documents

Aggregating Intraday Records into Four-Hour Candles

Article FMZ forum · Author: 伊利丹

Summary

The document demonstrates a routine for combining shorter-period market records into four-hour OHLCV bars. It first examines timestamps and discards records until it encounters a bar whose hour matches a four-hour boundary. It then processes records in groups of four, taking the first open, highest high, lowest low, and last close to create each aggregated bar. A small example retrieves exchange records and plots the resulting series for visual comparison.

The example indicates how candle aggregation can support analysis at a coarser timeframe, but it provides no quantitative validation or trading results. The implementation assumes that input records are evenly spaced and aligned to the intended session and timezone. It also sets aggregated volume from only the last constituent record rather than summing all four, and its fixed grouping and incomplete-tail handling may produce inaccurate bars. Users need to verify timestamp alignment, missing records, session boundaries, and volume semantics against their data source.

Key ideas

  • Four consecutive records are combined into a single four-hour bar using the first open, maximum high, minimum low, and final close.
  • The routine discards leading records until it finds a timestamp on a four-hour clock boundary.
  • Its example sets aggregate volume from the final input record instead of summing the constituent volumes.
  • Fixed groups of four assume evenly spaced, correctly aligned records and require careful handling of missing or partial bars.
  • The document suggests visual comparison but provides no accuracy study or strategy performance results.

Tags

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