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/

    Got IndexError: array index out of range if preload=False

    Indicators/Strategies/Analyzers
    2
    3
    86
    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.
    • Yacc Don
      Yacc Don last edited by

      Hi,

      I want to caculate growth each day, so I did like this in strategy:

      class UserStockStrategy(bt.Strategy):
          def __init__(self):
              exp_variables["growth"] = (self.data.close - self.data.close[-1])/self.data.close[-1]
      

      Everthing is OK, until I run cerebo with preload=False

          cerebro = bt.Cerebro(runonce=False, preload=False)
      

      The I got IndexError:
      IndexError: array index out of range

          exp_variables["growth"] = (self.data.close - self.data.close[-1])/self.data.close[-1]
        File "/home/user/.local/lib/python3.7/site-packages/backtrader/linebuffer.py", line 163, in __getitem__
          return self.array[self.idx + ago]
      IndexError: array index out of range
      

      Could anybody help me, thanks

      @ab_trader @backtrader

      vladisld 1 Reply Last reply Reply Quote 0
      • vladisld
        vladisld @Yacc Don last edited by

        @yacc-don please take a look at delayed indexing docs: https://www.backtrader.com/docu/concepts/#lines-delayed-indexing

        Yacc Don 1 Reply Last reply Reply Quote 2
        • Yacc Don
          Yacc Don @vladisld last edited by

          @vladisld Thanks

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