Skip to content
All library documents

Combining Fine-Grained Crypto Data with Higher-Timeframe Backtests

Article Quant Q&A · Author: Amin Saqi

Summary

The document addresses backtesting crypto strategies that calculate indicators on daily candles while processing finer-grained data for entries, exits, and risk controls. Its accepted answer recommends using Backtrader’s data replay feature with minute data to construct daily-timeframe updates. Other responses suggest exchange candle data, or building a custom loop that tracks trades or short-interval candles separately from the higher-timeframe bars used for indicators.

The discussion highlights why data resolution matters: candle closes alone may miss stop-loss triggers or entries and exits that occur within a bar. One proposed custom workflow prebuilds candles for comparison, updates them as fine-grained observations arrive, and recalculates indicators when a candle is complete. The advice is a set of implementation options rather than a tested comparison. Tick availability, intrabar assumptions, exchange data coverage, and framework capabilities limit how faithfully any backtest can reproduce live execution.

Key ideas

  • Higher-timeframe indicators can be paired with finer-grained data for strategy decisions.
  • Backtrader’s replay feature is presented as a way to replay minute data into daily bars.
  • Fine-grained observations help simulate stops and trades that occur within a candle.
  • A custom backtest can update candles from trades and refresh indicators when each bar completes.
  • Backtest realism depends on data coverage and assumptions about intrabar execution.

Tags

Full text
# Python library for tick-based backtesting on cryptos


# Python library for tick-based backtesting on cryptos












I saw and reviewed many python backtesting libraries - pyalgotrade, zipline, catalyst, backtrader, etc.

It seems that none of the provide a straightforward way to perform "Tick-based or Multi-timeframe backtesting on CRYPTO".

- pyalgotrade seems to be only close-based.

- zipline is for stocks.

- catalyst (a fork of zipline) can simulate ticks with 1min closes, but their data provider for data ingestion is down.

- backtrader seems to be only close-based.

What I want to achieve

I want to perform backtests such that:

- Indicators being calculated with daily timeframe data.

- Main loop progress with tick-based data or at least like zipline (with closes of a shorter timeframe, like 1min).

And I need feature two for the following:

- being able to simulate stop-losses, i.e. within candle body or shadows - not only in candle close.

- being able to backtest intra-bar strategies, so it could simulate entry and exits within body of a single bar.

Thanks in advance.

## Answer by Amin Saqi (score 1, accepted)

https://quant.stackexchange.com/a/65800

backtrader's Data Replay feature, does exactly what I was looking for. So, all you need to do is the following:

- Create a CSV data file with 1min timeframe.

- Load the data into a CSV data feed of backtrader.

- Pass the data feed to cerebro (backtrader's engine) with `replaydata` utility.

- Finally, add a strategy and other steps.

A code example to use `replaydata` is like the following:

```
cerebro.replaydata(minuteDataFeed,
                   timeframe=TimeFrame.Days,
                   compression=1)
```

## Answer by Hamish Gibson (score 0)

https://quant.stackexchange.com/a/60912

Have you tried using ccxt? This library is available on GitHub and offers most of what you’re looking for. It offers minutely candle data from several dozen exchanges as well as a backtesting framework which implements indicators really well. I’m not sure if they offer intra-candle strategies but their features support what you’re looking for otherwise.

## Answer by YohjiNakamoto (score 0)

https://quant.stackexchange.com/a/64214

I have been looking for it also, and I don't think anything is able to do that. I personally re-built some backtrading program, and I think it's pretty straightforward to do especially with Pandas' ability to resample data by time and build candles from it. https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.resample.html

You have 2 set of data:

- The ticks/trades, over which you look in real time to compute your balance, stop loss, take profit etc. Could be 1 minute candles also (and you use the "close" data as the tick, or could be live ticks).

- The candles on which you build your indicators etc, that you can also build on-the-go as you loop over your ticks-trades. Personally, I pre-build the candles with pandas so I can "verify" that the live-built data from the trades matches exactly. And I also use the pre-computed candles to know at which time I should recompute the indicators (because when you loop over all the ticks/trades, you won't recompute the indicators every time, you have to wait for the candle to be completely built)

As for getting the data... You can get pretty good 1 minute candles (200 days) from Binance, or full trade history from Kraken from the API. Those are free and easy to get, maybe there are other ones.

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.