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/

    How execute a close order with a Stop Loss in place (without waiting another "next")

    General Code/Help
    2
    2
    353
    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.
    • C
      cwse last edited by

      Is it possible to self.close() when you have an open Stop order, without running the risk of the Stop and Close executing at the same time (and resulting in an unwanted net short position)?

      It seems you have to first cancel the Stop, then wait until the next "next" iteration to "Close" the position. But working with daily data, this means up to 3 days before you can get out of the market.

      I have tried self.cancel followed by self.Close in the one Next() iteration, but if the Stop has not yet been Accepted by the Broker (i.e. was recently created), it appears this "self.cancel" step doesn't work (and you have to wait another next iteration).

      Would love anyone's thoughts on how to manage stops without waiting multiple "next" iterations!

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

        @cwse said in How execute a close order with a Stop Loss in place (without waiting another "next"):

        I have tried self.cancel followed by self.Close in the one Next() iteration, but if the Stop has not yet been Accepted by the Broker (i.e. was recently created), it appears this "self.cancel" step doesn't work (and you have to wait another next iteration).

        This is plainly wrong. Unless "recently" means you have created it in the same iteration, in which case your logic is flawed, because you create and cancel an order in the same iteration.

        In any other case the broker will accept orders before you have your chance in next.

        @cwse said in How execute a close order with a Stop Loss in place (without waiting another "next"):

        It seems you have to first cancel the Stop, then wait until the next "next" iteration to "Close" the position. But working with daily data, this means up to 3 days before you can get out of the market.

        It seems wrongly. Cancel the stop and issue a close.

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