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/

    How to change the index of indicator to the opposite ?

    General Code/Help
    2
    2
    94
    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.
    • MuSaCN
      MuSaCN last edited by

      if we use code:
      self.sma = bt.indicators.MovingAverageSimple(data, period)
      self.sma[0] --> current bar
      self.sma[-1] --> last one bar

      But, I want it:
      self.sma[0] --> current bar
      self.sma[1] --> last one bar
      Is there any other way besides the function ?

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

        @MuSaCN said in How to change the index of indicator to the opposite ?:

        Is there any other way besides the function ?

        I don't know which "function" you may be referring to, because there is no such function.

        But if you want to change the semantics of backtrader about what's the past and what's the future, you should consider using something else.

        The semantics were chosen to stay as close as possible to the semantics of "last" in Python (i.e.: -1) and have a pivot point around 0 (Python has no notion of a pivot for an array)

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