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/

    Put stop order that valid at each TimeFrame

    General Code/Help
    1
    1
    18
    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.
    • R
      rodket last edited by

      I need to put a limit order in each TimeFrame and it has to be valid just for that TimeFrame. I used the following code, but it did not cancel the orders at the end of each TimeFrame:

      self.buy(exectype = bt.Order.Stop, price = price, valid = datetime.datetime.now() + datetime.timedelta(minutes=1))
      

      Is this right?

      Since it does not work, first I cancel all previous orders at the beginning of the next(self), by this code:

      [self.cancel(o) for o in self.broker.orders if o.status < 4]
      

      and then I put the stop order. This action works, but makes the calculation process really slow. Is there any way to optimize this action?

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