52-week Highs/Lows For ThinkOrSwim

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)
Hello, Wondering how to make change to this script to use the ATH if the stock has less than 252 days of trading history. I looked at the thinkscript functions, but didn't find any functions that returns me ATH. Appreciate your response. Thanks.

Update: Below is the code I came up with. Can someone please audit and let me know if it looks ok. thinkorswim is flashing warning sign saying it might affect performance.

Code:
def high52WeekHigh =  if IsNaN( Highest(high, 252))  then HighestAll(high) else  Highest(high, 252);
def high52WeekHighPercent = (close - high52WeekHigh)/close * 100;
 
Last edited:

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

Hello, Wondering how to make change to this script to use the ATH if the stock has less than 252 days of trading history. I looked at the thinkscript functions, but didn't find any functions that returns me ATH. Appreciate your response. Thanks.

Update: Below is the code I came up with. Can someone please audit and let me know if it looks ok. thinkorswim is flashing warning sign saying it might affect performance.

Code:
def high52WeekHigh =  if IsNaN( Highest(high, 252))  then HighestAll(high) else  Highest(high, 252);
def high52WeekHighPercent = (close - high52WeekHigh)/close * 100;
The script uses the function: HighestAll which ToS broke in the last update and has no plans on fixing. This function no longer calculates in real time, which will cause scripts that use it to lag to the point of being un-usable. Read more here: https://usethinkscript.com/threads/...ing-issues-due-to-tos-update.8794/#post-72936
 
@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);
I added the following but it did not give the right location for the highest, can you please help?

def b = Highest(high, 252);
def bar2 = if IsNaN(b)then Double.NaN else BarNumber();
DEF Thisbar2 = lowestall(bar2);
def Line2 = if bar2 == ThisBar2 then b else Double.NaN;
plot Q = if ThisBar2 then Lowestall(Line2)else Double.NaN;
Q.SetStyle(Curve.Short_Dash);
Q.SetLineWeight(1);
Q.SetDefaultColor(CreateColor(75,250,150));
def SR2 = showBubble and !IsNaN(close) and IsNaN(close [-1] ) && Lowestall(BarNumber());
AddChartBubble(SR2 and b, Lowestall(Line2), "Highest", Color.PINK, yes);
 
Got it. Is there an alternative way of rewriting this script without using HighestAll function. Thanks.
No, given that the function of the script is to calculate the HighestAll 52-week price, that can't be really 'worked around'
 
I added the following but it did not give the right location for the highest, can you please help?

def b = Highest(high, 252);
def bar2 = if IsNaN(b)then Double.NaN else BarNumber();
DEF Thisbar2 = lowestall(bar2);
def Line2 = if bar2 == ThisBar2 then b else Double.NaN;
plot Q = if ThisBar2 then Lowestall(Line2)else Double.NaN;
Q.SetStyle(Curve.Short_Dash);
Q.SetLineWeight(1);
Q.SetDefaultColor(CreateColor(75,250,150));
def SR2 = showBubble and !IsNaN(close) and IsNaN(close [-1] ) && Lowestall(BarNumber());
AddChartBubble(SR2 and b, Lowestall(Line2), "Highest", Color.PINK, yes);
Please provide a marked-up image of what you are trying to do.
Unsure of how to upload screenshots to the forum, Here are directions.
 
BenTen wrote a code with a line at lowestall with the chartlabel at the lowestall. I wanted to do the same for the highestall with the chartlabel at the highestall.
You are in the right place. These 8 pages have plenty of examples (y)
 
@Superfast Here's a watchlist column to perform what you requested

def Low52Week = Lowest(low(period = "Day"), 252);
AddLabel(1, AsPercent((close-Low52Week)/Low52Week), Color.Cyan);
Can this be adjusted to return the value as a number so that the column can be sorted? [Currently it's sorting as an alpha string] -- thx!
 
@cabe1332 Thank you so much for your quick response.
I had actually tried something very similar to what you propose. Would your script return names that are 30% below the 52 wk high and lower? What I was trying to accomplish is to find names that are in the range of 15% to 30% below the high.
Thanks again. I feel I am learning.

Hi Berkhar,

To narrow the range to only 70-85% of the high, I think stormy77’s reply in post #130 has the idea that you need. Just change the numbers in his code to be those shown in boldface below.

Close <= Highest(High(period = "DAY"), 252)0.85 and Close >= Highest(High(period = "DAY"), 252)0.7
 
How to write closing price must be less than 50% away from 52 week high? what I have is not working:
((highest(high,252) - close[-1])/close[-1]) is less than .50
 
How to write closing price must be less than 50% away from 52 week high? what I have is not working:
((highest(high,252) - close[-1])/close[-1]) is less than .50

here is something to experiment with.
bubbles are draw with 4 values: highest value, close, % difference, 1/0 - is the % < set percent.
bubbles are yellow when the % difference is < the set amount, and gray if not.
the highest line is drawn.

with the percent set at 50%, most of closes with be less than that. try setting it to 5%.


Ruby:
# within_xper_hi_00
# when is close < y% of a 52 week high ?

def na = double.nan;
input max_percent = 50;
#def p = max_percent / 100;

input agg = AggregationPeriod.WEEK;
input agg_periods = 52;

#def hix = Highest( high(period = agg), weeks_back);
def hix2 =  high(period = agg);
def hix = Highest( hix2, agg_periods);

input show_high_line = yes;
plot h1 = if show_high_line then hix else na;
h1.SetDefaultColor(color.light_gray);

def diffper = round( (( hix - close )/ hix ) * 100, 1);
def isless = if diffper < max_percent then 1 else 0;

input test1 = yes;
addchartbubble(test1, low*0.995, hix + "\n" + close + "\n" + diffper +"%\n" + isless , (if isless then color.yellow else color.gray), no );
#
 
((Max(high,252) - close[-1])/close[-1]) <= 1.50 Or High >=max(High,252) and H>= Max(High,252)*1.50

I gave it a shot, not sure if this is correct?????
 
Thank you for responding. Unfortunately no luck - still not working.
 
Code:
Declare Lower;
Input ALength = 10;
Def YH = Highest(High,252)[1];
Def YL = Lowest(Low,252)[1];
def X = (YH-YL);
Plot STK = (Close - YL)/X;
STK.SetdefaultColor(Color.Cyan);
STK.SetLineWeight(2);
Plot STKA = Average(STK,ALength);
STKA.SetDefaultColor(Color.Magenta);
Plot twenty = .2;
Plot Eighty = .8;
Twenty.SetDefaultColor(Color.Gray);
Plot Fifty = .5;
Fifty.AssignValueColor(If Stk > .5 then Color.Green else Color.Red);
Eighty.SetDefaultColor(Color.Gray);
AddCloud(STK,STKA,Color.Cyan,Color.Magenta);
AddCloud(.2,0,Color.Light_Green,Color.Light_Green);
AddCloud(.8,1,Color.Orange,Color.Orange);

Your Scan would be STK > .5
 
52 Week Range in Eighths

Code:
Declare Upper;
Def YH = Highest(High,252)[1];
Def YL = Lowest(Low,252)[1];
def X = (YH-YL)/8;
Plot R9 = YH+X;
Plot R8 = YH;
Plot R7 = YH - X;
Plot R6 = YH - (2*X);
Plot R5 = YH - (3*X);
Plot R4 = YH - (4*X);
Plot R3 = YH - (5*X);
Plot R2 = YH - (6*X);
Plot R1 = YH - (7*X);
Plot R0 = YL;
Plot RM1 = YH - (9*X);
R9.SetDefaultColor(Color.Gray);
R8.SetDefaultColor(Color.Cyan);
R7.SetDefaultColor(Color.Yellow);
R6.SetDefaultColor(Color.Red);
R5.SetDefaultColor(Color.Light_Green);
R4.SetDefaultColor(Color.Cyan);
R3.SetDefaultColor(Color.Light_Green);
R2.SetDefaultColor(Color.Red);
R1.SetDefaultColor(Color.Yellow);
R0.SetDefaultColor(Color.Cyan);
RM1.SetDefaultColor(Color.Gray);
AddCloud(R9,R8,Color.Light_Gray,Color.Light_Gray);
AddCloud(R8,R7,Color.Cyan,Color.Cyan);
AddCloud(R7,R6,Color.Yellow,Color.Yellow);
AddCloud(R6,R5,Color.Orange,Color.Orange);
AddCloud(R5,R3,Color.Light_Green,Color.Light_Green);
AddCloud(R3,R2,Color.Orange,Color.Orange);
AddCloud(R2,R1,Color.Yellow,Color.Yellow);
AddCloud(R1,R0,Color.Cyan,Color.Cyan);
AddCloud(R0,RM1,Color.Light_Gray,Color.Light_Gray);
 
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
392 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