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

AttributeError: module 'backtrader.indicators' has no attribute 'DummyInd'

  • Hi guys, need a little help
    I tested building a custom indicator with the help of the Backtrader documentation and I got an AttributeError. I am new to Backtrader and I'd appreciate a little help.

    import backtrader as bt
    import backtrader.indicators as btind
    class DummyInd(bt.Indicator):
        lines = ('dummyline',)
        params = (('value', 5),)
        def __init__(self):
            self.lines.dummyline = bt.Max(0.0, self.params.value)
    class MyStrategy(bt.Strategy):
        def __init__(self):
            self.rocp = btind.DummyInd()
        def next(self):
    cerebro = bt.Cerebro()  # create a "Cerebro" engine instance
    # Create a data feed
    data = bt.feeds.YahooFinanceData(dataname='sunpharma.csv')
    cerebro.adddata(data)  # Add the data feed
    cerebro.addstrategy(MyStrategy)  # Add the trading strategy
    print('Starting Portfolio Value: ',  # run it all
    print('Final Portfolio Value: ',
    cerebro.plot()  # and plot it with a single command

  • Since it is unknown where the actual error happened, than a guess - try this

    self.rocp = DummyInd()

  • @ab_trader Thank you for taking the time to reply.
    But I didn't get what was wrong exactly. I made the change and the error is gone.

  • btind.some_indicator() tries to get an indicator from bt library. Evidently there is no DummyInd() indicator there, it is developed in your code.

Log in to reply