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

Insisting "IndexError within GenericCSVData-loading

  • Hello backtrader-experts,

    half the day I spended in trying-searching-troubleshooting all change at all:
    "IndexError" within dataloading is solid as a rock, does not change a bit...any advice?

    CSV (GBPUSD, M5) has 100000 rows, for troubleshooting I have reduced to only 10
    Original with dtformat = ('%Y.%m.%d %H:%M:%S'),

    I have also changed to default-dtformat = ('%Y-%m-%d %H:%M:%S') with no difference

    GenericCSVData is loading data with following parameters

    import backtrader.feeds as btfeed
       dataLoad = btfeed.GenericCSVData(
            dataname = CSV_PATH + CSV_FILE,
            #separator = ",",
            #fromdate = datetime.datetime(2019, 1, 21),
            #fromdate = datetime.datetime(2020, 8, 8),
            #dtformat = ('%Y.%m.%d %H:%M:%S'),
            dtformat = ('%Y-%m-%d %H:%M:%S'),
            #dtformat = ('%YYYY.%mm.%dd %HH:%MM:%SS'),
            datetime = 2,
            time = -1,
            timeframe = 5,
            compression = 1,
            open = 3,
            high = 4,
            low = 5,
            close = 6,
            volume = -1,
            openinterest = -1,
            nullvalue = 0.0,
            header = True)



    What ever I try/change/add/remove, it allways keeps: "IndexError: list index out of range".

    • with 10 rows only, you can see: CSV cannot be corrupt
    • "CSV_PATH + CSV_FILE" gives correct path to file, otherwise "No such file or director" would rise
    • I have tried both dtformats..therefore

    ...I am completely helpless, what can be the error.
    Any advice?


  • Your data is backwards. Change the sort order so that oldest data points are first and newest are last.

  • Thats why! Thx so much!

Log in to reply