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

How to initialize indicators for each data in self.datas?

  • The following create errors

    class PriceRelative(bt.Indicator):
        ''' x_t = Close_t/Close_{t-1} '''
        lines = ('PriceRelative', )
        def __init__(self):
            self.lines.PriceRelative = bt.indicators.RateOfChange(, period=1)+1
    class Test(bt.Strategy):
        def __init__(self):
            for a in self.datas:
                a.relative = PriceRelative(

    How can i fix this so that I can initialize my indicator for each data.close?

  • This has been discussed. Try this thread .

Log in to reply