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 ?



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


  • administrators

    @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)


Log in to reply
 

});