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 Order with Short Trades

    General Code/Help
    1
    2
    171
    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
      wendellmartin last edited by

      I have been using your fantastic software to do some testing of some technical trading strategies I have been learning in a course. I have a basic framework operational. The strategy calls for long and short trades, and setting stops, and adjusting those stops over time.

      What I am seeing is that the stop seems to work as expected for the long trades, but not work at all for the short trades. Essentially as soon as the stop order is processed, the short trade triggers immediately, rather than taking the direction of the trade into account--as it would if I were to set a stop higher than the current price for a long trade. It makes me suspect that either I am doing something wrong, or there is a hidden assumption of long in the implementation of the stop order.

      Here's how I'm creating the stop order:

          def adjustStop(self):
              if self.openTradeDirection=="long":
                  self.log('CLOSE-STOP created long at {}'.format(self.last.low))
                  self.order = self.close(exectype=bt.Order.Stop, price=self.last.low)
              else:
                  self.log('CLOSE-STOP created short at {}'.format(self.last.high))
                  self.order = self.close(exectype=bt.Order.Stop, price=self.last.high)
      
      

      Can anyone help me understand what I am doing wrong? Is the stop functionality not working for short trades?

      1 Reply Last reply Reply Quote 0
      • W
        wendellmartin last edited by

        Please disregard! A copy paste error in another part of the code was causing this behavior, nothing in the stop functionality.

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