# Reentry of Long at better price

## 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.

``//working with 5 minute bars here//should work with any time frameinput:startTradeTime(0930),numOfBarsHHLL(6),stopTradeTime(1200),maxLongEntriesToday(2);vars: startTime(0),endTime(0),barCountToday(0),totTrades(0),mp(0),longEntriesToday(0),periodHigh(-99999999),periodLow(99999999);startTime = sessionStartTime(0,1); endTime = sessionStartTime(0,1); if t = calcTime(startTime,barInterval) Thenbegin	periodHigh = -99999999;	periodLow = 99999999;	barCountToday = 1;	totTrades = totalTrades;end;if barCountToday <= numOfBarsHHLL ThenBegin	periodHigh = maxList(periodHigh,h);	periodLow = minList(periodLow,l);end;barCountToday = barCountToday + 1;longEntriesToday = totalTrades - totTrades;mp = marketPosition;if t <= stopTradeTime and barCountToday > numOfBarsHHLL ThenBegin	if longEntriesToday = 0 then 		buy("InitBreakOut") next bar at periodHigh + minMove/priceScale stop;	if longEntriesToday = 1 Then		buy("BetterBuy") next bar at (periodHigh+periodLow)/2 stop;end;if mp = 1 then	if longEntriesToday = 0 then sell("InitXit") next bar at periodLow stop;	if longEntriesToday = 1 then sell("2ndXit") next bar at periodLow - (periodHigh - periodLow) stop;SetExitOnClose;	``

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.

``//working with 5 minute bars here//should work with any time frameinput:startTradeTime(0930),numOfBarsHHLL(6);vars: startTime(0),endTime(0),barCountToday(0),periodHigh(-99999999),periodLow(99999999);startTime = sessionStartTime(0,1); endTime = sessionStartTime(0,1); if t = calcTime(startTime,barInterval) Thenbegin	periodHigh = -99999999;	periodLow = 99999999;	barCountToday = 1;end;if barCountToday <= numOfBarsHHLL ThenBegin	periodHigh = maxList(periodHigh,h);	periodLow = minList(periodLow,l);end;if barCountToday < numOfBarsHHLL Thenbegin	noPlot(1);	noPlot(2);	noPlot(3);	noPlot(4);EndElsebegin	plot1(periodHigh,"top");	plot2((periodHigh+periodLow)/2,"mid");	plot3(periodLow,"bot");	plot4(periodLow - (periodHigh - periodLow),"2bot");end;barCountToday = barCountToday + 1;``

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.

### Discover more from George Pruitt

Subscribe to get the latest posts sent to your email.