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/

    extending data feed ==> list index out of range issue

    General Code/Help
    5
    6
    954
    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.
    • Zhangjt9317
      Zhangjt9317 last edited by

      Hi, I am new to backtrader, and I have a minute-based OHLCV dataset for BTC price, but with an extra 'Forecast' column. I read the extending data feeds post and made my own datafeed class as shown below:

      class datafeed(GenericCSVData):
          lines = ('Forecast',)  # add a 'Forecast' line to the inherited ones from the base class
          params = (
              ('nullvalue', float('NaN')),
              ('dtformat', '%Y-%m-%d %H:%M:%S'),
              ('tmformat', '%H:%M:%S'),
              ('datetime', 1),
              ('open', 2),
              ('high', 3),
              ('low', 4),
              ('close', 5),
              ('volume', 6),
              ('Forecast', 11) # 11th col
          )
      

      and I am trying to compare the open price and forecast price as a signal

          def __init__(self):
              # To control operation entries
              self.orderid = None
      
              # Create a CrossOver Signal from close an moving average
              self.signal = self.data.Forecast - self.data.open
      

      But I have the error:

      Traceback (most recent call last):
        File "D:/DailyTradeForecast.py", line 228, in <module>
          runstrategy()
        File "D:/DailyTradeForecast.py", line 159, in runstrategy
          cerebro.run()
        File "C:\Users\anaconda3\lib\site-packages\backtrader\cerebro.py", line 1127, in run
          runstrat = self.runstrategies(iterstrat)
        File "C:\Users\anaconda3\lib\site-packages\backtrader\cerebro.py", line 1212, in runstrategies
          data.preload()
        File "C:\Users\anaconda3\lib\site-packages\backtrader\feed.py", line 688, in preload
          while self.load():
        File "C:\Users\anaconda3\lib\site-packages\backtrader\feed.py", line 479, in load
          _loadret = self._load()
        File "C:\Users\anaconda3\lib\site-packages\backtrader\feed.py", line 710, in _load
          return self._loadline(linetokens)
        File "C:\Users\anaconda3\lib\site-packages\backtrader\feeds\csvgeneric.py", line 148, in _loadline
          csvfield = linetokens[csvidx]
      IndexError: list index out of range
      
      Process finished with exit code 1
      

      I am not so sure what is wrong with my datafeed, or it is the error from the signal, can someone help?

      1 Reply Last reply Reply Quote 0
      • vladisld
        vladisld last edited by

        Could you please share at least a part of the csv file ?

        1 Reply Last reply Reply Quote 1
        • Xu Liu
          Xu Liu last edited by

          I have the same problem,My solution is to get more columns out。

          1 Reply Last reply Reply Quote 0
          • Zhangjt9317
            Zhangjt9317 last edited by

            thank you all for the response, I solve the problem by following the documentation, just make sure you count the column number correctly (start from 0) and follow the extending data section in doc

            S 1 Reply Last reply Reply Quote 0
            • S
              sid_vishnu @Zhangjt9317 last edited by

              @zhangjt9317 which documentation did you read to correct the code?

              run-out 1 Reply Last reply Reply Quote 0
              • run-out
                run-out @sid_vishnu last edited by

                @sid_vishnu Try these:

                Extending a Datafeed
                Extended Data Feed: post

                RunBacktest.com

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