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/

    Customer indicator. Data synchronization issue.

    General Code/Help
    1
    1
    32
    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.
    • Alexander Nesm
      Alexander Nesm last edited by

      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
      
      
      1 Reply Last reply Reply Quote 0
      • 1 / 1
      • First post
        Last post
      Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
      $(document).ready(function () { app.coldLoad(); }); }