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

Indicator periods by time instead of bars

  • Hello backtrader community,

    I was wondering if it is possible to make indicators by using time instead of bars for the "period". I think if i want to use an indicator and tick data together now, I would have to import two separate data feeds of the same data. One as ticks and one re-sampled as candles/bars.

    Anyone have any suggestions to get around having to do that?

  • administrators

    Nothing prevents you from having a parameter to your indicator which is quoted in time units (seconds, minutes, ...). But tha won't change what an indicator does: follow the pace of the data feed (which may be another indicator) delivery of bars.

    Your time-based indicator may choose to only deliver signals at given times based on the parameter, but it will still be delivering a value for each bar of the data feed (if you do nothing, the default value delivered by an indicator is NaN)

  • So its impossible to get a 10m moving average indicator if you dont re-sample ticks to some denomination of minutes/second bars?

  • administrators

    If by 10m you mean 10-minutes, yes you are right. You need a data series which is 1-minute based to get a 10-minutes moving average. Resampling to 1-second would allow you to get a 10-seconds moving average.

    As quoted above, you can develop an indicator, take a parameter which indicates time and deliver the output yourself after 10 minutes. But the indicator will have as many data points as ticks, because it's running on the tick-based data series. It will only output a sensible value each 10-minutes though.

    There may be something from your message which is not being understood here.

  • Ok that makes sense. Il just re-sample to something like 1 second since the amount of ticks within a certain amount of time isnt consistent.


Log in to reply