Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

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

    Indicators/Strategies/Analyzers
    2
    4
    389
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • aman jha
      aman jha last edited by

      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.
      Code```

      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):
              print(self.rocp)
      
      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: ',cerebro.broker.getvalue())
      cerebro.run()  # run it all
      print('Final Portfolio Value: ',cerebro.broker.getvalue())
      cerebro.plot()  # and plot it with a single command
      1 Reply Last reply Reply Quote 0
      • A
        ab_trader last edited by

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

        self.rocp = DummyInd()
        
        aman jha 1 Reply Last reply Reply Quote 1
        • aman jha
          aman jha @ab_trader last edited by

          @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.

          1 Reply Last reply Reply Quote 0
          • A
            ab_trader last edited by

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

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
            $(document).ready(function () { app.coldLoad(); }); }