Custom indicator with resampled data
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:
Resample the data to weekly:
cerebro.resampledata(data, timeframe=bt.TimeFrame.Weeks, compression=1)
Create a new indicator, based on the SMA indicator:
self.sma_filter = self.datas.close > self.sma
bt.LinePlotterIndicator(self.sma_filter, name='SMA filter')
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:
However, with the resampling, the plot shows the new indicator offset to the left by 1 bar:
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?