52-Week & Current High Low Labels / Bubbles For ThinkOrSwim

Green Trades

New member
Stock's current price vs its 52-week high is a technical indicator
It indicates how much the stock has moved within the 52-wk range.
This information gives insight into the volatility of a stock's price is and its potential future range.

52-week high low is important because it:
serves as a benchmark for a stock's performance
establishes the relative current value of a stock
range represents the fluctuation and risk of a stock.

A stock at its 52-week high attracts institutional interest if a stock is not overvalued.
Therefore, there is a chance of significant gains ahead after any short-term pullback.


tRyqbbT.png



I am stumped, so time to call on the experts. The three lines I want are:
52-week high: [value] 52-week low: [value]
Today's high: [value] Today's low: [value]
Current price: [value] Percentage gain/loss [value] (from previous close please)

If possible, please include how to change the color (although I think I have that figured out), and also is there a way to adjust the font size? Thank you all so much.
 
Last edited by a moderator:

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

@Green Trades

1, This will plot labels that you can change the color at the input screen as well as in the code.
2, Regrettably, we cannot chage the font or its' color.
3. The labels can be stacked in the left corner by adding blank labels (eg: addlabel(1, " ", color.black)) between the 3 labels with enough spaces between the quotes necessary to move the label to the next line.
4. The image shows the labels that you requested and the optional bubble method below.

Code:
input Labels  = yes;
def _52W_High  = Highest(high(period = AggregationPeriod.WEEK), 52);
def _52W_Low   = Lowest(low(period = AggregationPeriod.WEEK), 52);
def Today_High = high(period = AggregationPeriod.DAY);
def Today_Low  = low(period = AggregationPeriod.DAY);
def Last_Close = close;
def Yesterday_Close = close(period = AggregationPeriod.DAY)[1];
def Percent_Change  = (Last_Close - Yesterday_Close) / Yesterday_Close;

DefineGlobalColor("52", Color.WHITE);
DefineGlobalColor("Today", Color.YELLOW);
DefineGlobalColor("Current", Color.ORANGE);
AddLabel(Labels, "52W High " + _52W_High + " 52W Low " + _52W_Low, GlobalColor("52"));
AddLabel(Labels, " Today High  "  + Today_High + " Today Low " + Today_Low, GlobalColor("Today"));
AddLabel(Labels, " Last_Close " +  Last_Close + " % Change " + AsPercent(Percent_Change), GlobalColor("Current"));

5. This is an optional method using bubbles in the right expansion.
6. You can place then either at the top or bottom of the screen with the input where.
7. The bubbles are movable sideways at the input bubblemover.
8. This uses 'declare lower' which places the bubbles in a lower panel. This you need to move the indicator to the upper panel.
9. You need to either uncheck 'Left axis' at the input screen or at chart settings/price axis, uncheck 'Enable Left Axis'.


Screenshot 2024-05-20 163344.png
Code:
def _52W_High  = Highest(high(period = AggregationPeriod.WEEK), 52);
def _52W_Low   = Lowest(low(period = AggregationPeriod.WEEK), 52);
def Today_High = high(period = AggregationPeriod.DAY);
def Today_Low  = low(period = AggregationPeriod.DAY);
def Last_Close = close;
def Yesterday_Close = close(period = AggregationPeriod.DAY)[1];
def Percent_Change  = (Last_Close - Yesterday_Close) / Yesterday_Close;

DefineGlobalColor("52", Color.WHITE);
DefineGlobalColor("Today", Color.YELLOW);
DefineGlobalColor("Current", Color.ORANGE);


#Optional Bubbles
declare lower;
input bubbles     = yes;
input where       = {default top, bottom};
input bubblemover = 2;
def   b           = bubblemover;
plot  line100     = 100;
plot  line0       = 0;
def   mover       = bubbles and isnan(close[bubblemover]) and !isnan(close[bubblemover + 1]);
AddchartBubble(mover, if where==where.top then 100 else 0,"52W High " + _52W_High[b+1] + " 52W Low " + _52W_Low[b+1], GlobalColor("52"),if where==where.top then no else yes);
AddchartBubble(mover, if where==where.top then 100 else 0, " Today High  "  + Today_High[b+1] + " Today Low " + Today_Low[b+1], GlobalColor("Today"),if where==where.top then no else yes);
AddchartBubble(mover, if where==where.top then 100 else 0, " Last_Close " +  Last_Close[b+1] + " % Change " + AsPercent(Percent_Change[b+1]), GlobalColor("Current"),if where==where.top then no else yes);
line100.setdefaultColor(color.black);
line0.setdefaultColor(color.black);

#
 
Last edited by a moderator:
Can it be enhanced to add lines instead of bubbles? Possibly an option which would enable/disable bubble and show line instead?

This uses the optional Label version above and adds optional lines that match the label colors.

Screenshot 2024-05-24 084037.png
Code:
#52WHL_TodayHL_YesterdayClose_TodayClose_Optional_Labels_Lines

input lines   = yes;
input Labels  = yes;
plot _52W_High  = Highest(high(period = AggregationPeriod.WEEK), 52);
plot _52W_Low   = Lowest(low(period = AggregationPeriod.WEEK), 52);
plot Today_High = high(period = AggregationPeriod.DAY);
plot Today_Low  = low(period = AggregationPeriod.DAY);
plot Last_Close = HighestAll(if IsNaN(close[-1]) and !IsNaN(close) then close else Double.NaN);
plot Yesterday_Close = close(period = AggregationPeriod.DAY)[1];
def Percent_Change  = (Last_Close - Yesterday_Close) / Yesterday_Close;

DefineGlobalColor("52", Color.WHITE);
DefineGlobalColor("Today", Color.YELLOW);
DefineGlobalColor("Current", Color.ORANGE);
DefineGlobalColor("Yesterday", Color.CYAN);

AddLabel(Labels, "52W High " + _52W_High + " 52W Low " + _52W_Low, GlobalColor("52"));
AddLabel(Labels, " Today High  "  + Today_High + " Today Low " + Today_Low, GlobalColor("Today"));
AddLabel(Labels, " Yesterday_Close " +  Yesterday_Close, GlobalColor("Yesterday"));
AddLabel(Labels, " Last_Close " +  Last_Close + " % Change " + AsPercent(Percent_Change), GlobalColor("Current"));

_52W_High. SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
_52W_Low. SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Today_High. SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Today_Low. SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Last_Close. SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Yesterday_Close.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

_52W_High.AssignValueColor(GlobalColor("52"));
_52W_Low.AssignValueColor(GlobalColor("52"));
Today_High.AssignValueColor(GlobalColor("Today"));
Today_Low.AssignValueColor(GlobalColor("Today"));
Yesterday_Close.AssignValueColor(GlobalColor("Yesterday"));
Last_Close.AssignValueColor(GlobalColor("Current"));

_52W_High.SetHiding(!lines);
_52W_Low.SetHiding(!lines);
Today_High.SetHiding(!lines);
Today_Low.SetHiding(!lines);
Yesterday_Close.SetHiding(!lines);
Last_Close.SetHiding(!lines);

#
 
This uses the optional Label version above and adds optional lines that match the label colors.
Hi SleepyZ, can you please help to show the code for the 52 week high and 52week low on the chart as chart bubble? The following did produce any results:

def _52W_High = Highest(high(period = AggregationPeriod.WEEK), 52);
def _52W_Low = Lowest(low(period = AggregationPeriod.WEEK), 52);
addchartbubble(yes, _52W_High and high == _52W_High, round(high,2),color.magenta,yes);
addchartbubble(yes, _52W_low and low == _52W_low, round(low,2),color.magenta,yes);
 
Last edited by a moderator:
Thanks @SleepyZ Would it also be possible to show the current lines and not show all prior lines which clutters the chart?

Use input todayonly = yes; to limit the display to just the last day.
The bubblemover allows you to move the bubbles sideways.
In the image, the right expansion is set to 10 and bubblemover is set to 9.
Change the bubble content to your liking.

Screenshot 2024-05-25 073445.png
Code:
#52WHL_TodayHL_YesterdayClose_TodayClose_Optional_Labels_Lines

input lines     = yes;
input Labels    = yes;
input bubbles   = yes;
input todayonly = yes;
def   na        = Double.NaN;

plot _52W_High  = if todayonly and GetDay() != GetLastDay() then na else Highest(high(period = AggregationPeriod.WEEK), 52);
plot _52W_Low   = if todayonly and GetDay() != GetLastDay() then na else Lowest(low(period = AggregationPeriod.WEEK), 52);
plot Today_High = if todayonly and GetDay() != GetLastDay() then na else high(period = AggregationPeriod.DAY);
plot Today_Low  = if todayonly and GetDay() != GetLastDay() then na else low(period = AggregationPeriod.DAY);
plot Last_Close = if todayonly and GetDay() != GetLastDay() then na else HighestAll(if IsNaN(close[-1]) and !IsNaN(close) then close else Double.NaN);
plot Yesterday_Close = if todayonly and GetDay() != GetLastDay() then na else close(period = AggregationPeriod.DAY)[1];
def Percent_Change   = (Last_Close - Yesterday_Close) / Yesterday_Close;

DefineGlobalColor("52", Color.WHITE);
DefineGlobalColor("Today", Color.YELLOW);
DefineGlobalColor("Current", Color.ORANGE);
DefineGlobalColor("Yesterday", Color.CYAN);

AddLabel(Labels, "52W High " + astext(_52W_High) + "  52W Low " + astext(_52W_Low), GlobalColor("52"));
AddLabel(Labels, " Today High  "  + astext(Today_High) + "  Today Low " + astext(Today_Low), GlobalColor("Today"));
AddLabel(Labels, " Yesterday_Close " +  astext(Yesterday_Close), GlobalColor("Yesterday"));
AddLabel(Labels, " Last_Close " +  astext(Last_Close) + " % Change " + AsPercent(Percent_Change), GlobalColor("Current"));

_52W_High. SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
_52W_Low. SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Today_High. SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Today_Low. SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Last_Close. SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Yesterday_Close.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

_52W_High.AssignValueColor(GlobalColor("52"));
_52W_Low.AssignValueColor(GlobalColor("52"));
Today_High.AssignValueColor(GlobalColor("Today"));
Today_Low.AssignValueColor(GlobalColor("Today"));
Yesterday_Close.AssignValueColor(GlobalColor("Yesterday"));
Last_Close.AssignValueColor(GlobalColor("Current"));

_52W_High.SetHiding(!lines);
_52W_Low.SetHiding(!lines);
Today_High.SetHiding(!lines);
Today_Low.SetHiding(!lines);
Yesterday_Close.SetHiding(!lines);
Last_Close.SetHiding(!lines);

input bubblemover = 9;
def   b   = bubblemover;
def mover = bubbles and IsNaN(close[b]) and !IsNaN(close[b + 1]);
AddChartBubble(mover, _52W_High[b + 1], "52W High " + AsText(_52W_High[b + 1]) , GlobalColor("52"));
AddChartBubble(mover, _52W_Low[b + 1], "52W Low " + AsText(_52W_Low[b + 1]), GlobalColor("52"));
AddChartBubble(mover, Today_High[b + 1], "Today High  "  + AsText(Today_High[b + 1]), GlobalColor("Today"));
AddChartBubble(mover, Today_Low[b + 1], "Today Low  "  + AsText(Today_Low[b + 1]), GlobalColor("Today"));
AddChartBubble(mover, Last_Close[b + 1], "Last_Close " +  AsText(Last_Close[b + 1]) + "\n % Change " + AsPercent(Percent_Change[b + 1]), GlobalColor("Current"));
AddChartBubble(mover, Yesterday_Close[b + 1], "Yesterday_Close " +  AsText(Yesterday_Close[b + 1]), GlobalColor("Yesterday"));
#
 
Hi SleepyZ, can you please help to show the code for the 52 week high and 52week low on the chart as chart bubble? The following did produce any results:

def _52W_High = Highest(high(period = AggregationPeriod.WEEK), 52);
def _52W_Low = Lowest(low(period = AggregationPeriod.WEEK), 52);
addchartbubble(yes, _52W_High and high == _52W_High, round(high,2),color.magenta,yes);
addchartbubble(yes, _52W_low and low == _52W_low, round(low,2),color.magenta,yes);

In addition to the above post that shows bubbles in the expansion on the 52 w lines, this will show these bubbles on the bar where these occur.

Screenshot 2024-05-25 080205.png
Code:
def _52W_High = Highest(high(period = AggregationPeriod.WEEK), 52);
def _52W_Low  = Lowest(low(period = AggregationPeriod.WEEK), 52);
AddChartBubble(high == HighestAll( _52W_High), high, "52W_H\n" + AsText(high), Color.MAGENTA, yes);
AddChartBubble(low == HighestAll(_52W_Low), low, "52W_L\n" + AsText(low), Color.MAGENTA, no);
 
1, This will plot labels that you can change the color at the input screen as well as in the code.
2, Regrettably, we cannot chage the font or its' color.
3. The labels can be stacked in the left corner by adding blank labels (eg: addlabel(1, " ", color.black)) between the 3 labels with enough spaces between the quotes necessary to move the label to the next line.
4. The image shows the labels that you requested and the optional bubble method below.

Code:
input Labels  = yes;
def _52W_High  = Highest(high(period = AggregationPeriod.WEEK), 52);
def _52W_Low   = Lowest(low(period = AggregationPeriod.WEEK), 52);
def Today_High = high(period = AggregationPeriod.DAY);
def Today_Low  = low(period = AggregationPeriod.DAY);
def Last_Close = close;
def Yesterday_Close = close(period = AggregationPeriod.DAY)[1];
def Percent_Change  = (Last_Close - Yesterday_Close) / Yesterday_Close;

DefineGlobalColor("52", Color.WHITE);
DefineGlobalColor("Today", Color.YELLOW);
DefineGlobalColor("Current", Color.ORANGE);
AddLabel(Labels, "52W High " + _52W_High + " 52W Low " + _52W_Low, GlobalColor("52"));
AddLabel(Labels, " Today High  "  + Today_High + " Today Low " + Today_Low, GlobalColor("Today"));
AddLabel(Labels, " Last_Close " +  Last_Close + " % Change " + AsPercent(Percent_Change), GlobalColor("Current"));

5. This is an optional method using bubbles in the right expansion.
6. You can place then either at the top or bottom of the screen with the input where.
7. The bubbles are movable sideways at the input bubblemover.
8. This uses 'declare lower' which places the bubbles in a lower panel. This you need to move the indicator to the upper panel.
9. You need to either uncheck 'Left axis' at the input screen or at chart settings/price axis, uncheck 'Enable Left Axis'.


View attachment 21923
Code:
def _52W_High  = Highest(high(period = AggregationPeriod.WEEK), 52);
def _52W_Low   = Lowest(low(period = AggregationPeriod.WEEK), 52);
def Today_High = high(period = AggregationPeriod.DAY);
def Today_Low  = low(period = AggregationPeriod.DAY);
def Last_Close = close;
def Yesterday_Close = close(period = AggregationPeriod.DAY)[1];
def Percent_Change  = (Last_Close - Yesterday_Close) / Yesterday_Close;

DefineGlobalColor("52", Color.WHITE);
DefineGlobalColor("Today", Color.YELLOW);
DefineGlobalColor("Current", Color.ORANGE);


#Optional Bubbles
declare lower;
input bubbles     = yes;
input where       = {default top, bottom};
input bubblemover = 2;
def   b           = bubblemover;
plot  line100     = 100;
plot  line0       = 0;
def   mover       = bubbles and isnan(close[bubblemover]) and !isnan(close[bubblemover + 1]);
AddchartBubble(mover, if where==where.top then 100 else 0,"52W High " + _52W_High[b+1] + " 52W Low " + _52W_Low[b+1], GlobalColor("52"),if where==where.top then no else yes);
AddchartBubble(mover, if where==where.top then 100 else 0, " Today High  "  + Today_High[b+1] + " Today Low " + Today_Low[b+1], GlobalColor("Today"),if where==where.top then no else yes);
AddchartBubble(mover, if where==where.top then 100 else 0, " Last_Close " +  Last_Close[b+1] + " % Change " + AsPercent(Percent_Change[b+1]), GlobalColor("Current"),if where==where.top then no else yes);
line100.setdefaultColor(color.black);
line0.setdefaultColor(color.black);

#
Excellent tutorial here; thank you so much
 
Hi Sleepy, can you please help to scan for 52 week high and low? Thanks

You could use the TOS built-in Highs_Lows as shown in the image by selecting add study filter, study and fill in the blanks. It uses the close to find the HIghs_Lows.

If you want to use the current price (close) to find the high or low, then should probably use the built-in scanner.

Otherwise if you want to use the high or low price to find the 52 week high or low then you could use one of the following.

In either case set the scanner aggregation to Weekly

high == highest(high, 52)
low == lowest(low, 52)
high == highest(high, 52) or low == lowest(low, 52)
 
You could use the TOS built-in Highs_Lows as shown in the image by selecting add study filter, study and fill in the blanks. It uses the close to find the HIghs_Lows.


If you want to use the current price (close) to find the high or low, then should probably use the built-in scanner.

Otherwise if you want to use the high or low price to find the 52 week high or low then you could use one of the following.

In either case set the scanner aggregation to Weekly
Thank you SleepyZ!
 
Hi all,
The 52-week labels are not producing any results for me on my charts.
Love this work! Thanks
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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