For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See:

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 ?

    IndexError: array index out of range

    Indicator class

    class RatioInd(bt.Indicator):
        lines = ('line',)
        params = (('period', 20),)
        def __init__(self):
        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
    ==> TLT_D.csv <==
    Date,Open,High,Low,Close,Adj Close,Volume

Log in to reply