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/

    Question about Stop Loss Trading article

    Indicators/Strategies/Analyzers
    2
    2
    58
    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.
    • P
      petehe last edited by

      Hi All
      I have a question regarding Stop Loss Trading article
      https://www.backtrader.com/blog/posts/2018-02-01-stop-trading/stop-trading/
      why do we need to have a parent child order to do stop loss?

          def next(self):
              if not self.position and self.crossup > 0:
                  if self.buy_order:  # something was pending
                      self.cancel(self.buy_order)
      
                  # not in the market and signal triggered
                  if not self.p.buy_limit:
                      self.buy_order = self.buy(transmit=False)
                  else:
                      price = self.data.close[0] * (1.0 - self.p.buy_limit)
      
                      # transmit = False ... await child order before transmission
                      self.buy_order = self.buy(price=price, exectype=bt.Order.Limit,
                                                transmit=False)
      
                  # Setting parent=buy_order ... sends both together
                  if not self.p.trail:
                      stop_price = self.data.close[0] * (1.0 - self.p.stop_loss)
                      self.sell(exectype=bt.Order.Stop, price=stop_price,
                                parent=self.buy_order)
                  else:
                      self.sell(exectype=bt.Order.StopTrail,
                                trailamount=self.p.trail,
                                parent=self.buy_order)
      

      I thought we could we can use something like below to do both buy and stop loss together

      self.buy(size=1, exectype=bt.Order.StopTrail, trailamount=0.25)
      
      A 1 Reply Last reply Reply Quote 0
      • A
        ab_trader @petehe last edited by

        @petehe The line you posted issues buy trailing stop order only.

        1 Reply Last reply Reply Quote 1
        • 1 / 1
        • First post
          Last post
        Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
        $(document).ready(function () { app.coldLoad(); }); }