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.
Size:
Color:
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.
Size:
Color:
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.
Size:
Color: