Backtrader Community

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

    Is exectype parameter of order_target_* ignored?

    General Discussion
    3
    5
    1360
    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.
    • E
      Ed Bartosh last edited by

      If I create stop order using order_target* calls the order is immediately filled even if current security price isn't even close to the order stop price. Is it a bug or I'm missing something?

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

        From order_target_size for example:

            def order_target_size(self, data=None, target=0,
                                  price=None, plimit=None,
                                  exectype=None, valid=None,
                                  tradeid=0, **kwargs):
        
        ...
        ...
                    return self.buy(data=data, size=target - possize,
                                    price=price, plimit=plimit,
                                    exectype=exectype, valid=valid,
                                    tradeid=tradeid, **kwargs)
        ....
        ....
        

        Not it's not being ignored. It is also unknown what you actually do.

        E 1 Reply Last reply Reply Quote 0
        • E
          Ed Bartosh @backtrader last edited by

          You're right. It's not being ignored. It's something else, but I wasn't able to figure that out yet :(

          Now I can see the same thing even when I use self.buy(...)

          It is also unknown what you actually do.

          I'm trying to create stop loss order for short position. Here is my log:

          info: 2015-01-27 10:00:00, AAPL: price: 111.1
          info: 2015-01-27 10:00:00, short entry order 14, stock = AAPL, size = 958
          info: 2015-01-27 10:01:00, AAPL: 14 order executed: price: 111.10, value: -106433.80, commm 0.00, cost basis: 111.10, stock price: 111.02
          info: 2015-01-27 10:02:00, AAPL: price: 111.22
          info: 2015-01-27 10:02:00, (short position) stop loss order 15, stock = AAPL, entry price = 111.1, stop price = 111.882110705
          info: 2015-01-27 10:04:00, AAPL: 15 order executed: price: 111.88, value: -106433.80, commm 0.00, cost basis: 111.10, stock price: 111.05
          info: 2015-01-27 10:04:00, Trade value: 0.00, P/L -749.26, P/L comm: -749.26
          

          As you can see my stop loss order gets executed almost immediately, but current stock price 111.05 is far from stop price 111.88
          Any idea what could be the reason?

          I'm using this code to create the order:

          self.buy(data, size=position.size, price=stop_price, exectype=bt.Order.Stop)
          
          E 1 Reply Last reply Reply Quote 0
          • E
            Ed Bartosh @Ed Bartosh last edited by

            figured that out. the stop price was actually triggered. The high for the bar is higher than the stop price. As always, the explanation is simple, but it takes time to find it out :)

            1 Reply Last reply Reply Quote 0
            • Hi. Candyreview
              Hi. Candyreview last edited by

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