Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    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

    General Discussion
    1
    1
    68
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Li Mike
      Li Mike last edited by

      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.
      QQ图片20210327102135.png

      1 Reply Last reply Reply Quote 0
      • 1 / 1
      • First post
        Last post
      Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors