For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See:

[Enhancement?] Resampler support for non-time-based bars (e.g. range, tick)

  • administrators

    From to keep a reference for the future

    Has there been any interest in supporting tick-based (i.e. 89-tick) or range bars (or Renko, heikin-ashi, etc.). Many platforms seem to support time-based bars only but I've been using range-based bars almost exclusively for the past few years and thought I'd ask if it were planned before I jump in and try to implement it myself. I have a script that creates OHLC range bars from tick data for back-testing but haven't yet found where similar logic would need to be inserted for "live trading" from streamed tick data from Oanda for example.

    Thanks for a great platform thus far - the Oanda support was rather timely ;).


  • administrators

    The tick data, from for example Oanda can be resampled to any larger timeframe. This was added in October 2015

    The issue is not if the data is tick data but in which format is presented. Many times this is a pair of bid/ask prices. Following a discussion in a issue a blog post came out as to how to load bid/ask data directly into backtrader using the GenericCSVData.

    The sample chooses the bid field as the price for the tick by telling the GenericCSVData sample that open, high, low and close can all be found at position 5.

    In this sample the ticks are simply compressed, but nothing prevents to give the cerebro.resampledata a timeframe argument to resample the ticks to a larger timeframe

    For range bars there has been nothing. Although backtrader tries to be as time agnostic as possible, things happen with a timestamp and some parts do always expect a datetime field. This is possibly not a large obstacle to implement range bars, but it has to be looked into with some care.

  • Hi @backtrader,

    To start with, congratulations for the neat framework you have here came up with. Have been fiddling around since few weeks ago with it, and i am surprised with the simplicity of use, yet powerful abilities available.

    Going to the subject under discussion, I would like to give it a go and try some implementation of different bars, initially with Heikin-Ashi and later on with Renko or Range bars.

    The first question would be if you have any advice on where to plug the code for those bars? After looking into backtrader docs, i wonder if Filters are the right way to do it, after looking at it's description:

    'Filters transform the values provided by a data feed to deliver a different data feed' ?
    Or rather one shall just previously compute the bars and just add them as a regular datafeed to cerebro? Obviously this would loose later on the live trading ability and just be useful for backtesting purposes.

    As for the issue with datetime stamping observations for price based bars, i don't see an issue there, as from my pov they shall have anyhow a time-stamp associated with the time they were started/per observation, therefore comparable with regular bars, just not with a regular interval. Apart from plotting which shall be non sense, the rest should work. Does this make any sense?


Log in to reply