Help building a late day breakout scanner

stockula

stockula

New member
VIP
Hi folks, I hope everyone is well.

I am trying to construct a basic late day breakout scanner on tos. I don't think it requires scripting, as much as knowing which settings to apply on the tos scanner. I was hoping someone could help me with it, it would be greatly appreciated. It is best approached on a 5min time frame.

Setup conditions BULL:
-Stock is trading above prior DAY close
-stock is trading above current day's opening price
-the stock is trading sideways/chopping AT OR NEAR hod for at least 1.5 hours (more accurately, eighteen 5min candles)

-Entry trigger, upside break of the chop zone high bar (preferably slightly lower than the hod)
-Stop loss set to below the low of the chop zone

Setup conditions BEAR:
-Stock is trading below prior DAY close
-stock is trading below current day's opening price
-the stock is trading sideways/chopping AT OR NEAR lod for at least 1.5 hours (more accurately, eighteen 5min candles)

Bear trigger is downside break of chop zone low, stop loss, upside break of chop zone high.

So depending on the stock, its a pretty nice tight stopped setup that can catch late day surges. I'm not sure how to incorporate the prior day close conditions to a 5min candle scan.

Any help is appreciated.

Note: The setup is great, and can fail miserably like any other setup. The entry trigger is not set in stone, but I personally prefer to wait for momentum before jumping in. Also, those who are familiar with the "Opening range break" indicator we have on the forums, I can see ways to incorporate the opening range lines with late day breaks.

Any help with the scanner is greatly apprecaited. Thanks folks.
 
BenTen

BenTen

Administrative
Staff
VIP
There are a couple of existing indicators that you can use to fulfill some of the conditions you mentioned above.

Use the script below to scan for stocks trading above or below its previous day's close.

Code:
# Previous Day's Close

input aggregationPeriod = AggregationPeriod.DAY;
def close = close(period = aggregationPeriod)[1];
plot prev_close = close;
Use the script below to scan for stocks trading above or below its current day's opening price.

Code:
input aggregationPeriod = AggregationPeriod.DAY;
def open = open(period = aggregationPeriod);
plot current_open = open;
These two conditions will help you gather a filtered basket of stocks, and then from there, you can continue to filter out the stocks that you want based on your third condition.
 
J

Jynx

New member
I use this code in the morning to filter through stocks that are already moving outside their normal range daily range but it could work for sort of for that 3rd condition...it will look over the last 20 bars and average out the high and low and will alert you if the range for that bar jumps above the avg range by 150% signaling some sort of breakout or breakdown
put this code in a study then in when scanning add a custom study as a filter using thinkscript option put in the following code to scan
for scanner...
rangehist().rangepercentage is greater than 150

now set it to 5 min in the scan

Code:
#RangeHist
declare lower;
def todaysrange=(high-low);
def yesterdaysrange=(high[1]-low[1]);
def range3=(high[3]-low[3]);
def range4=(high[4]-low[4]);
def range5=(high[5]-low[5]);
def range6=(high[6]-low[6]);
def range7=(high[6]-low[6]);
def range8=(high[7]-low[8]);
def range9=(high[9]-low[9]);
def range10=(high[10]-low[10]);
def range11=(high[11]-low[11]);
def range12=(high[12]-low[12]);
def range13=(high[13]-low[13]);
def range14=(high[14]-low[14]);
def range15=(high[15]-low[15]);
def range16=(high[16]-low[16]);
def range17=(high[17]-low[17]);
def range18=(high[18]-low[18]);
def range19=(high[19]-low[19]);
def range20=(high[20]-low[20]);

plot rangevalue=todaysrange;
rangevalue.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
rangevalue.SetLineWeight(3);
def avgrange=((todaysrange+yesterdaysrange+range3+range4+range5+range6+range7+range8+range9+range10+range11+range12+range13+range14+range15+range16+range17+range18+range19+range20)/20);
plot avgrange1=avgrange;
def rangepercentage=((todaysrange/avgrange)*100);
AddLabel(yes, (roundDown(rangevalue/avgrange)*100)+ " % Daily");
def avgclose=average(close,20);
def rangepercentofavgclose =((avgrange/avgclose)*100);
AddLabel(yes, (roundDown(avgrange/avgclose)*100)+ " %Avg Close");
 
H

HighBredCloud

Well-known member
VIP
@Jynx So this needs to be turned into a scanner? Can you copy and paste exactly how you have it in your Think Scrip editor to work as a scanner? Or do you need to set this as a study first before you scan? If so what conditions do you need to set to make this work correctly?
 
stockula

stockula

New member
VIP
@Jynx that is awesome. I’ll give that a shot as soon as I get to my desk. Truly appreciate the help !
 
J

Jynx

New member
@HighBredCloud @stockula @BenTen
Save the code as a study named RangeHist...No it doesn't need to be turned into a scanner you can just use the internal variables as a reference for the scan so in the scanner choose study then custom study and put the following code in the thinkscript (be sure to name the study RangeHist)
#Code:
RangeHist().Rangepercentage is greater than 100
#end code
That will single out all the stocks that have already moved more than there avg range over the last 20 periods so if you set it to Days it will be over the last 20 days if you set it to 5 min it will be over the last 20- 5 min bars generally in the first 5 minutes you'll get about 100 or so that have moved more than there avg range for an entire avg day and those are the one you want to trade, I use to go by relative volume but its a lot harder to code that for the first few minutes of the day this was a work around that basically generated the same ideas if the relative volume is a lot higher the range was sure blow up too

There is another variable in the study that I added that gives you the percentage of AVG range for the last 20 periods divided by the the AVG close for those 20 periods so you can see what percentage the range is relative to the close price higher percentage means more movement in the stock price relative to other stocks for instance today aapl was 113% of its daily range and the avg range is approximately 3% of its close but Macys was 106% of its Daily Range but its avg range is 6% of its close so if your trading macys your probably going to get more bang for your buck than if you are trading appl
the code for that variable is
#code:
RangeHist().rangepercentofavgclose is greater than 3
#end code
where the last number is the minimum percent you want to search for
 
J

Jynx

New member
@stockula @HighBredCloud Here is a modified version for a watchlist column... for the range percentage that is color based I would set it to five min, so just scan for your first 2 variables then save as a watchlist add this as a column, I was thinking about your strategy you might want to incorporate some new high(bullish) or low(bearish) of the day counter that counts new highs in a given period set of 2 min periods seems like the strategy would be more successful if there was a trend of like 10 new hod instead of just near the one and done hod then chop/ just sell off bc then the chop is more likely to be consolidation/basing for the next move...I also would like to mention if the open range is really high it will be like 2-3 hours before the avg calms down on my code so that the current range might exceed the avg on a 5 min time frame just an fyi, I might explore using a ema instead of a sma in the code later on


Code:
declare lower;
def todaysrange=(high-low);
def yesterdaysrange=(high[1]-low[1]);
def range3=(high[3]-low[3]);
def range4=(high[4]-low[4]);
def range5=(high[5]-low[5]);
def range6=(high[6]-low[6]);
def range7=(high[6]-low[6]);
def range8=(high[7]-low[8]);
def range9=(high[9]-low[9]);
def range10=(high[10]-low[10]);
def range11=(high[11]-low[11]);
def range12=(high[12]-low[12]);
def range13=(high[13]-low[13]);
def range14=(high[14]-low[14]);
def range15=(high[15]-low[15]);
def range16=(high[16]-low[16]);
def range17=(high[17]-low[17]);
def range18=(high[18]-low[18]);
def range19=(high[19]-low[19]);
def range20=(high[20]-low[20]);

#plot rangevalue=todaysrange;
#rangevalue.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
#rangevalue.SetLineWeight(3);
def avgrange=((todaysrange+yesterdaysrange+range3+range4+range5+range6+range7+range8+range9+range10+range11+range12+range13+range14+range15+range16+range17+range18+range19+range20)/20);
#plot avgrange1=avgrange;
def rangepercentage=((todaysrange/avgrange)*100);
#AddLabel(yes, (roundDown(todaysrange/avgrange)*100)+ " % Daily");
plot rangepercentage1=rangepercentage;
def avgclose=average(close,20);
def rangepercentofavgclose =((avgrange/avgclose)*100);
#AddLabel(yes, (roundDown(avgrange/avgclose)*100)+ " %Avg Close");
def condition1 = rangepercentage1 <50;
def condition2 = rangepercentage1 >100 and rangepercentage1 is less than 150;
def condition3 = rangepercentage1 >150 and rangepercentage1 is less than 200;
def condition4 = rangepercentage1 >200 and rangepercentage1 is less than 300;
def condition5 = rangepercentage1 >300;

AssignBackgroundColor(if condition1 then color.blue else if condition2 then color.green else if condition3 then color.yellow else if condition4 then color.orange else if condition5 then color.red else color.gray);
 
H

HighBredCloud

Well-known member
VIP
@Jynx Thanks for getting back to me on this...Will give this a go and see how it goes...testing some other scanners as we speak...IF I run into any questions I will let you know.
 

Similar threads

Top