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/

    Sell when exit conditions are met or trailing stop loss?

    Indicators/Strategies/Analyzers
    trailing stop loss
    1
    1
    199
    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.
    • W
      wykazox last edited by

      Hi everyone,

      Not sure if my question makes sense...

      Say I want to do a simple MA crossover strategy for entry and exit.
      But I just want to add a trailing stop loss to protect myself, just in case.

      How would I implement the sell orders so that I exit my position either when the exit conditions are met (MA crossdown) or when the trailing stop loss is triggered?

      At the moment, I have this code, but I am not sure it is actually doing what I intended...
      (i.e. it might actually look for trailing stop loss trigger after the crossdown occurs, instead of looking for either a crossdown OR a trailing stop loss trigger)

      elif self.order is None:
          if self.MAfast < self.MAslow:
              self.order = self.sell(exectype=bt.Order.StopTrail, trailpercent=self.p.trailpercent)
      

      Thanks to this knowledgeable community for helping!

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