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/

    Stop-Loss order is getting value from Parent Order even if sized passed in

    General Code/Help
    execution order
    1
    1
    69
    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.
    • Bo Vargas
      Bo Vargas last edited by

      I have the following order with a stop-loss attached. The problem is the Buy Limit order will be reverse the position from Short -> Long; But I need the Stop-Loss size should be for the balance.

      Example
      Current Position -2 (short)
      Buy 4 (long)
      New Position 2 (long)
      StopLoss Order is 4. I'm passing in the size 2. But somehow this is getting overwritten.

      Does anyone know how to fix this? I don't want to submit an order to close the existing position and then open a new order.

      self.order = self.buy(exectype=bt.Order.Limit,
                                        size=size,
                                        price=p1,
                                        tif='GTD',
                                        goodTillDate=gtd.strftime('%Y%m%d %H:%M:%S GMT'),
                                        account=self.account,
                                        transmit=False)
      
      o2 = self.sell(exectype=bt.Order.Stop,
                                 price=sp,
                                 valid=valid2,
                                 account=self.account,
                                 parent=self.order,
                                 size=stop_size,  # We want the stop loss to be half our position; meaning don't reverse
                                 transmit=True)
      
                  logging.info('{}: Oref {} / Sell Stop at {}'.format(self.datetime.date(), o2.ref, sp))
      
      1 Reply Last reply Reply Quote 0
      • 1 / 1
      • First post
        Last post
      Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors