Skip to content
All library documents

Building Higher-Timeframe Candles from Lower-Timeframe Data

Article FMZ digest · Author: 发明者量化-小小梦

Summary

The document explains how to combine existing candles into a larger target interval when an exchange or data source does not provide that interval. Its example infers the source interval from the final two records, checks that the requested interval is an integral multiple and aligns with a day or hour, then aggregates open, high, low, close, time, and volume across source candles. It also describes adapting the procedure from JavaScript to Python, including a timezone-offset adjustment used to identify candle boundaries.

The author illustrates the result with a synthesized four-hour chart based on Huobi market data and a backtest chart. These visuals show an example output, but the document gives no quantitative comparison or performance evidence. It warns that the implementation is for reference and should be modified and tested for the intended strategy. The sample also relies on assumptions about timestamp units, timezone handling, and the ordering and spacing of input records, so users should check those details against their own data.

Key ideas

  • Larger candles can be synthesized by aggregating lower-interval records when the desired interval is unavailable.
  • The target interval must be an integral multiple of the inferred source interval and satisfy the code's cycle-alignment checks.
  • Aggregated candles retain the first open and time, track the maximum high and minimum low, use the last close, and sum volume.
  • The example uses timezone-adjusted timestamps to determine where target candles begin.
  • The included chart examples are illustrative, and the implementation needs testing against the intended data and strategy.

Tags

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