How to reenter at a better price after a stop loss
A reader of this blog wanted to know how he could reenter a position at a better price if the first attempt turned out to be a loser. Here I am working with 5 minute bars, but the concepts work for daily bars too. The daily bar is quite a bit easier to program.
ES.D Day Trade using 30 minute Break Out
Here we are going to wait for the first 30 minutes to develop a channel at the highest high and the lowest low of the first 30 minutes. After the first 30 minutes and before 12:00 pm eastern, we will place a buy stop at the upper channel. The initial stop for this initial entry will be the lower channel. If we get stopped out, then we will reenter long at the midpoint between the upper and lower channel. The exit for this second entry will be the lower channel minus the width of the upper and lower channel.
Here are some pix. It kinda, sorta worked here – well the code worked perfectly. The initial thrust blew through the top channel and then immediately consolidated, distributed and crashed through the bottom channel. The bulls wanted another go at it, so they pushed it halfway to the midpoint and then immediately the bears came in and played tug of war. In the end the bulls won out.
Here the bulls had initial control and then the bears, and then the bulls and finally the bears tipped the canoe over.
This type of logic can be applied to any daytrade or swing trade algorithm. Here is the code for the strategy.
The key concepts here are the time constraints and how I count bars to calculate the first 30 – minute channel. I have had problems with EasyLanguages’s entriesToday function, so I like how I did it here much better. On the first bar of the day, I set my variable totTrades to EasyLanguages built-in totalTrades (notice the difference in the spelling!) The keyword TotalTrades is immediately updated when a trade is closed out. So, I simply subtract my totTrades (the total number of trades at the beginning of the day) from totalTrades. If totalTrades is incremented (a trade is closed out) then the difference between the two variables is 1. I assign the difference of these two values to longEntriesToday. If longEntriesToday = 1, then I know I have entered long and have been stopped out. I then say, OK let’s get back long at a better price – the midpoint. I use the longEntriesToday variable again to determine which exit to use. With any luck the initial momentum that got us long initially will work its way back into the market for another shot.
It’s Easy to Create a Strategy Based Indicator
Once you develop a strategy, the indicator that plots entry and exit levels is very easy to derive. You have already done the math – just plot the values. Check this out.
So, that’s how you do it. You can use this code as a foundation for any system that wants to try and reenter at a better price. You can also use this code to develop your own time based break out strategy. In my new book, Easing Into EasyLanguage – the Daytrade Edition I will discuss topics very similar to this post.