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/

    Secondary limit/stop order

    General Code/Help
    3
    5
    894
    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.
    • M
      maxpaton last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • S
        Samy David last edited by

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

        M 1 Reply Last reply Reply Quote 0
        • M
          maxpaton @Samy David last edited by maxpaton

          @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)

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

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

            M 1 Reply Last reply Reply Quote 0
            • M
              maxpaton @backtrader last edited by

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

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