Backtrader Community

    • 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/

    IndexError: array index out of range in next()

    Indicators/Strategies/Analyzers
    1
    1
    122
    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.
    • amit.kehat
      amit.kehat last edited by

      Hello,

      I am facing the next issue.
      This is my code:

      class ShortSuperTrend(bt.Indicator):
          lines = ('ShortSuperTrendUp',)
      
          params = (('atr_period', 14), ('Multiplier', 0.6), )
      
          def __init__(self):
            self.atr = bt.talib.ATR(self.datas[0].high, self.datas[0].low, self.datas[0].close, timeperiod=self.params.atr_period)
            self.up = self.datas[0].low - (self.params.Multiplier * self.atr)
            self.up1 = self.up(-1)
            #self.lines.ShortSuperTrendUp = self.up1
               
          def next(self):
            self.up = bt.If(self.datas[0].close[-1] > self.up, bt.Max(self.up, self.up1), self.up[0])
      

      When using indexing with () in the __init__() I am getting the next error:

      TypeError: 'list' object is not callable

      The assignment in the next() function produce the next error:

      IndexError: array index out of range

      My wish is to update self.up with the expression's results for each candle.

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