52-week Highs/Lows For ThinkOrSwim

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:
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
2t1VzHB.png


Those are built in columns already in both the scanner and the watchlist.
 
I'd like to create a column on my watchlist that shows the % difference between the last price and the 52 week low. E.g. if the last price of BA is 355 and the 52 week low is 300, I'd like to have a column on my watchlist that shows the % difference between 355 and 300 i.e. 55/300 = 18.33%. Thanks.
 
Hi everyone,

I am trying to figure out how to be alerted when a stock in my watch list hits a new 52 week high or low. I can't figure it out. Can anyone help?

Thanks.
 
Here is a scan for stocks hitting 52-week high. Loading this into the scanner on a daily aggregation on the S&P 500, I get 16 results. There were no results for stocks hitting 52 weeks low on the S&P 500

Code:
High == Highest(High(period = "DAY"), 252)
 
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:
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);
 
Hello,
Looking to plot 52 week high and 52 week low once and not dynamically update (recalculate) with each tick.

Code:
def Start;
def Finish;

if (GetUnderlyingSymbol() == GetSymbol())
{
    Start = Highest(high, 252);
    Finish = Lowest(low, 252);
}
else
{
    Start = Double.NaN;
    Finish = Double.NaN;
}
 
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
 
@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 ------------------
 
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
 
Using this to show a dashed line for 52wk high, how can i add a price bubble to show on the right axis

Code:
def a = Highest(high, 252);
def barNumber = barNumber();
def bar = if IsNaN(a)
then Double.NaN
else BarNumber();
def ThisBar = HighestAll(bar);
def Line = if bar == ThisBar
then a
else Double.NaN;
plot P = if ThisBar
then HighestAll(Line)
else Double.NaN;
P.SetStyle(Curve.Short_Dash);
P.SetLineWeight(1);
P.SetDefaultColor(CreateColor(75,250,150));
 
@Nikola Add the following snippet to the bottom of your script:

Code:
input showBubble = yes;
def SR = showBubble and !IsNaN(close) and IsNaN(close [-1] ) && HighestAll(BarNumber());
AddChartBubble(SR and p, HighestAll(Line), "Highest", Color.RED, yes);
 
@Nikola Here you go:

Code:
def a = Lowest(low, 252);
def barNumber = barNumber();
def bar = if IsNaN(a)
then Double.NaN
else BarNumber();
def ThisBar = HighestAll(bar);
def Line = if bar == ThisBar
then a
else Double.NaN;
plot P = if ThisBar
then HighestAll(Line)
else Double.NaN;
P.SetStyle(Curve.Short_Dash);
P.SetLineWeight(1);
P.SetDefaultColor(CreateColor(75,250,150));

input showBubble = yes;
def SR = showBubble and !IsNaN(close) and IsNaN(close [-1] ) && HighestAll(BarNumber());
AddChartBubble(SR and a, HighestAll(Line), "Lowest", Color.Green, yes);
 
It wont work in the same script because the "def a" and "plot p".

Can the bubbles be moved to the left so they don't block stuff?
 
Last edited by a moderator:
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.
 

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

Thread starter Similar threads Forum Replies Date
inthefutures New Intraday Highs and Lows For ThinkOrSwim Indicators 0

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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