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/

    Array out of index after resampling data

    General Code/Help
    3
    4
    62
    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.
    • K
      Kestutis Tamosiunas last edited by

      Hi,
      I was happy out testing my basic strategies until I introduced data resampling.I used to check the price of a next bar ahead and it worked fine but now I get:
      return self.array[self.idx + ago]
      IndexError: array index out of range
      when executing this line of code, as long as I use positive number, I get the error:

      first_bottom = [(self.datalow[i]) for i in range(-8, 5)]
      

      Now i can't get to see price ahead anywhere in the code, I tried lines attribute, but no luck either.Spend the whole day fiddling with the code, but as for being not a programmer, I cant figure out for myself.
      If anyone could point me out to the right direction, I 'd very appreciate.

      Here is more snippets of my code that could clarify the reason of the problem:

      def __init__(self):
      self.datalow = self.datas[0].low
      .......................................................
      
      data = bt.feeds.GenericCSVData(
              dataname=datapath,
              # Do not pass values before this date
              fromdate=datetime.datetime(2018, 9, 9),
              todate = datetime.datetime(2020, 2, 2),
              timeframe = bt.TimeFrame.Minutes,
              compression = 60,
              .................
              openinterest = -1)
      .......................................................................
      cerebro.adddata(data)
      cerebro.resampledata(data,timeframe=bt.TimeFrame.Days,compression=1)
      
      1 Reply Last reply Reply Quote 0
      • run-out
        run-out last edited by

        Backtrader is specifically designed not to allow looking ahead of the current bar. The mostly eliminates look ahead bias in the backtest. Have a look over here for more info.

        K 1 Reply Last reply Reply Quote 1
        • A
          ab_trader last edited by

          I would re-write the code to use only available data.

          1 Reply Last reply Reply Quote 0
          • K
            Kestutis Tamosiunas @run-out last edited by

            @run-out well it was working fine with single data.I guess I need to find a way to cheat a system . For a noob it will be a big challenge :) . Thanks for your replays guys.
            And by the way run-out, good look with the backtrader2.

            1 Reply Last reply Reply Quote 1
            • 1 / 1
            • First post
              Last post
            Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
            $(document).ready(function () { app.coldLoad(); }); }