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

Lines Coupling not working

  • Following the example in the documentation and it seems to give a index out of range when trying to use the lines coupling method ()

    class LineCoupler(bt.Strategy):
        params = dict(period=20)
        def __init__(self):
            # data0 is a daily data
            sma0 = btind.SMA(self.data0, period=7)  # 15 days sma
            # data1 is a weekly data
            sma1 = btind.SMA(self.data1, period=2)  # 5 weeks sma
            self.buysig = sma0 < sma1()
    data = pdr.get_data_yahoo('AAPL', start=datetime(2017, 8, 13), end=datetime(2018, 8, 14),interval='d')
    data1 = pdr.get_data_yahoo('AAPL', start=datetime(2017, 8, 13), end=datetime(2018, 8, 14), interval='w')
     # add the data from a pandasDataFrame
    backtest =

    Traceback (most recent call last):
    File "", line 200, in <module>
    backtest =
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/backtrader/", line 1127, in run
    runstrat = self.runstrategies(iterstrat)
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/backtrader/", line 1293, in runstrategies
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/backtrader/", line 1652, in _runonce
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/backtrader/", line 297, in _once
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/backtrader/", line 631, in _once
    self.once(self._minperiod, self.buflen())
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/backtrader/", line 755, in once
    self._once_op(start, end)
    File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/backtrader/", line 772, in _once_op
    dst[i] = op(srca[i], srcb[i])
    IndexError: array index out of range

  • administrators

    You have to disable step-by-step evaluation as shown in the code., runonce=False). Coupling cannot be precalculated.

    Blog - Mixing Timeframes in Indicators

Log in to reply