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/

    StopTrail is executing 2 bars after it's cancelled

    Indicators/Strategies/Analyzers
    3
    6
    100
    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.
    • K
      kfue last edited by

      After my limit is reached I sell half of my position and I open a trailing stop at that point for the rest of the amount to "let it ride". I'm using a strategy on 5m intervals so I'm cancelling any orders at the end of the day (30 mins before). The timeframe of what is happening is that a stock's price hits the limit and half of the position gets sold. Then it hits 3:30 and the other half gets sold and I'm cancelling my trailing stop loss. 10 minutes later my trailing stop loss gets triggered even though it should be cancelled? It then shorts the stock which is then immediately bought back 5mins later since it's past 3:30. Is there some type of issue cancelling trailing stops? Or am I misunderstanding something?

      A 1 Reply Last reply Reply Quote 0
      • A
        ab_trader @kfue last edited by

        @kfue

        you may want to share your script if you need answers. Otherwise it will be long guessing game. Highly likely you are not cancelling the order appropriately.

        • If my answer helped, hit reputation up arrow at lower right corner of the post.
        • Python Debugging With Pdb
        • New to python and bt - check this out
        run-out 1 Reply Last reply Reply Quote 1
        • run-out
          run-out @ab_trader last edited by

          @ab_trader said in StopTrail is executing 2 bars after it's cancelled:

          Otherwise it will be long guessing game.

          Actually, probably a very short guessing game.

          RunBacktest.com

          1 Reply Last reply Reply Quote 0
          • K
            kfue last edited by

            @ab_trader @run-out
            Do I need more than this?

            d.orders["limit"].cancel()
            d.orders["stop"].cancel()
            

            Those are my orders, I confirmed the stop went into a cancelled state. Then it went into a completed state as it executed 10 minutes later

            A 1 Reply Last reply Reply Quote 0
            • A
              ab_trader @kfue last edited by

              @kfue according to the docs the order can be cancelled as follows from the strategy:

              self.cancel(order)
              

              definitely you did it different, so i stay with my opinion that you cancelled order inappropriately.

              • If my answer helped, hit reputation up arrow at lower right corner of the post.
              • Python Debugging With Pdb
              • New to python and bt - check this out
              K 1 Reply Last reply Reply Quote 1
              • K
                kfue @ab_trader last edited by

                @ab_trader I believe that was it, I looked at the source code and it looks like calling cancel from the order object simply marks the status as cancelled and doesn't actually cancel the order with the broker. Which was very confusing because of course it wasn't giving an error and when I was printing out the orders they were marked cancelled, but the broker didn't know that.

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