@run-out said in How to use 5minutes BOLL and 10 minute BOLL together?:
A few things to help you on your way.
You don't need to add data with resample. Resample will add the date automatically.
Also, you use the variable
self.lines.top
twice. Finally, I would avoid using the .lines. Not sure if there's an impact here but lines are an important word inside backtrader.I've rewritten your code a bit to help you out.
import backtrader as bt class Strategy(bt.Strategy): params = (("bb_period", 22),) def __init__(self): self.bb = bt.indicators.BollingerBands(self.datas[0], period=self.p.bb_period) self.bb5 = bt.indicators.BollingerBands(self.datas[1], period=self.p.bb_period) self.bb30 = bt.indicators.BollingerBands(self.datas[2], period=self.p.bb_period) def next(self): print( "OHLCV", bt.num2date(self.data.datetime[0]), self.datas[0].close[0], self.datas[1].close[0], self.datas[2].close[0], ) print( "Bollinger Bands\n", "minute", self.bb.top[0], self.bb[0], self.bb.bot[0], '\n', "5 min", self.bb5.top[0], self.bb5[0], self.bb5.bot[0], '\n', "30 min", self.bb30.top[0], self.bb30[0], self.bb30.bot[0], '\n', ) if __name__ == "__main__": cerebro = bt.Cerebro() data = bt.feeds.GenericCSVData( dataname="data/dev.csv", dtformat=("%Y-%m-%d %H:%M:%S"), timeframe=bt.TimeFrame.Minutes, compression=1, date=0, high=1, low=2, open=3, close=4, volume=6, ) cerebro.adddata(data) cerebro.resampledata(data, timeframe=bt.TimeFrame.Minutes, compression=5) cerebro.resampledata(data, timeframe=bt.TimeFrame.Minutes, compression=30) cerebro.addstrategy(Strategy) # Execute cerebro.run()
cool, works charm, thanks a lot