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:

markos

Well-known member
VIP
Try this chart out...
Code:
# This indicator uses the Index New highs and Index New lows to help gauge overall Market sentiment. It's a leading indicator.
# Index New High - New Low Indicator
# Mobius 2015
 
declare lower;
input Symb = {default "NYSE", "NASDQ", "AMEX", "ARCA", "ETF"};
input length = 10;
input OverSold = 20;
input OverBought = 80;
Input AvgType = AverageType.Hull;
 
def agg = AggregationPeriod.Day;
def NYSEH  = close(Symbol = "$NYHGH", period = agg);
def NYSEL  = close(Symbol = "$NYLOW", period = agg);
def NASDQH = close(Symbol = "$NAHGH", period = agg);
def NASDQL = close(Symbol = "$NALOW", period = agg);
def AMEXH  = close(Symbol = "$AMHGH", period = agg);
def AMEXL  = close(Symbol = "$AMLOW", period = agg);
def ARCAH  = close(Symbol = "$ARHGH", period = agg);
def ARCAL  = close(Symbol = "$ARLOW", period = agg);
def ETFH   = close(Symbol = "$ETFHGH", period = agg);
def ETFL   = close(Symbol = "$ETFLOW", period = agg);
def P;
Switch (Symb){   
case "NYSE":
P = NYSEH / (NYSEH + NYSEL) * 100;
case "NASDQ":
P = NASDQH / (NASDQH + NASDQL) * 100;
case "AMEX":
P = AMEXH / (AMEXH + AMEXL) * 100;
case "ARCA":
P = ARCAH / (ARCAH + ARCAL) * 100;
case "ETF":
P = ETFH / (ETFH + ETFL) * 100;
}
def price = if isNaN(P) then price[1] else P;
plot data = if isNaN(close) then double.nan else price;
data.EnableApproximation();
data.SetDefaultColor(Color.Cyan);
plot avg = MovingAverage(AvgType, data, length);
avg.EnableApproximation();
avg.AssignValueColor(if between(avg, OverSold, OverBought)
                     then Color.yellow
                     else if avg >= OverBought
                          then Color.Green
                          else Color.Red);
avg.SetLineWeight(2);
plot OB = if isNaN(close) then double.nan else OverBought;
OB.SetDefaultColor(Color.Red);
plot OS = if isNaN(close) then double.nan else OverSold;
OS.SetDefaultColor(Color.Green);
plot neutral = if isNaN(close) then double.nan else 50;
neutral.SetdefaultColor(Color.Dark_Gray);
addCloud(0, OS, CreateColor(250,0,0), CreateColor(250,0,0));
addCloud(OS, neutral, createColor(50,0,0), createColor(50,0,0));
addCloud(neutral, OB, createColor(0,50,0), createColor(0,50,0));
addCloud(OB, 100, CreateColor(0,250,0), createColor(0,250,0));
# End High - Low Index
 

Jeff1228

New member
Hi, this is great, can you do a scanner, like scanning stocks at 52 weeks low or 10% above. Also, could you please set a different color in the watchlist column to give a warning message?

Thank you

P.S. Did I miss something? I didn't find it in scanner

PP.S. Sorry for the mess, just found it, it's great! But could you please set it a different color in the scanner and watchlist column if it's oversold or overbought? Thanks

Or simply put a percentage there, like, let's say 52 week high is 100, low is 50, now stock is at 60, so (60-50)/(100-50) = 10%, and set it red, how about this?

Thanks
 
Last edited:

stockalerts72

New member
Does anyone have a code for % off 52 week high for a watchlist, search or chart?

This one is for charts:

Code:
# Pct_off _52High_52Low_Chart
# Tos Chatroom, 101615
 
#Percentage Off 52 Week High
#Percentage Off 52 week Low
#ESP 09.08.2015
 
def C = Close;
def FiftyTwoWeekHigh = Highest(High,252);
def FiftyTwoWeekHighPercent = 100-(C /FiftyTwoWeekHigh)*100;
def FiftyTwoWeekLow = Lowest(Low,252);
def FiftyTwoWeekLowPercent = (C/FiftyTwoWeekLow)*100-100;
 
addlabel(1, "% off 52-week high: " + round(fiftytwoweekhighPercent,2), color.dark_orange);
addlabel(1, "% off 52-week low: " + round(fiftytwoweeklowPercent,2), color.dark_orange);
 

Nikola

Member
I was wondering if it was possible to make a chart label that will show on my charts and tell me the ATH or 52wk high
 

BenTen

Administrative
Staff
VIP
@Nikola See this one:

This code creates a custom column for your watchlist that turns green if today is a new 52-week high

Code:
# HINT: right-click on any watchlist column-->>Customize
# click and drag one of the custom choices to add it to your watchlist column choices
# click on ThinkScript tab and replace the code with this code
# BE SURE to give your new column a name and keep the name short enough it will appear on your watchlist at top of the column (ie new 52wk high)
# REMINDER - you can sort your watchlist by this column by clicking on the column header
 
#def allows you to teach ThinkScript new "words" that you can reference later in your code
def newHigh = high is equal to highest(HIGH (period = AggregationPeriod.DAY), 252);
def newLow = low is equal to lowest(LOW (period = AggregationPeriod.DAY), 252);
 
#AddLabel allows you to set conditions such as what words or values will appear when your condition is met.  Yes at the beginning means do show the label ... >=1 or ==1 means when the condition is True then ___ and <=0 or ==) would mean then the condition is False then _____
AddLabel(yes, if newHigh >= 1 then "new 52wk high TODAY" else if newLow >= 1 then "new 52wk low TODAY" else " ");
 
#on a watchlist column AssignBackgroundColor will change the column color when conditions are met.  But AssignBackgroundColor when used in a chart Study or Strategy will change entire chart background
AssignBackgroundColor (if newHigh >= 1 then color.GREEN else if NewLow >= 1 then color.RED else color.LIGHT_GRAY);
 
# end custom column code ------------------
 

Nikola

Member
i was looking more for a chart label so when im charting AH or weekends i can see what 52wk high is or ATH is
 

spencer13579

New member
Hello, I was hoping somebody could help me out with some ThinkScript coding. I'm trying to create a scan that will find stocks in a bull trend that are %50 away from the 52 week high. I figured out how to scan for a bull trend, but anything else is beyond my coding capabilities. If anyone can teach me how to set up a scanner study to screen for stocks %50 below the 52 week high, I should be able to take it from there, and would be grateful. Also, if its not too much trouble, you could let me know how to change it from %50, to %40, %60, %35, and maybe even from 52 weeks to 6 months, or 1 month et cetera, so I can fine tune my strategy. I've tried researching how to do it and use commands from other peoples posts, but nothing has worked so far. Anyways, thanks for any help you can give.


~Spencer C.
 

XeoNoX

Active member
VIP
As per your request here is current price is XYZ Percent away from (52 Week / 1Year / 252Day) High



Code:
##Percent Away From High by XeoNoX via https://usethinkscript.com/
##  Change Percent_value to desired percent
##  Example 3.0 means 3%   1.5 means 1.5%
##  NOTE: 252 is standard agregration for days in a regular trading year according to thinkscript
##  If you want 6 Months change the "PERIOD" to 126 and for a month change to 30, Week change to 7.
##  Be sure to set the Agregation to Day
##
def Percent_value = 50;
def number_of_days = 252;

def price = close;
def choice = High;
def hi = high;
def lo = low;
plot scan = price <= highest(hi,number_of_days )* ((100 - percent_value) /100);
#End of Script
 

HighBredCloud

Well-known member
VIP
@XeoNoX To scan for a new 52 week low...Does anything else need to be updated in your script?

Code:
##Percent Away From High by XeoNoX via https://usethinkscript.com/
##  Change Percent_value to desired percent
##  Example 3.0 means 3%   1.5 means 1.5%
##  NOTE: 252 is standard agregration for days in a regular trading year according to thinkscript
##  If you want 6 Months change the "PERIOD" to 126 and for a month change to 30, Week change to 7.
##  Be sure to set the Agregation to Day
##
def Percent_value = 50;
def number_of_days = 252;

def price = close;
def choice = High;
def hi = high;
def lo = low;
plot scan = price <= lowest(lo,number_of_days )* ((100 - percent_value) /100);
#End of Script
 

XeoNoX

Active member
VIP
you almost had it right, you need to add a negative for the percent value. here is the correct code for scanning for the LOWEST (period) low, in this case this example below scans for stocks within 10% of the 252 day (52 week) low

Code:
##Percent Away From Low by XeoNoX via https://usethinkscript.com/
##  Change Percent_value to desired percent
##  Example -3.0 means 3%   -1.5 means 1.5% away from the (number_of_day/period) low
##  NOTE: 252 is standard agregration for days in a regular trading year according to thinkscript
##  If you want 6 Months change the "PERIOD" to 126 and for a month change to 30, Week change to 7.
##  Be sure to set the Agregation to Day
##
def Percent_value = -10;
def number_of_days = 252;

def price = close;
def choice = High;
def hi = high;
def lo = low;
plot scan = price <= lowest(lo,number_of_days )* ((100 - percent_value) /100);
#End of Script
 

HighBredCloud

Well-known member
VIP
@XeoNoX Thank you for correcting this...As you can tell I am not a coder but trying as much as I can to figure things out on my own...This scan will come in very handy.
 

XeoNoX

Active member
VIP
Thank you for correcting this...As you can tell I am not a coder but trying as much as I can to figure things out on my own...This scan will come in very handy.
Your welcome.... Keep trying and playing with it and asking questions, its how i learned, i didnt mean to learn it, it just happened as i started coming up with ideas and a bunch of trial and error and research. i still have much to learn.
 

Similar threads

Top