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.



  • 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
    
    

Log in to reply
 

});