# how to create scan that compares value to high price of a specific time interval?

#### redicarus

##### New member
Hello,

I'm trying to create a scan for an afternoon breakout. The main criteria for the breakout is that the price must move up at least 30% above the high price between open and noon, at any time after noon.

This is meant to run at the end of the day just to check for any occurrences throughout the day. The way I wanted to do that was by getting the high price from open to noon (the morning high), and then checking to see if the price at any point between noon and close (i.e. in the afternoon) was greater than that morning high.

I don't have a lot of experience with thinkscript, but I've tried adapting the code in this post to get what I need. I haven't really been successful. I'm stuck on what a "volume profile" is and how to use it. The documentation is not very helpful.

Any help would be appreciated.

@redicarus scan for 'Above_First_Session_High_Plot' being true.
Ruby:
``````input First_Session_Start_Time = 0930;
input Session_Split_Time = 1200;
input Second_Session_End_Time = 1630;
input Percentage = 0.00;

def First_Session_High;
if SecondsTillTime(First_Session_Start_Time) == 0 {
First_Session_High = high;
} else if high > First_Session_High[1] and SecondsTillTime(Session_Split_Time) >= 0 {
First_Session_High = high;
} else {
First_Session_High = First_Session_High[1];}

plot First_Session_High_Plot= if SecondsFromTime(Session_Split_Time) > 0 and SecondsTillTime(Second_Session_End_Time) >= 0 then First_Session_High+(First_Session_High*Percentage) else Double.NaN;

def Above_First_Session_High = if SecondsTillTime(First_Session_Start_Time) == 0 then 0 else if high > First_Session_High+(First_Session_High*Percentage) then 1 else Above_First_Session_High[1] ;

plot Above_First_Session_High_Plot = Above_First_Session_High;
Above_First_Session_High_Plot.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Above_First_Session_High_Plot.Hide();``````

Last edited:
@redicarus scan for 'Above_First_Session_High_Plot' being true.
Ruby:
``````input First_Session_Start_Time = 0930;
input Session_Split_Time = 1200;
input Second_Session_End_Time = 1630;
input Percentage = 0.0;

def First_Session_High;
if SecondsTillTime(First_Session_Start_Time) == 0 {
First_Session_High = high +(high*Percentage);
} else if high > First_Session_High[1] and SecondsTillTime(Session_Split_Time) >= 0 {
First_Session_High = high +(high*Percentage);
} else {
First_Session_High = First_Session_High[1];}

plot First_Session_High_Plot= if SecondsFromTime(Session_Split_Time) >= 0 and SecondsTillTime(Second_Session_End_Time) >= 0 then First_Session_High else Double.NaN;

def Above_First_Session_High = if SecondsTillTime(First_Session_Start_Time) == 0 then 0 else if high > First_Session_High then 1 else Above_First_Session_High[1] ;

plot Above_First_Session_High_Plot = Above_First_Session_High;
Above_First_Session_High_Plot.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Above_First_Session_High_Plot.Hide();``````

This is great, thank you so much!!

for this part:
Ruby:
``````def First_Session_High;
if SecondsTillTime(First_Session_Start_Time) == 0 {
First_Session_High = high +(high*Percentage);
} else if high > First_Session_High[1] and SecondsTillTime(Session_Split_Time) >= 0 {
First_Session_High = high +(high*Percentage);
} else {
First_Session_High = First_Session_High[1];}``````

why do you add the high multiplied by the percentage?

Edit: I think I understand, it would be the same as doing this instead, right?
Ruby:
``````def Above_First_Session_High =
if SecondsTillTime(First_Session_Start_Time) == 0 then 0
else if high > First_Session_High+(First_Session_High*Percentage) then 1
else Above_First_Session_High[1] ;``````

Last edited:
@redicarus I make a mistake, Your change is correct. Updated the code in last post.

@redicarus I make a mistake, Your change is correct. Updated the code in last post.
oh nice. I'm running into another issue, it seems the script works perfectly fine on some stocks but not all. For example, here's ELAN, one of the stocks that came up when I used the script on the scanner (for 20% breakouts):

several such cases in the screener, not sure if it's because I'm running it at 2AM. I'll try debugging tomorrow, but maybe you could identify the issue more easily.

@redicarus on the chart for ELAN there was no bar at 0930. So as far as the code was concerned 'SecondsTillTime(First_Session_Start_Time) == 0' never happened, so the signal never reset.

@redicarus scan for 'Above_First_Session_High_Plot' being true.
Ruby:
``````input First_Session_Start_Time = 0930;
input Session_Split_Time = 1200;
input Second_Session_End_Time = 1630;
input Percentage = 0.00;

def First_Session_High;
if SecondsTillTime(First_Session_Start_Time) == 0 {
First_Session_High = high;
} else if high > First_Session_High[1] and SecondsTillTime(Session_Split_Time) >= 0 {
First_Session_High = high;
} else {
First_Session_High = First_Session_High[1];}

plot First_Session_High_Plot= if SecondsFromTime(Session_Split_Time) > 0 and SecondsTillTime(Second_Session_End_Time) >= 0 then First_Session_High+(First_Session_High*Percentage) else Double.NaN;

def Above_First_Session_High = if SecondsTillTime(First_Session_Start_Time) == 0 then 0 else if high > First_Session_High+(First_Session_High*Percentage) then 1 else Above_First_Session_High[1] ;

plot Above_First_Session_High_Plot = Above_First_Session_High;
Above_First_Session_High_Plot.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Above_First_Session_High_Plot.Hide();``````

I pasted the code into custom study under scanning. And I get the "1 plot expected" error" And ideas? TY for the scan and for the help!!

87k+ Posts
378 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?