Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. Alexander Nesm
    3. Posts
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
    • Profile
    • Following 0
    • Followers 0
    • Topics 1
    • Posts 1
    • Best 0
    • Groups 0

    Posts made by Alexander Nesm

    • Customer indicator. Data synchronization issue.

      Hi everyone,

      I try to create customer indicator with two datafeeds. However, indicator instance creation fails with error because
      data0 and data1 have different start & end dates. How do I synchronize datas ?
      Error

      IndexError: array index out of range
      

      Indicator class

      class RatioInd(bt.Indicator):
          lines = ('line',)
          params = (('period', 20),)
      
          def __init__(self):
              self.addminperiod(self.params.period)
      
          def next(self):
              self.lines.line[0] = self.data1.close[0]/self.data0.close[0]
      

      Indicator instance:

      class TestStrategy(bt.Strategy):
      ...
          def __init__(self,exclfromdate, excltodate, ticker):
              self.RATIO = RatioInd(self.datas[0], self.datas[1], period=20)
          
      

      Data is not in sync:

      ==> QQQ_D.csv <==
      Date,Open,High,Low,Close,Adj Close,Volume
      1999-03-10,51.125000,51.156250,50.281250,51.062500,44.792862,5232000
      
      ==> TLT_D.csv <==
      Date,Open,High,Low,Close,Adj Close,Volume
      2002-07-30,81.750000,81.900002,81.519997,81.519997,43.715279,6100
      
      
      posted in General Code/Help
      Alexander Nesm
      Alexander Nesm
    • 1 / 1