Range Scan & Column

Tomahawk6117

Member
Plus
Hi everyone,

I would please like to set up a scanner to find the differences in the ranges of a stock. Specifically, I would like to set up a scanner where it determines the range of a stock's price between 9:30 a.m. and 12:00 p.m., and then subtract this value from the same stock's price range between 12:00 p.m. and 4:00 p.m.

For a hypothetical example, for the stock, $AAA the lowest price today between 9:30 a.m. and 12:00 p.m. was $1.37, and the highest price today between 9:30 a.m. and 12:00 p.m. was $2.21, thus the range between 9:30 a.m. and 12:00 p.m. was $0.84. For later in the day, between 12:00 p.m. and 4:00 p.m., the lowest stock price was $1.90 and the highest stock price was $2.10, thus the range was $0.20. As a result, the difference between the morning range, $0.84, and the afternoon range, $0.20, was $0.84-$0.20 = $0.64. Thank you very much in advance for your time and your help.
 
Hi everyone,

I would please like to set up a scanner to find the differences in the ranges of a stock. Specifically, I would like to set up a scanner where it determines the range of a stock's price between 9:30 a.m. and 12:00 p.m., and then subtract this value from the same stock's price range between 12:00 p.m. and 4:00 p.m.

For a hypothetical example, for the stock, $AAA the lowest price today between 9:30 a.m. and 12:00 p.m. was $1.37, and the highest price today between 9:30 a.m. and 12:00 p.m. was $2.21, thus the range between 9:30 a.m. and 12:00 p.m. was $0.84. For later in the day, between 12:00 p.m. and 4:00 p.m., the lowest stock price was $1.90 and the highest stock price was $2.10, thus the range was $0.20. As a result, the difference between the morning range, $0.84, and the afternoon range, $0.20, was $0.84-$0.20 = $0.64. Thank you very much in advance for your time and your help.
you can't scan for a number.
scanning results are driven by true or false conditions. scanning produces a list of stocks, after checking if every condition is true.
what number are you going to compare the numbers to, to determine a true false output?

or do you want a watchlist column of numbers?
 

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

you can't scan for a number.
scanning results are driven by true or false conditions. scanning produces a list of stocks, after checking if every condition is true.
what number are you going to compare the numbers to, to determine a true false output?

or do you want a watchlist column of numbers?
Hi @halcyonguy thank you very much for your reply. I would please like a scan where it tells me if the morning range (9:30 am to 12:00 pm) is greater than the afternoon range (12:00 pm to 4:00 pm).

If I could set it up where I could input a value as well, such as a percentage, that would be a great benefit as well. Such as, the morning range was at least 5% greater than the afternoon range. Thank you very much for your time and your help.
 
Hi @halcyonguy, I believe I was able to come up with a script. I was able to use some of the information you have provided to me previously as well. I have provided the script below, and it seems to be working well in the scans. The code below would be for a 10% greater range in the morning versus the afternoon. Thank you very much for offering your help.

Code:
input openingrangestarttimeest = 930;
input openingrangeendtimeest = 1200;
input percentdiff = 10.0;

def openingrange = if SecondsTillTime(openingrangestarttimeest) <= 0 and SecondsTillTime(openingrangeendtimeest) >= 0 then 1 else 0;

def openingrangehigh = if secondstilltime(openingrangestarttimeest) == 0 then high else if openingrange and high > openingrangehigh[1] then high else openingrangehigh[1];

def openingrangelow = if secondstilltime(openingrangestarttimeest) == 0 then low else if openingrange and low < openingrangelow[1] then low else openingrangelow[1];

def openingrangetotal = openingrangehigh - openingrangelow;

input endingrangestarttimeest = 1201;
input endingrangeendtimeest = 1600;

def endingrange = if SecondsTillTime(endingrangestarttimeest) <= 0 and SecondsTillTime(endingrangeendtimeest) >= 0 then 1 else 0;

def endingrangehigh = if secondstilltime(endingrangestarttimeest) == 0 then high else if endingrange and high > endingrangehigh[1] then high else endingrangehigh[1];

def endingrangelow = if secondstilltime(endingrangestarttimeest) == 0 then low else if endingrange and low < endingrangelow[1] then low else endingrangelow[1];

def endingrangetotal = endingrangehigh - endingrangelow;

def daydiff = round(openingrangetotal - endingrangetotal,2);
def pergain = round(100*daydiff/ endingrangetotal,1);

def sell1 = if pergain >= percentdiff then 1 else 0;

plot z1 = sell1;
 
Hi everyone, I am looking to add a custom column to my scanner to display the range in price during the morning (9:30 a.m. to 12:00 p.m.) and the afternoon (12:01 p.m. to 4:00 p.m.). I was able to have the afternoon price range display correctly, but I am receiving a NaN message for the morning range. The scripts I wrote are identical, the only real difference is the time for the input. Would someone please tell me the mistake I am making? Thank you very much for your time and your help.

This script reports NaN:
Code:
input openingrangestarttimeest = 0930;
input openingrangeendtimeest = 1200;

def openingrange = if SecondsTillTime(openingrangestarttimeest) <= 0 and SecondsTillTime(openingrangeendtimeest) >= 0 then 1 else 0;

def openingrangehigh = if secondstilltime(openingrangestarttimeest) == 0 then high else if openingrange and high > openingrangehigh[1] then high else openingrangehigh[1];

def openingrangelow = if secondstilltime(openingrangestarttimeest) == 0 then low else if openingrange and low < openingrangelow[1] then low else openingrangelow[1];

def difference = openingrangehigh - openingrangelow;

plot z1 = if openingrange then difference else double.nan;

This script reports what I want:
Code:
input endingrangestarttimeest = 1201;
input endingrangeendtimeest = 1600;

def endingrange = if SecondsTillTime(endingrangestarttimeest) <= 0 and SecondsTillTime(endingrangeendtimeest) >= 0 then 1 else 0;

def endingrangehigh = if secondstilltime(endingrangestarttimeest) == 0 then high else if endingrange and high > endingrangehigh[1] then high else endingrangehigh[1];

def endingrangelow = if secondstilltime(endingrangestarttimeest) == 0 then low else if endingrange and low < endingrangelow[1] then low else endingrangelow[1];

def difference = endingrangehigh - endingrangelow;

plot z1 = if endingrange then difference else double.nan;

cL3AxPI.png
 
its showing nan because the current time is not active (not currently that time)... it will work during those times you specified, if the current LIVE time is outside of those times you specified it will show nan. in other words, if the current live time is inside those hours it will show.
time exception is: the final bar on chart will be the last value it recognizes/plots/shows, therefore its showing ending range... hope that makes sense, its early morning and i might not be explaining very well.

i would make the assumption that you would like to have both work at the same times and use one column.
you can try this, i just did it real quick and didnt test it so let me know if it works.

Code:
input openingrangestarttimeest = 0930;
input openingrangeendtimeest = 1200;

def openingrange = if SecondsTillTime(openingrangestarttimeest) <= 0 and SecondsTillTime(openingrangeendtimeest) >= 0 then 1 else 0;

def openingrangehigh = if secondstilltime(openingrangestarttimeest) == 0 then high else if openingrange and high > openingrangehigh[1] then high else openingrangehigh[1];

def openingrangelow = if secondstilltime(openingrangestarttimeest) == 0 then low else if openingrange and low < openingrangelow[1] then low else openingrangelow[1];

def difference = openingrangehigh - openingrangelow;

input endingrangestarttimeest2 = 1201;
input endingrangeendtimeest2 = 1600;

def endingrange2 = if SecondsTillTime(endingrangestarttimeest2) <= 0 and SecondsTillTime(endingrangeendtimeest2) >= 0 then 1 else 0;

def endingrangehigh2 = if secondstilltime(endingrangestarttimeest2) == 0 then high else if endingrange2 and high > endingrangehigh2[1] then high else endingrangehigh2[1];

def endingrangelow2 = if secondstilltime(endingrangestarttimeest2) == 0 then low else if endingrange2 and low < endingrangelow2[1] then low else endingrangelow2[1];

def difference2 = endingrangehigh2 - endingrangelow2;

plot scan  = if endingrange2 then difference2 else if openingrange  then difference else 0;
 
its showing nan because the current time is not active (not currently that time)... it will work during those times you specified, if the current LIVE time is outside of those times you specified it will show nan. in other words, if the current live time is inside those hours it will show.
time exception is: the final bar on chart will be the last value it recognizes/plots/shows, therefore its showing ending range... hope that makes sense, its early morning and i might not be explaining very well.

i would make the assumption that you would like to have both work at the same times and use one column.
you can try this, i just did it real quick and didnt test it so let me know if it works.

Code:
input openingrangestarttimeest = 0930;
input openingrangeendtimeest = 1200;

def openingrange = if SecondsTillTime(openingrangestarttimeest) <= 0 and SecondsTillTime(openingrangeendtimeest) >= 0 then 1 else 0;

def openingrangehigh = if secondstilltime(openingrangestarttimeest) == 0 then high else if openingrange and high > openingrangehigh[1] then high else openingrangehigh[1];

def openingrangelow = if secondstilltime(openingrangestarttimeest) == 0 then low else if openingrange and low < openingrangelow[1] then low else openingrangelow[1];

def difference = openingrangehigh - openingrangelow;

input endingrangestarttimeest2 = 1201;
input endingrangeendtimeest2 = 1600;

def endingrange2 = if SecondsTillTime(endingrangestarttimeest2) <= 0 and SecondsTillTime(endingrangeendtimeest2) >= 0 then 1 else 0;

def endingrangehigh2 = if secondstilltime(endingrangestarttimeest2) == 0 then high else if endingrange2 and high > endingrangehigh2[1] then high else endingrangehigh2[1];

def endingrangelow2 = if secondstilltime(endingrangestarttimeest2) == 0 then low else if endingrange2 and low < endingrangelow2[1] then low else endingrangelow2[1];

def difference2 = endingrangehigh2 - endingrangelow2;

plot scan  = if endingrange2 then difference2 else if openingrange  then difference else 0;
Hi @XeoNoX thank you very much for your help, I really appreciate it. May you please tell me, how would I plot the percentage difference between the opening range and the ending range? Specifically, I am looking to perform:

Percent Difference = (Opening Range - Ending Range) / (Opening Range)

I tried inputting the script below, but it did not provide me with the correct value.

Code:
def perdiff  = (difference-difference2)/ difference;

plot z1 = perdiff;

Thank you very much for your help, I really appreciate it.
 
Hi @XeoNoX thank you very much for your help, I really appreciate it. May you please tell me, how would I plot the percentage difference between the opening range and the ending range? Specifically, I am looking to perform:

Percent Difference = (Opening Range - Ending Range) / (Opening Range)

I tried inputting the script below, but it did not provide me with the correct value.

Code:
def perdiff  = (difference-difference2)/ difference;

plot z1 = perdiff;

Thank you very much for your help, I really appreciate it.
thats correct what you did, it plots correct as shown below, im not sure what you are trying to do. remember it plots the last value (in your case the difference) at the time you specified.



1717349570843.png
 
Last edited:
Hi @XeoNoX thank you very much for your help, I really appreciate it. May you please tell me, how would I plot the percentage difference between the opening range and the ending range? Specifically, I am looking to perform:

Percent Difference = (Opening Range - Ending Range) / (Opening Range)

I tried inputting the script below, but it did not provide me with the correct value.

Code:
def perdiff  = (difference-difference2)/ difference;

plot z1 = perdiff;

Thank you very much for your help, I really appreciate it.

maybe we are thinking of it differently since im seeing it from what your input is vs what you are possibly attempting to do.
there are different ways you can look at what you are possibly attempting to do.
percentage difference between the opening range and the ending range?
im not really sure what that means considering you have it TIME BASED. the difference from one range to the other at the specified time or between both times or from the last recorded time between the two... or at the same time of the different ranges? the lack of you specifying the time and what you want the difference of from what time to what time is confusing, you are comparing ranges and time to get the percent you want, not sure what range you want to compare and at what time to get the percent you want but the script works as you originally described you wanted.
 
Thank you very much for your response @XeoNoX, you are right, the data is correct.
I have one more question if you do not mind @XeoNoX. Why do you think for some symbols the end of day range (12:01 p.m. to 4:00 p.m.) displays a low value of zero, while for some symbols the low value is displayed correctly? This never occurs for the range for the start of the day (9:30 a.m. to 12:00 p.m.). I have included a picture below of what happens sometimes.

Code:
input endingrangestarttimeest = 1201;
input endingrangeendtimeest = 1600;

def endingrange = if SecondsTillTime(endingrangestarttimeest) <= 0 and SecondsTillTime(endingrangeendtimeest) >= 0 then 1 else 0;

def endingrangehigh = if secondstilltime(endingrangestarttimeest) == 0 then high else if endingrange and high > endingrangehigh[1] then high else endingrangehigh[1];

def endingrangelow = if secondstilltime(endingrangestarttimeest) == 0 then low else if endingrange and low < endingrangelow[1] then low else endingrangelow[1];

plot highcloud = if endingrange then endingrangehigh else double.nan;
plot lowcloud = if endingrange then endingrangelow else double.nan;

02Xp3XS.png
 
i was working with the code you provided, but there might be a better way to do what you want, let me try to understand what you are attempting to do OVERALL instead of chopping this study piece by piece.

are you just trying to get the price range (highest high minus the lowest low) that has occurred during the specified time periods? in this case you have 2 time periods, "ending" and "opening".
is this correct to this point?

assuming the previous is correct, then the next part is during those two time periods you are seeking to find the difference of the two ranges? is this correct?
 
i was working with the code you provided, but there might be a better way to do what you want, let me try to understand what you are attempting to do OVERALL instead of chopping this study piece by piece.

are you just trying to get the price range (highest high minus the lowest low) that has occurred during the specified time periods? in this case you have 2 time periods, "ending" and "opening".
is this correct to this point?

assuming the previous is correct, then the next part is during those two time periods you are seeking to find the difference of the two ranges? is this correct?
Thank you very much for both of your replies. That makes sense regarding the low volume. You are exactly correct regarding what I am trying to accomplish. Specifically I would like to calculate the difference between the two ranges as a percentage. Thank you again for all of your time and your help.
 
Thank you very much for both of your replies. That makes sense regarding the low volume. You are exactly correct regarding what I am trying to accomplish. Specifically I would like to calculate the difference between the two ranges as a percentage. Thank you again for all of your time and your help.
as a study label or as a scan or as a column?
 
I was just planning on using it as a scan so that I can collect the data overtime and analyze it. Thank you again for your help, I really appreciate it.
try this, let me know how it works. im still not really too sure what percentage you are trying to get but i added in what i think you were trying to do, HOWEVER the main part of the scan i fixed the issue you were having with it showing 0.

Code:
declare lower;

input start_time1 = 0930;
input end_time1 = 1200;
def Time1 = if GetLastDay() == GetDay() and SecondsFromTime(start_time1) >= 0 and SecondsFromTime(end_time1) <
0 then 1 else 0;
input start_time2 = 1201;
input end_time2 = 1600;
def time2 = if GetLastDay() == GetDay() and SecondsFromTime(start_time2) >= 0 and SecondsFromTime(end_time2) <
0 then 1 else 0;
def ORH   = if ORH[1] == 0 or Time1[1] == 0 and Time1 == 1 then high else if Time1 and high > ORH[1] then high else ORH[1];
def ORL    = if ORL[1] == 0 or Time1[1] == 0 and Time1 == 1 then low else if Time1 and low < ORL[1] then low else ORL[1];
def ERH   = if ERH[1] == 0 or time2[1] == 0 and time2 == 1 then high else if time2 and high > ERH[1] then high else ERH[1];
def ERL    = if ERL[1] == 0 or time2[1] == 0 and time2 == 1 then low else if time2 and low < ERL[1] then low else ERL[1];

#### CHOOSE WHATEVER SCAN/PLOT YOU WANT TO USE FOR COLUMNS AND SCANS YOU CAN ONLY HAVE 1 PLOT
#opening rage high
plot scan1 =  ORH;
AddLabel (yes, "ORH: " +  (ORH)  );
#opening range low
plot scan2 = ORL;
AddLabel (yes, "ORL: " +  (ORL)  );
#end range high
plot scan3 =  ERH;
AddLabel (yes, "ERH: " +  (ERH)  );
#end range low
plot scan4 = ERL;
AddLabel (yes, "ERL: " +  (ERL)  );
#percentage difference between the opening range and the ending range
plot percent_difference = (ORH-ORL)-(ERH-ERL)/(ORH-ORL);
AddLabel (yes, "PercentDifference: " +  (percent_difference)  );
 
try this, let me know how it works. im still not really too sure what percentage you are trying to get but i added in what i think you were trying to do, HOWEVER the main part of the scan i fixed the issue you were having with it showing 0.

Code:
declare lower;

input start_time1 = 0930;
input end_time1 = 1200;
def Time1 = if GetLastDay() == GetDay() and SecondsFromTime(start_time1) >= 0 and SecondsFromTime(end_time1) <
0 then 1 else 0;
input start_time2 = 1201;
input end_time2 = 1600;
def time2 = if GetLastDay() == GetDay() and SecondsFromTime(start_time2) >= 0 and SecondsFromTime(end_time2) <
0 then 1 else 0;
def ORH   = if ORH[1] == 0 or Time1[1] == 0 and Time1 == 1 then high else if Time1 and high > ORH[1] then high else ORH[1];
def ORL    = if ORL[1] == 0 or Time1[1] == 0 and Time1 == 1 then low else if Time1 and low < ORL[1] then low else ORL[1];
def ERH   = if ERH[1] == 0 or time2[1] == 0 and time2 == 1 then high else if time2 and high > ERH[1] then high else ERH[1];
def ERL    = if ERL[1] == 0 or time2[1] == 0 and time2 == 1 then low else if time2 and low < ERL[1] then low else ERL[1];

#### CHOOSE WHATEVER SCAN/PLOT YOU WANT TO USE FOR COLUMNS AND SCANS YOU CAN ONLY HAVE 1 PLOT
#opening rage high
plot scan1 =  ORH;
AddLabel (yes, "ORH: " +  (ORH)  );
#opening range low
plot scan2 = ORL;
AddLabel (yes, "ORL: " +  (ORL)  );
#end range high
plot scan3 =  ERH;
AddLabel (yes, "ERH: " +  (ERH)  );
#end range low
plot scan4 = ERL;
AddLabel (yes, "ERL: " +  (ERL)  );
#percentage difference between the opening range and the ending range
plot percent_difference = (ORH-ORL)-(ERH-ERL)/(ORH-ORL);
AddLabel (yes, "PercentDifference: " +  (percent_difference)  );
Thank you very much for offering your help @XeoNoX, I really appreciate it. I tried used the following script:
plot percent_difference = (ORH-ORL)-(ERH-ERL)/(ORH-ORL)
However, the numbers did not come out the same as the previous script. It is ok though, I really appreciate you offering your help, I believe you have provided me already will allow me to accomplish my goal, thank you again, I really appreciate it.
 
Thank you very much for offering your help @XeoNoX, I really appreciate it. I tried used the following script:

However, the numbers did not come out the same as the previous script. It is ok though, I really appreciate you offering your help, I believe you have provided me already will allow me to accomplish my goal, thank you again, I really appreciate it.
no problem, the main study works good now, its just the formula for the "percentage difference"... im not quite sure what percentage value you are after, but its just a matter of putting in the variables you want.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
564 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