Building Higher-Timeframe OHLC Bars from One-Minute Data
Summary
The document explains how to convert one-minute price data into longer timeframe bars for strategy analysis or backtesting. Selecting every 240th candle would discard most observations and would not preserve the information needed to form a four-hour bar.
Instead, aggregate all lower-timeframe candles within each target interval: take the first candle’s open, the maximum high, the minimum low, and the final candle’s close. The answer points to an R package as one possible implementation and suggests that equivalent tools may exist in other languages. It gives the aggregation rule but no code, package details, or empirical comparison. Correct interval boundaries and handling of incomplete bars are not discussed, so those choices still need to be defined for a particular dataset and backtest.
Key ideas
- A higher-timeframe bar should summarize every lower-timeframe candle in its interval.
- Use the first open, highest high, lowest low, and last close when aggregating OHLC data.
- Taking every Nth candle alone does not produce a valid OHLC summary of the intervening data.
- Choose interval boundaries and decide how to handle incomplete bars for the dataset.
Tags
Full text
# Converting timeframe of a time series # Converting timeframe of a time series So I've encountered a problem - I have a lot of 1 min data, but my strategy works better on longer timeframes and backtrader has some problems with backtesting on 1 mln rows. I want to convert it to 1h/4h/1d timeframes, tried to convert to 4h just by selecting every 240th candle but not sure that's the right way, any thoughts on how to do it? ## Answer by Bob Jansen (score 3) https://quant.stackexchange.com/a/66061 You need to get the open of the first candle, the high and low over all candles in the time frame and the close of the last candle. R has a package for this, your language of choice might have it as well.
Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.