For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
question on replay
-
Hello, backtrader. I have a question on replay. pls see the following.
class SmaCross(bt.Strategy): def __init__(self): self.SMA0 = bt.ind.MovingAverageSimple(self.data0, period=5) self.SMA1 = bt.ind.MovingAverageSimple(self.data1, period=5) def next(self): pass if self.data0.datetime.datetime() == datetime.datetime(2010, 1, 1, 12, 19) or self.data0.datetime.datetime() == datetime.datetime( 2010, 1, 1, 12, 18): print(self.data0.datetime.datetime(), 'd1_sma', self.SMA1[0], 'd1_sma[-1]', self.SMA1[-1]) ########################## # main ######################### cerebro = bt.Cerebro() data = bt.feeds.GenericCSVData( dataname='./candles00.csv', timeframe=bt.TimeFrame.Minutes, ) # 1 minute bar cerebro.adddata(data, name='1min') cerebro.replaydata(data, timeframe=bt.TimeFrame.Minutes, compression=60, name='60m') # 60 minute bar cerebro.addstrategy(SmaCross) cerebro.broker.setcash(10000) results = cerebro.run()
and the following is the output.
I expect that sma[-1] for data1 at 12:19 should be equal to sma[0] at 12:18, but they are not. I wonder how to make them equal.