Backtrader Community

    • 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/

    Adding lines and shifts from indicators

    Indicators/Strategies/Analyzers
    2
    2
    2033
    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.
    • ealvarpe
      ealvarpe last edited by

      I have this scenario:

      • I´ve defined an indicator (let´s say RSI) at the init function : self.rsi = bt.indicators.RSI(...)
      • Then I need to add that line with it´s previous values, or in other words the RSI shifted by 1

      So if RSI[0] = 80 and RSI[-1] = 50, the new line[0] would be 80+50..

      Is that possible? I´m trying to create a Fisher transformation with some changes but can´t know how to shift lines in order to sum them as an init definition..

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

        Shifting is implemented with the (x) operators in lines objects.

        See: Docs - Concepts and look for delayed. The use of the term delayed was meant to indicate that looking into the future is not possible. But it is possible for indicators to project values into the future (like Ichimoku does), although it is seldom used.

        Basically:

        newline = self.rsi + self.rsi(-1)
        

        Notice how the first term doesn't use the (x) notation and with it it simply takes the current value. One could of course also do it formally as:

        newline = self.rsi(0) + self.rsi(-1)
        

        which is functionally 100% equivalent but not 100% memory equivalent because self.rsi(0) will create an extra buffer for the copies of itself.

        RSI has a single line, so there is not much need to address the specific lines and by simply using the indicator itself the 1st line in the indicator is automatically used.

        But for indicators with multiple lines like a MACD, one can also do things like:

        newline = self.macd + self.macd(-1)  # 1st line
        newline = self.macd.lines.macd + self.macd.lines.macd(-1)  # the 1st line is also called macd
        newline = self.macd + self.macd.lines.signal(-1)  # sum of present 1st line + delayed line "signal"
        
        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors