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/

    Pass ZeroLag indicator output as input to RSI

    General Discussion
    3
    4
    110
    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.
    • A
      azohar last edited by

      Hello, I am trying to create an indicator that takes the output of the ZeroLagIndicator and passes it to RSI as the input, tried several ways but can't figure out how to correctly pass the data between them.

      When I run the code example I can see the correct value for zerolag[0] printed out, but nan for RSI.
      Like so:
      zerolag[0]=3646.76
      rsi[0]=nan

      class MyIndicator(bt.Indicator):
          def __init__(self, data):
              self.zerolag = bt.indicators.ZeroLagIndicator(
                  data,)
              self.rsi = bt.indicators.RSI(self.zerolag, period=5)
      
          def next(self):
              print("zerolag[0]=" + str(self.zerolag[0]))
              print("rsi[0]=" + str(self.rsi[0]))
      

      What is the correct way of doing this? Any help would be highly appreciated.

      1 Reply Last reply Reply Quote 0
      • F
        freedumb2000 last edited by

        You need to always the "lines" class attribute, when creating an indicator, if if you don't use any lines. Also, you never actually passed the output of ZeroLag to RSI.
        This works:

        class MyIndicator(bt.Indicator):
            lines = ("dummyline",)
        
            def __init__(self):
                self.zerolag = bt.indicators.ZeroLagIndicator(self.data, period=5)
                self.rsi = bt.indicators.RSI(self.zerolag, period=5)
        
            def next(self):
                print("zerolag[0]=" + str(self.zerolag[0]))
                print("rsi[0]=" + str(self.rsi[0]))
        

        This is actually useful:

        class MyIndicator(bt.Indicator):
            lines = ("zerolag", "rsi")
        
            def __init__(self):
                self.zerolag = bt.indicators.ZeroLagIndicator(self.data, period=5)
                self.rsi = bt.indicators.RSI(self.zerolag, period=5)
        
        1 Reply Last reply Reply Quote 0
        • F
          freedumb2000 last edited by

          I made a mistake in the post above, but I cannot find a way to edit the post? Please let me know how to edit the post above or delete it. Thank you

          run-out 1 Reply Last reply Reply Quote 0
          • run-out
            run-out @freedumb2000 last edited by

            @freedumb2000 There is no way to edit or delete.

            RunBacktest.com

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