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

Custom indicator with resampled data



  • Hi,

    I'm having some trouble applying a simple indicator to a data feed that has been resampled.

    I've taken code from the quickstart (in the "Adding an indicator" section). I made three changes:

    1. Resample the data to weekly:
      cerebro.resampledata(data, timeframe=bt.TimeFrame.Weeks, compression=1)

    2. Create a new indicator, based on the SMA indicator:
      self.sma_filter = self.datas[0].close > self.sma
      bt.LinePlotterIndicator(self.sma_filter, name='SMA filter')

    3. Add plotting to the end of the script:
      cerebro.plot(style='candlestick', barup='green', bardown='red', volume=False)

    So, the new indicator "sma_filter" should output a 1 when the close is above the SMA, and 0 otherwise. This works ok when the data is not resampled:

    0_1543707628057_Figure_0.png

    However, with the resampling, the plot shows the new indicator offset to the left by 1 bar:

    0_1543707672020_Figure_1.png

    You can see cases where the close is below the SMA, it outputs "1", and cases there the opposite occurs. Are there any ideas what I'm doing wrong?


Log in to reply
 

});