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



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


  • administrators

    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)



  • @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.


Log in to reply
 

});