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

with Interactive brokers backtrader crash



  •     stockkwargs = dict(
            timeframe=bt.TimeFrame.Seconds
        )
        stockkwargs_days = dict(
            timeframe=bt.TimeFrame.Days
        )
    
        spyd = store.getdata(dataname='SPY-STK-ARCA-USD',**stockkwargs_days )
    
        spyg = store.getdata(dataname='SPYG-STK-ARCA-USD',**stockkwargs )
        tlt = store.getdata(dataname='TLT-STK-ARCA-USD',**stockkwargs  )
        gld = store.getdata(dataname='IAU-STK-ARCA-USD',**stockkwargs )
    
        spygd = store.getdata(dataname='SPYG-STK-ARCA-USD',**stockkwargs_days )
        tltd = store.getdata(dataname='TLT-STK-ARCA-USD',**stockkwargs_days  )
        gldd = store.getdata(dataname='IAU-STK-ARCA-USD',**stockkwargs_days )
    
    
        cerebro.addcalendar("NYSE")
        cerebro.resampledata(spyd, name='SPYD', **stockkwargs_days)  
    
    
        cerebro.resampledata(spyg, name='MKT', **stockkwargs) 
        cerebro.resampledata(tlt, name='BONDLONG', **stockkwargs)  
        cerebro.resampledata(gld, name='GOLDLONG', **stockkwargs)  
    
        cerebro.resampledata(spygd, name='MKTD', **stockkwargs_days) 
        cerebro.resampledata(tltd, name='BONDLONGD', **stockkwargs_days)  
        cerebro.resampledata(gldd, name='GOLDLONGD', **stockkwargs_days)  
    
    


  • I continue to get crashes even before it's call my next function. some rare times it's pass OK, anyone can advise?

    
    Traceback (most recent call last):
    <historicalData reqId=16777255, date=20180418, open=121.02, high=121.34, low=120.19, close=120.25, volume=8863, count=3478, WAP=120.761, hasGaps=False>
    <historicalData reqId=16777255, date=20180419, open=119.86, high=119.91, low=118.81, close=119.29, volume=13703, count=5397, WAP=119.257, hasGaps=False>
      File "/Users/roman/Projects/ai/sample-backtrader/ibtutorial.py", line 219, in <module>
        run()
      File "/Users/roman/Projects/ai/sample-backtrader/ibtutorial.py", line 215, in run
        cerebro.run()
      File "/Users/roman/anaconda3/envs/backtrader/lib/python3.7/site-packages/backtrader/cerebro.py", line 1127, in run
        runstrat = self.runstrategies(iterstrat)
      File "/Users/roman/anaconda3/envs/backtrader/lib/python3.7/site-packages/backtrader/cerebro.py", line 1298, in runstrategies
    <historicalData reqId=16777255, date=20180420, open=119.22, high=119.22, low=118.37, close=118.41, volume=7372, count=3448, WAP=118.704, hasGaps=False>
    <historicalData reqId=16777255, date=20180423, open=118.11, high=118.61, low=117.8, close=118.5, volume=8573, count=3336, WAP=118.369, hasGaps=False>
    <historicalData reqId=16777255, date=20180424, open=118.16, high=118.45, low=117.76, close=117.76, volume=8363, count=3679, WAP=118.094, hasGaps=False>
        self._runnext(runstrats)
      File "/Users/roman/anaconda3/envs/backtrader/lib/python3.7/site-packages/backtrader/cerebro.py", line 1630, in _runnext
        strat._next()
      File "/Users/roman/anaconda3/envs/backtrader/lib/python3.7/site-packages/backtrader/strategy.py", line 347, in _next
        super(Strategy, self)._next()
      File "/Users/roman/anaconda3/envs/backtrader/lib/python3.7/site-packages/backtrader/lineiterator.py", line 260, in _next
        clock_len = self._clk_update()
      File "/Users/roman/anaconda3/envs/backtrader/lib/python3.7/site-packages/backtrader/strategy.py", line 327, in _clk_update
        newdlens = [len(d) for d in self.datas]
      File "/Users/roman/anaconda3/envs/backtrader/lib/python3.7/site-packages/backtrader/strategy.py", line 327, in <listcomp>
        newdlens = [len(d) for d in self.datas]
      File "/Users/roman/anaconda3/envs/backtrader/lib/python3.7/site-packages/backtrader/lineseries.py", line 464, in __len__
        return len(self.lines)
      File "/Users/roman/anaconda3/envs/backtrader/lib/python3.7/site-packages/backtrader/lineseries.py", line 220, in __len__
        return len(self.lines[0])
    ValueError: __len__() should return >= 0
    
    Process finished with exit code 1
    


  • found issue - just replace with resampledata to replaydata


Log in to reply
 

});