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();

ByDwKng.png
 
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

@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();

ByDwKng.png
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.
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):
CC4a5Na.png

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 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();

ByDwKng.png
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!!
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
490 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

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?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top