For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

Clarifying parent-child order behavior



  • Hi,

    I'm looking to attach child Stop orders to my main Limit orders for downside protection. Like this (from example here):

    o1 = self.buy(data=d, exectype=bt.Order.Limit,
                          price=p, valid=valid, transmit=False)
    
    o2 = self.sell(data=d, exectype=bt.Order.Stop,
                   price=pstp, size=o1.size,
                   transmit=True, parent=o1)
    

    Note that only the main Limit order, o1, has a valid duration (expiry).

    I'd like to clarify three points:

    1. When the main Limit order is only partially filled, are Stop orders active?

    This post in the Multi Example thread:

    The stop-loss and take-profit orders are created but... Are created inactive and will only become active (available for execution) if the parent is Completed

    suggests that the Stop orders are inactive if parent is not Completed.

    So, that means that while the main Limit order is being filled, there is no protection even though a Stop order was submitted with the main Limit order?

    2. When the main Limit order expires (not canceled), does the child Stop order expire too?

    Per the strategy docs:

    parent (default: None)
    Controls the relationship of a group of orders, for example a buy which is bracketed by a high-side limit sell and a low side stop sell. The high/low side orders remain inactive until the parent order has been either executed (they become active) or is canceled/expires (the children are also canceled) bracket orders have the same size

    The Stop trading docs here https://www.backtrader.com/blog/posts/2018-02-01-stop-trading/stop-trading.html say:

    If the parent order is cancelled, the child order will also be cancelled

    But do not mention expiry.

    It seems very counter intuitive that the Stop would not protect against size filled by the Limit order (esp. since the Stop did not have an expiry set on it), but would love clarification. And, it would be very helpful to describe that explicitly in the Stop trading docs.

    3. Does Backtrader's Interactive Brokers implementation support "manual" parent-child relationships?

    I believe bracket orders are implemented, but if we submit a parent-child manually per above, does IB see this as a parent-child pair? Since the OCO docs state:

    This is only implemented in backtesting and there isn’t yet an implementation for live brokers

    I'd like to clarify since this seems to be a way to achieve implicit OCO behavior for a live broker.

    Thank you very much!