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/

    Backtrader DOES NOT CRASH on MOO orders - The USER CODE does

    General Discussion
    3
    8
    246
    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.
    • E
      Ed Bartosh last edited by backtrader

      Hi,

      I'm getting this traceback when creating MOO(Market On Open) order before market open. It seems that backtrader needs price data to create orders. However, some securities do not trade during premarket.

      Any ideas how to fix or work around this?

      P.S. This happens in live trading.

      Traceback (most recent call last):
        File "./test-moo.py", line 87, in <module>
          sys.exit(main(sys.argv))
        File "./test-moo.py", line 84, in main
          cerebro.run()
        File "backtrader\cerebro.py", line 1127, in run
          runstrat = self.runstrategies(iterstrat)
        File "backtrader\cerebro.py", line 1295, in runstrategies
          self._runnext(runstrats)
        File "backtrader\cerebro.py", line 1626, in _runnext
          strat._next()
        File "backtrader\strategy.py", line 325, in _next
          super(Strategy, self)._next()
        File "backtrader\lineiterator.py", line 270, in _next
          self.prenext()
        File "./test-moo.py", line 53, in prenext
          self.buy(data, size=100, exectype=bt.Order.Market,
        File "backtrader\strategy.py", line 905, in buy
          data = data or self.datas[0]
        File "backtrader\lineroot.py", line 287, in __nonzero__
          return self._operationown(bool)
        File "backtrader\lineroot.py", line 94, in _operationown
          return self._operationown_stage2(operation)
        File "backtrader\lineroot.py", line 218, in _operationown_stage2
          return operation(self[0])
        File "backtrader\lineseries.py", line 467, in __getitem__
          return self.lines[0][key]
        File "backtrader\linebuffer.py", line 163, in __getitem__
          return self.array[self.idx + ago]
      IndexError: array index out of range
      

      Regards,
      Ed

      A B 2 Replies Last reply Reply Quote 0
      • A
        ab_trader @Ed Bartosh last edited by

        @Ed-Bartosh maybe some data from the previous day loaded into bt might help?

        • If my answer helped, hit reputation up arrow at lower right corner of the post.
        • Python Debugging With Pdb
        • New to python and bt - check this out
        1 Reply Last reply Reply Quote 0
        • B
          backtrader administrators @Ed Bartosh last edited by backtrader

          CORRECTION: YOUR CODE CRASHES.

          @Ed-Bartosh said in Backtrader crashes on MOO orders:

          Hi,
          I'm getting this traceback when creating MOO(Market On Open)

          That order type is not supported. You are using a Market order. But that's not the problem.

          @Ed-Bartosh said in Backtrader crashes on MOO orders:

          It seems that backtrader needs price data to create orders

          That's also not the problem.

          @Ed-Bartosh said in Backtrader crashes on MOO orders:

          File "backtrader\lineiterator.py", line 270, in _next
          self.prenext()
          File "./test-moo.py", line 53, in prenext
          self.buy(data, size=100, exectype=bt.Order.Market,

          That's the problem. I will reduce it to the actual problem

          @Ed-Bartosh said in Backtrader crashes on MOO orders:

          File "backtrader\lineiterator.py", line 270, in _next
          self.prenext()

          @Ed-Bartosh said in Backtrader crashes on MOO orders:

          Any ideas how to fix or work around this?

          Use next where guarantees are valid.

          1 Reply Last reply Reply Quote 0
          • E
            Ed Bartosh last edited by

            @backtrader said in Backtrader DOES NOT CRASH on MOO orders - The USER CODE does:

            Use next where guarantees are valid.

            I tried this before using prenext. next is not called as securities are not traded, so there not enough bars I guess. For some securities there is no trading happening at all. Does it mean that for them it's not possible to create orders before market open?

            1 Reply Last reply Reply Quote 0
            • B
              backtrader administrators last edited by

              prenext and next (and nextstart) have nothing to do with market times. Docs - Operating the Platform - Minimum Period

              @ab_trader said in Backtrader DOES NOT CRASH on MOO orders - The USER CODE does:

              @Ed-Bartosh maybe some data from the previous day loaded into bt might help?

              E 1 Reply Last reply Reply Quote 0
              • E
                Ed Bartosh @backtrader last edited by

                @backtrader said in Backtrader DOES NOT CRASH on MOO orders - The USER CODE does:

                prenext and next (and nextstart) have nothing to do with market times. Docs - Operating the Platform - Minimum Period

                @ab_trader said in Backtrader DOES NOT CRASH on MOO orders - The USER CODE does:

                @Ed-Bartosh maybe some data from the previous day loaded into bt might help?

                Have I understood correctly that you're suggesting to load price data to be able to create orders?

                1 Reply Last reply Reply Quote 0
                • B
                  backtrader administrators last edited by

                  You want to use a method with no guarantees (i.e.: prenext) for a purpose which is also not designed (i.e.: pre-market times, where the pre in the name and the pre in market times, have nothing to do with each other)

                  The only thing you present is a trace ... but you obviously come into prenext because something has a buffer with at least one data point.. Probably because you use multiple data feeds ... and you probably target the one which doesn't have any data point.

                  You additionally want to send an order type which is not supported (you may implemented it, that I don't know, but it seems a regular Market order)

                  @ab_trader has stated how you can overcome the situation and I have remarked it. Your options: do so ... do something else.

                  E 1 Reply Last reply Reply Quote 0
                  • E
                    Ed Bartosh @backtrader last edited by

                    @backtrader thank you for the explanations.

                    Yes, I was trying to use one symbol that's trading on pre-market to trigger prenext. As you can see it didn't help much, i.e. it crashed backtrader.

                    What I was trying to ask (and apparently failed) is: if creating orders without price data supported by backtrader at all? If it's possible then it would be great if you explain how to do it without loading data as @ab_trader suggested. If it's not possible ... well I'll try to work around it using @ab_trader's suggestion.

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