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

Secondary limit/stop order



  • Hi,

    I currently place a market order, along with a limit order and stop order (of different sizes), all at the same time in next(). If that limit price is reached, I want to immediately place a new limit and stop order (of different sizes) based around this limit price.

    Please could you tell me the best way of doing this?



  • use notify_order in the strategy - you will get notified for the changes in the order statuses you submitted.



  • @samy-david I understand that, and already have notify_order in my strategy. Currently, use it to log various details of orders depending on their order.status.

    However, I place all orders in the next() method, and can't seem to get the order.status whilst in next(). It seems I need a way of using the order.status in order to trigger the second trade (i.e. when the previous limit order is executed)


  • administrators

    @maxpaton said in Secondary limit/stop order:

    I currently place a market order, along with a limit order and stop order (of different sizes), all at the same time in next(). If that limit price is reached, I want to immediately place a new limit and stop order (of different sizes) based around this limit price.

    There may something missing in your explanation or I may be missing the entire idea. See:

    • I currently place a market order, along with a limit order and stop order

      You have placed the Limit order so you know the actual limit_price which you want.

    • If that limit price is reached, I want to immediately place a new limit and stop order (of different sizes) based around this limit price.

      As pointed out above, you know the limit_price because you have placed the Limit order. It is then trivial to conclude that the limit_price has been reached when examinig the OHLC prices in next:

          if self.data.low <= limit_price <= self.data.high:
              # place new orders around `limit_price`
      

    Of course it is unknown where you are storing (or where you wan to store) the limit_price

    Is there anything which I have missed?

    The suggestion from @Samy-David is to use the Completed status of the execution of the first Limit order as an indication that the price has been reached, saving some management. Nothing forbids from placing new orders from inside notify_order.



  • @backtrader It doesn't seem like you've missed anything, no. It had occurred to me that I could place the secondary order in notify_order(), but I just thought you couldn't as I had never seen done it anywhere else.

    It looks like I should be able to get my algo working by placing the secondary order (on occurrence of order.Completed), in notify_order()!

    Thanks for the clarification, and will let you know if I have any further problems in relation to this post.