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/

    Novice at python

    General Code/Help
    3
    4
    372
    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.
    • N
      No1uknow last edited by

      I tried using the snippet of code from main page with a slight edit and I am getting errors...

      ''' from datetime import datetime
      import backtrader as bt

      class SmaCross(bt.SignalStrategy):
      params = (('pfast', 10), ('pslow', 30),)
      def init(self):
      sma1, sma2 = bt.ind.SMA(period=self.p.pfast), bt.ind.SMA(period=self.p.pslow)
      self.signal_add(bt.SIGNAL_LONG, bt.ind.CrossOver(sma1, sma2))

      cerebro = bt.Cerebro()
      
      data = bt.feeds.CCXT(exchange='coinbasepro', symbol='ETH/USD', ohlcv_limit=None,
                          fromdate=datetime(2019, 3, 1),
                          todate=datetime(2019, 3, 18))
      
      #data = bt.feeds.YahooFinanceData(dataname='MSFT', fromdate=datetime(2011, 1, 1),
      #                                todate=datetime(2012, 12, 31))
      cerebro.adddata(data)
      
      cerebro.addstrategy(SmaCross)
      cerebro.run()
      cerebro.plot() 
      

      Errors:

      To many positional arguements for constuctor call pylint line 8,41
      Unexpected keyword fromdate
      Unexpected keyword todate
      Undefined variable SMACross

      Help the noob please!

      Thanks.

      N B 2 Replies Last reply Reply Quote 0
      • N
        No1uknow @No1uknow last edited by

        @no1uknow Sigh can't edit post? Wanted to fix the code block.

        1 Reply Last reply Reply Quote 0
        • B
          backtrader administrators @No1uknow last edited by

          @no1uknow said in Novice at python:

          Errors:
          To many positional arguements for constuctor call pylint line 8,41
          Unexpected keyword fromdate
          Unexpected keyword todate
          Undefined variable SMACross

          Those aren't errors. That's pylint

          Do you have any actual error?

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

            As an idea - CCXT feed is not in the bt module. You might need to install and import it separately.

            • If my answer helped, hit reputation up arrow at lower right corner of the post.
            • Python Debugging With Pdb
            • New to python and bt - check this out
            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors