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



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



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


Log in to reply
 

});