Aggregating Base Candles into Custom Timeframe Bars
Summary
This utility describes how to combine a stream of lower-timeframe candle records into bars of a user-selected duration. It aligns each generated bar to the duration boundary, carries forward the first open, updates the high and low as source records arrive, uses the latest close, and sums volume. A rolling buffer retains a configurable number of completed or current bars for display or further use.
The notes address an important data-feed detail: the latest source candle may still change, so the aggregator permits updates to the current interval while rejecting records that arrive out of order. The requested interval should be an integer multiple of the source record interval, though the implementation does not check this. The included example repeatedly fetches records and plots the synthesized bars. This is a data-handling technique rather than a trading strategy, and the sample contains implementation issues, including a malformed ticker path and a misspelled volume field, that users would need to resolve before relying on it.
Key ideas
- Custom bars are aligned by flooring each source timestamp to the selected interval boundary.
- The first source value initializes a bar's open, while later records update its high, low, close, and volume.
- The latest interval can be revised as source candle data changes, and older out-of-order records are ignored.
- The source interval should divide evenly into the target duration, but the example does not validate this condition.
- The provided sample includes apparent coding errors that could prevent correct operation.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.