Stop loss never triggered
Author: dankimel
Creation Date: 8/20/2009 7:59 PM
profile picture

dankimel

#1
The following code is supposed to get me out of a position at the close or limit my losses to 3% with a stop loss order. However, when I backtest it on a data set, the stop loss exit is never triggered, even though some of the losses are larger than 3%. Any suggestions about what I'm doing wrong?

CODE:
Please log in to see this code.
profile picture

Cone

#2
The code unconditionally sells at the close on the bar after entry, so there's no active Position to sell when the stop order is hit.

Also,
CODE:
Please log in to see this code.
profile picture

dankimel

#3
Thanks for the suggestion. But wouldn't your change never be executed since the code unconditionally sells at the close on the bar of entry(a day trade)?

What I want is for the position to be sold at the close on the bar of entry (a day trade) only if I'm not stopped out at 3% loss during the bar of entry.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).