52-week Highs/Lows For ThinkOrSwim

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
#52 week high low any time frame --- joe

def Low52Week = Lowest(low(period = "Day"), 252);
def Hi52Week = Highest(high(period = "Day"), 252);
def change = (close-Hi52Week)/Hi52Week;
addlabel(1,"L/H: " + Low52Week +"-"+Hi52Week, color.cyan);
AddLabel(1,"Change: "+ aspercent(change), if change<0 then Color.pink else color.green)
 
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;
Would this script be a watchlist column?!
 
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)
How would you set up a scan to identify stocks that are a given percentage below 52 week highs? Thanks!

Looking to scan for stocks that have declined substantially from 52-week highs. Scan would allow changing percentage amounts. This is probably an easy scan but I am new to thinkscript and just learning. Thanks!
 
Last edited by a moderator:
How would you set up a scan to identify stocks that are a given percentage below 52 week highs? Thanks!

Looking to scan for stocks that have declined substantially from 52-week highs. Scan would allow changing percentage amounts. This is probably an easy scan but I am new to thinkscript and just learning. Thanks!

Last Closing price is within XYZ percent of 52 Week High
Code:
#Last Closing price is within XYZ percent of 52 Week High
#By XeoNoX
#via usethinkscript.com
#6-20-2023
#     *****  BE SURE TO SET TO WEEK AGGREGATION ****
#### Change percentvalue to percent % in decimal format
###  Example .02 is 2%  and .025 is 2.5%
def percentvalue = .02;
def YearHigh_52WHigh = Highest(high(period = AggregationPeriod.Week),52);
def PercentOf =  YearHigh_52WHigh*percentvalue;
def withinPercent = absvalue(close -  YearHigh_52WHigh) is less than or equal to PercentOf;
plot scan = withinPercent;
 
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));
can you please show the dashed line for 52Wk Low? thanks
 
Kashkian said:
Hi SleepyZ, can you please show the chartbubble on the 52W high or low points instead of on the dashed line?

# @Joshua code - Just added bubbles
# The bubbles work on primarily daily and weekly charts and the bars where these occur have to be visible on the chart for these to appear.
Screenshot 2024-03-10 211612.png
# The labels seem to work intraday with most aggregations with adequate timeframes set. For example, on a 1m chart, a 30day timeframe seemed to work, usually without a date, unless it is visible on the chart.
Code:
#_52_Week_HL_Bubbles
# @joshua code - Just added bubbles
# The bubbles work on primarily daily and weekly charts and the bars where these occur have to be visible on the chart for these to appear.
# The labels seem to work intraday with most aggregations with adequate timeframes set. For example, on a 1m chart, a 30 day timeframe seemed to work.  

input showbubbles = yes;
input showlabels  = yes;

def LastBar  = HighestAll(if !IsNaN(close) then BarNumber() else Double.NaN);
def LastHigh = HighestAll(if BarNumber() == LastBar then Highest(high(period = AggregationPeriod.WEEK), 52) else Double.NaN);
def Day;
def Month;
def Year;
if high == LastHigh {
    Day   = GetDayOfMonth(GetYYYYMMDD());
    Month = GetMonth();
    Year  = GetYear();
} else {
    Day   = Day[1];
    Month = Month[1];
    Year  = Year[1];
}
AddLabel(showlabels, "High is: " + LastHigh + " on " + Month + "/" + Day + "/" + AsPrice(Year), Color.LIGHT_GREEN);
AddChartBubble(showbubbles and high == LastHigh, high, "HH: " + AsDollars(LastHigh) + "\n" + Month + "/" + Day + "/" + AsPrice(Year), Color.LIGHT_GREEN);

##########################

def LastLow = HighestAll(if BarNumber() == LastBar then Lowest(low(period = AggregationPeriod.WEEK), 52) else Double.NaN);
def DayL;
def MonthL;
def YearL;
if low == LastLow {
    DayL   = GetDayOfMonth(GetYYYYMMDD());
    MonthL = GetMonth();
    YearL  = GetYear();
} else {
    DayL   = DayL[1];
    MonthL = MonthL[1];
    YearL  = YearL[1];
}
AddLabel(showlabels, "Low is: " + LastLow + " on " + MonthL + "/" + DayL + "/" + AsPrice(YearL), Color.LIGHT_RED);
AddChartBubble(showbubbles and low == LastLow, low, "LL: " + AsDollars(LastLow) + "\n" + MonthL + "/" + DayL + "/" + AsPrice(YearL), Color.LIGHT_RED, no);
 
Last edited:

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
403 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