ThinkOrSwim 52-week Highs/Lows Scanner and Watchlist Column

mo2020

New member
52-week high/low is the highest and lowest price at which a stock has traded during the previous year. It is a technical indicator used by some traders and investors who view the 52-week high or low as an important factor in determining a stock's current value and predicting future price movement.

"Paris: Here's a watchlist you can use for percentage off 52 week high. For 52 week low, you can modify this."

Code:
# Percentage Off 52 Week High Watchlist
# Nick Name NAG®
# 11.02.2015

# This assumes a daily aggregation.  You will need to use
# daily or higher, adjust the 252 length as needed.

Round((close / Highest(high, 252) - 1) * 100)
 
Last edited:

rad14733

Well-known member
VIP
Try this code...

Ruby:
#PlotPctDiffDays
#plot price percent above or below close
#days: 5 = week, 22 = month, 252 = year
#pct positive for above, negative for below
#Change Highest to Lowest for finding lowest low
#Coded by rad14733 for usethinkscript.com
#v1.0 : 2021-02-06 : Initial Release

input days = 252;
input price = high;
input pct = 5;

plot data = Highest(price, days) * (1 + (pct / 100));

#END - PlotPctDiffDays
 

MarcVUM

New member
vertical or horizontal line? and to understand you... you want the line drawn 5% below the 52 week high or all time high.
Horizontal line. 52 week high. I have been manually updating the 5%, 10% and 15% horizontal lines on SPX for years. Thanks!

Try this code...

Ruby:
#PlotPctDiffDays
#plot price percent above or below close
#days: 5 = week, 22 = month, 252 = year
#pct positive for above, negative for below
#Change Highest to Lowest for finding lowest low
#Coded by rad14733 for usethinkscript.com
#v1.0 : 2021-02-06 : Initial Release

input days = 252;
input price = high;
input pct = 5;

plot data = Highest(price, days) * (1 + (pct / 100));

#END - PlotPctDiffDays
That's It! Thank you sir!
 

XeoNoX

Well-known member
VIP
@MarcVUM welll i already put the time into it, so figured ide post it anyways, here is a slighly different version of what you requested

Draws Line at the SPECIFIED DAY/WEEK/MONTH HIGH
Draws Secondary Line XYZ Percent away from the SPECIFIED HIGH

DEFAULT IS DRAWS LINE AT 12 MONTH HIGH and ANOTHER LINE AT -5% AWAY
Plots on different time frames
Remember to like if you found this post useful

8aY6AX4.png



Code:
#By XeoNoX via usethinkscript.com
#Draws Line at the SPECIFIED DAY/WEEK/MONTH HIGH
#Draws Secondary Line XYZ Percent away from the SPECIFIED HIGH
#DEFAULT IS  DRAWS LINE AT 12 MONTH HIGH and ANOTHER LINE AT -5% AWAY
input baseperiod =  {default MONTH, WEEK, DAY};
# Specify The number number of basePeriod periods to go back
Input ago = 12;
#Specify The Percent value you want to draw your secondary line
Input percent_away_to_draw = -5;
Input ShowPercentlabel = yes;
Input ShowMainLabel = yes;
plot PriceValue = HighestAll(if IsNaN(Highest(high(period=BasePeriod), ago)[-1]) and !IsNaN(Highest(high(period = BasePeriod), ago)) then Highest(high(period = BasePeriod), ago) else Double.NaN);
Plot PriceValuePercent = (PriceValue * (.01*percent_away_to_draw)) + pricevalue ;
AddLabel (ShowPercentlabel,  Round(PriceValuePercent,2) +" is " +percent_away_to_draw + "% from" + ago +" "+ baseperiod  + " High" );
AddLabel (ShowMainlabel, ago + " " + BasePeriod + " High:  " + round(PriceValue,2) );
PriceValue.SetDefaultColor(Color.Cyan);
PricevaluePercent.SetDefaultColor(Color.yellow);
 

Almighty1

New member
52-week high/low is the highest and lowest price at which a stock has traded during the previous year. It is a technical indicator used by some traders and investors who view the 52-week high or low as an important factor in determining a stock's current value and predicting future price movement.

"Paris: Here's a watchlist you can use for percentage off 52 week high. For 52 week low, you can modify this."

Code:
# Percentage Off 52 Week High Watchlist
# Nick Name NAG®
# 11.02.2015

# This assumes a daily aggregation.  You will need to use
# daily or higher, adjust the 252 length as needed.

Round((close / Highest(high, 252) - 1) * 100)
I have a question on this one, I added this and I noticed for a few securities, it is showing NaN currently as seen below...

2021-02-15-20-45-15.jpg
 

XeoNoX

Well-known member
VIP
Would it be possible instead of using the indicator as we know the 52 week low and 52 week high numbers, to just have a % treating 0 as the 52 week low and 100% as the 52 week high? So basically if the 52 week low was $1.00 and 52 week high was $100.00, and the current price was $49.00, it would show 49%?
here's what you requested, its going to show as the numerical percentage from 0-100 value rather than a histogram.
Be sure to set the scan aggregation to MONTH
(instead of 52 week high, i used 12 month high to account better for leap years)
Code:
def priceHigh = high;
def pricelow = low;
def YearHigh = Highest(priceHigh, 12) ;
def YearLow = Lowest(priceLow, 12) ;
def range = Yearhigh-Yearlow;
def closing_value = close - Yearlow;
def percent = (closing_value/range)*100;
plot scan = percent;
 
Last edited:

BenTen

Administrative
Staff
VIP
@PATrader Here you go

Code:
def priceHigh = high;
def pricelow = low;
def YearHigh = Highest(priceHigh, 12) ;
def YearLow = Lowest(priceLow, 12) ;
def range = Yearhigh-Yearlow;
def closing_value = close - Yearlow;
def percent = (closing_value/range)*100;
AddLabel(yes, Concat("52wk% = ", percent), color.orange);
 

PATrader

New member
VIP
@PATrader Here you go

Code:
def priceHigh = high;
def pricelow = low;
def YearHigh = Highest(priceHigh, 12) ;
def YearLow = Lowest(priceLow, 12) ;
def range = Yearhigh-Yearlow;
def closing_value = close - Yearlow;
def percent = (closing_value/range)*100;
AddLabel(yes, Concat("52wk% = ", percent), color.orange);
Ben, thank you for the code. I checked and the % in the display box seems to be incorrect, compared to the 52w H/L.
Thanks
 

Almighty1

New member
here's what you requested, its going to show as the numerical percentage from 0-100 value rather than a histogram.
Be sure to set the scan aggregation to MONTH
(instead of 52 week high, i used 12 month high to account better for leap years)
Code:
def priceHigh = high;
def pricelow = low;
def YearHigh = Highest(priceHigh, 12) ;
def YearLow = Lowest(priceLow, 12) ;
def range = Yearhigh-Yearlow;
def closing_value = close - Yearlow;
def percent = (closing_value/range)*100;
plot scan = percent;

Many thanks, just tried it with scan aggregation to Month and compared to the script in the OP of this thread using AAPL as a example for today which has the following data:
52 week low $53.1525
52 week high $145.09
Last $130.84

OP script shows -9.82% which would be $130.84
The script above shows 84.5% which would be $122.60105 as it should be 90.18%
 
Last edited:

XeoNoX

Well-known member
VIP
Many thanks, just tried it with scan aggregation to Month and compared to the script in the OP of this thread using AAPL as a example for today which has the following data:
52 week low $53.1525
52 week high $145.09
Last $130.84

OP script shows -9.82% which would be $130.84
The script above shows 84.5% which would be $122.60105 as it should be 90.18%
you requested:
"to just have a % treating 0 as the 52 week low and 100% as the 52 week high"
thats what that script does in post #70 of this thread that i posted.

the OP (post in post #1) is completely different and is the % away from the 252 day high.

Also keep in mind there is a difference from 252 days and 12 months in your calculations.
 

Almighty1

New member
you requested:
"to just have a % treating 0 as the 52 week low and 100% as the 52 week high"
thats what that script does in post #70 of this thread that i posted.

the OP (post in post #1) is completely different and is the % away from the 252 day high.

Also keep in mind there is a difference from 252 days and 12 months in your calculations.
Interesting. Is there a way to actually do it without the timeframe part since the lows and highs for 52 weeks are already defined so for example,
if the 52 week low is $50 and 52 week high is $150. So if the current price was $125, then it would be 75%, $110 would be 60%, $100 would be 50%, $90 would be 40%.
 

XeoNoX

Well-known member
VIP
Interesting. Is there a way to actually do it without the timeframe part since the lows and highs for 52 weeks are already defined so for example,
if the 52 week low is $50 and 52 week high is $150. So if the current price was $125, then it would be 75%, $110 would be 60%, $100 would be 50%, $90 would be 40%.
youre requesting the same thing jus with a different example, the code for that is listed above.
 

Almighty1

New member
youre requesting the same thing jus with a different example, the code for that is listed above.
Did it manually and you are right, the range is basically $91.9375 with YearHigh being 145.09 and YearLow being 53.125 so using that, if the closing was $130.84, which means it moved up $77.6875 from the YearLow so $77.6875/$91.9375=84.5%. Just need to understand how the different scan aggregation works even though one can probably tell that 252 means days in a year and 12 means months in a year.
 

XeoNoX

Well-known member
VIP
Did it manually and you are right, the range is basically $91.9375 with YearHigh being 145.09 and YearLow being 53.125 so using that, if the closing was $130.84, which means it moved up $77.6875 from the YearLow so $77.6875/$91.9375=84.5%. Just need to understand how the different scan aggregation works even though one can probably tell that 252 means days in a year and 12 means months in a year.
you stated:
"Just need to understand how the different scan aggregation works"
its just the basics of distance, rate, and ratio over time
simpler example:
you can drive one kilometer in 2 mins or drive 0.621371 miles in 2 mins.. end result of making it to 1 kilometer in 2 mins is the same because one kilomter is 0.621371 miles. how you decide to mathematically break down the distance traveled per minute inbetween is up to you and the possible varying different statistics in the smaller increments of the drive (which can possibly be more complicated).
 
Last edited:

Almighty1

New member
you stated:
"Just need to understand how the different scan aggregation works"
its just the basics of distance, rate, and ratio over time
simpler example:
you can drive one kilometer in 2 mins or drive 0.621371 miles in 2 mins.. end result of making it to 1 kilometer in 2 mins is the same because one kilomter is 0.621371 miles. how you decide to mathematically break down the distance traveled per minute inbetween is up to you and the possible varying different statistics in the smaller increments of the drive (which can possibly be more complicated).
What I actually meant was I am still new to ThinkorSwim, only used it briefly over 3 months and trying to understand thinkscript which is why I said 252 basically requires a day aggregation while 12 is months, I am sure the aggregation will be set to week if the 12 was changed to 52 since like you said, it's how it's broken down and ofcourse with what I wanted, the results are based on two other variables while for the OP, it's based just on one variable.
 

Similar threads

Top