For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See:

[FIXED] Ichimoku: Unable to get Future cloud

  • From what I understand backtrader can be operated pseudo-vectorized using runonce=True option of Cerebro. As a result indicators are getting pre-calculated before strategy execution starts.

    Keeping that in mind accessing the current cloud using

    self.ikh = bt.indicators.Ichimoku()

    works as expected. Current cloud means: The cloud which is on position [0] and has been calculated -26 bars in the past (because the cloud calculation forward-pushs 26 bars).

    In a second step I would assume to access the future cloud using

    self.ikh = bt.indicators.Ichimoku()

    which fails with {IndexError} array index out of range.

    So is it possible to access one of the future senkou_span_a or future senkou_span_b lines which has been calculated on the [0, -1, -2 ... -26] bars?

  • Oh... Just reverted from to and it works like expected.

    pip3 install 'backtrader==' --force-reinstall
    Collecting backtrader==
      Downloading backtrader- (391kB)
        100% |████████████████████████████████| 399kB 1.3MB/s 
    Installing collected packages: backtrader
      Found existing installation: backtrader
        Uninstalling backtrader-
          Successfully uninstalled backtrader-
    Successfully installed backtrader-

  • administrators

    There is a new feature for indicators introduced with 1.9.54.x:

    • Commit Hash: 27c406ccdb37a88eb115e132ddbdbd2407b41fa1
    • Comment: Allow indicators to disable runonce

    Because HeikinAshi due to the recursive nature cannot work properly in runonce=True mode. And the testing code remained in forcing runonce=False

    Looking into the future is not possible when runonce=False.

    Corrected and pushed to the development branch.

  • @backtrader Will check it to provide feedback shortly.

  • @backtrader: Now works again as expected. Thanks!

  • Is this really solved? Following simple test does not work:

    class IchimokuStrategy(StrategyBase.StrategyBase):
        def __init__(self):
            self.Ichimoku = bt.indicators.Ichimoku()
        def next(self):
    if __name__ == '__main__':
        cerebro = bt.Cerebro()

    It throws following error:

    File "/Users/BackTrader/", line 25, in next
    File "/usr/local/lib/python3.7/site-packages/backtrader/", line 163, in __getitem__
      return self.array[self.idx + ago]

    Why can't I get the values from the future?

Log in to reply