Backtrader Community

    • 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/

    Get list of orders?

    General Code/Help
    2
    3
    280
    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.
    • D
      doloop last edited by

      I've recently run across Backtrader. It is an impressive piece of software, but I think the learning curve is a bit steep (at least for me!) ;-(

      My question: I don't want to enter an order if I already entered one in the previous one or two days. So, I just want to check whether an order was entered. Something like this pseudo-code:

      if not order[-2] and not order[-1]:
          order.buy()
      

      How would I do that?

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

        Whenever you create a new order, track the length of self (current index) in a variable.

        So in your strategy:

        def __init__(self):
            self.track_last_order = 0
        
        def next(self):
            if (len(self) - self.track_last_order) > 2:
                # you make a new order here... then
                self.track_last_order = len(self)
        

        RunBacktest.com

        D 1 Reply Last reply Reply Quote 1
        • D
          doloop @run-out last edited by

          @run-out Thank you!

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