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/

    TypeError: __init__() takes 1 positional argument but 2 were given

    General Code/Help
    2
    3
    764
    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.
    • C
      Chricco94 last edited by

      hi, i'm trying to backtest this strategy:

      class WaveTrendStrategy(bt.Strategy):

      def __init__(self) :
          n1 = 21
          n2 = 14
          obLevel1 = 60
          obLevel1 = 60
          obLevel2 = 53
          osLevel1 = -60
          osLevel2 = -53
          hlc3 = (self.data.high+self.data.low+self.data.close)/3
          ap = hlc3 
          esa = bt.ind.EMA(ap, n1)
          d = bt.ind.EMA(abs(ap - esa), n1)
          ci = (ap - esa) / (0.015 * d)
          tci = bt.ind.EMA(ci, n2)
          wt1 = tci
          wt2 = bt.ind.SMA(wt1,4)
          longCondition  = bt.ind.CrossOver(wt2,osLevel2)
          shortCondition = bt.ind.CrossUnder(wt2,obLevel2)
          
          
      def next(self):
          if longCondition:
                  self.buy()
          
          elif shortCondition:
              self.sell()
      

      but i get TypeError: init() takes 1 positional argument but 2 were given.

      Someone can show me where i'm wrong? Thanks a lot.

      D 1 Reply Last reply Reply Quote 0
      • D
        davidavr @Chricco94 last edited by

        @chricco94 That error is coming from your use of EMA. You need to name the period parameter so use

        esa = bt.ind.EMA(ap, period=n1)
        

        instead of

        esa = bt.ind.EMA(ap, n1)
        

        BT makes heavy use of meta classes which can be confusing at times.

        There are a couple of other issues in your code:

        • There is no CrossUnder indicator in BT
        • You aren't storing the longCondition and shortCondition indicators in self so you cannot access them in next()
        1 Reply Last reply Reply Quote 0
        • C
          Chricco94 last edited by

          @davidavr thank you, it worked!

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors