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

Plotting a ratio without plotting underlying data

  • Dear All,

    I have a custom indicator that just calculates the ratio between 2 data series (data0 / data1). See indicator code and initialization below. I would like to plot the ratio indicator without ploting the 2 underlying series (i deactivate plotting for these series using data0.plotinfo.plot = False)? When i deactivate any of these data series, the ratio indicator automatically disappears. I think it is because the master relationship with underlying data. What is the best way to work around this? Thanks!

    class DivisionIndicator(bt.Indicator):
        _mindatas = 2  # requires two (2) data sources
        alias = ('DVD',)
        lines = ('div',)
        params = (
            ('not_required', 20),
        plotlines = dict(
        def nextstart(self):
            self.l.div[0] = self.data0[0] / self.data1[0]  # seed value
        def next(self):
            d = self.data0[0] / self.data1[0]
            self.l.div[0] = d if d else self.l.div[-1]
        def oncestart(self, start, end):
            self.line.array[start] = (
                self.data0.array[start] - self.data1.array[start])
        def once(self, start, end):
            d0array = self.data0.array
            d1array = self.data1.array
            larray = self.line.array
            prev = larray[start - 1]
            for i in range(start, end):
                d = d0array[i] / d1array[i]
                larray[i] = prev = d if d else prev
    class CalvadosStrategy(bt.Strategy):
          def __init__(self):
            my_ratio = DivisionIndicator(self.datas[1], self.datas[2])

  • administrators

    Docs - Plotting - plotmaster

Log in to reply