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/

    Bracket order only with Stop

    General Code/Help
    2
    3
    128
    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.
    • Rumen Nenov
      Rumen Nenov last edited by

      I've got following problem: Stop order is supposed to get cancelled automatically if Limit order is executed (also known as OCO) and position closed. In my strategy I do not use Limit order as my profitable positions are closed by the strategy logic. However, I cannot leave a position without a stop order. If I attach a stop or trailing stop and my trade is closed by the logic of the strategy, the stop order remains active and gets executed later. I need some help. I can't implement this part of the code.

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

        I seem some failing logic here.

        • A half-bracket is applied (only main order and stop order)
        • main order is executed and stop is activated
        • trade opened by main order is closed by a non-related order
        • the stop order remains (as expected and as it would happen in real-life) active

        It seems pointless to use a half-bracket to open the stop if the functionality of the bracket is ignored.

        In any case the bracket code gives you a reference to the orders which are created. When your foreign order closes the trade, you simply have to use the reference you have for the the stop order and call self.cancel(stop_order)

        Rumen Nenov 1 Reply Last reply Reply Quote 0
        • Rumen Nenov
          Rumen Nenov @backtrader last edited by

          @backtrader thank you for the guidance. I read the documentation but I struggle to implement it.

          Why it seems pointless and illogical? In fact many brokers give you a choice what to include in the bracket order (stop only, limit only, or stop/limit). What is wrong in having a stop to prevent you from excessive loss while working your own logic about the closing conditions.

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