52-week Highs/Lows For ThinkOrSwim

@XeoNoX I did it!

run52H/L
Code:
#IMPORTANT set the column (set it to YEAR aggregation)
#on a scale of 1 to 100 (lowest yearly price to highest yearly price)
#by XeoNoX via usethinkscript.com, customized by cygnus_stalker
def priceHigh = high;
def pricelow = low;
def YearHigh = Highest(priceHigh, 1) ;
def YearLow = Lowest(priceLow, 1) ;
def range = Yearhigh-Yearlow;
def closing_value = close - Yearlow;
def percent = (closing_value/range)*100;
plot scan = percent;
def var = percent==100;
def barUpCount = CompoundValue(1, if var then barUpCount[1] + 1 else 0, 0);
AddLabel (yes, "  " + barUpCount );

runDayH/L
Code:
#IMPORTANT set the column (set it to DAY aggregation)
#on a scale of 1 to 100 (lowest yearly price to highest yearly price)
#by XeoNoX via usethinkscript.com, customized by cygnus_stalker
def priceHigh = high;
def pricelow = low;
def YearHigh = Highest(priceHigh, 1) ;
def YearLow = Lowest(priceLow, 1) ;
def range = Yearhigh-Yearlow;
def closing_value = close - Yearlow;
def percent = (closing_value/range)*100;
plot scan = percent;
def var = percent==100;
def barUpCount = CompoundValue(1, if var then barUpCount[1] + 1 else 0, 0);
AddLabel (yes, "  " + barUpCount );

Thanks again for all your help. You've been a lifesaver
 

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

@XeoNoX @rad14733 appreciate the likes but I spoke too soon 🤦‍♂️ My counter never gets higher than 1 because I'm only counting each 100%. How do I count the consecutive close > close[1] (1 min agg) AFTER the Yearly high crossover aka percent hits 100? Not being able to set a secondary agg is going to throw a wrench in all this. Feels like the consecutive close > close[1] counter needs its own script but how in the heck will it know when the yearly high/low or daily high/low has hit?!?!😭
 
once the year high is true do you want close is greater than previous close or high is greater than previous high? i know u stated close is greater than previous close, but i think you may have meant high is greater than previous high, although i may be wrong :p

anyways... here is the general idea (not actual code) althougth i think all you have to do is correctly format high252 (aggregation period=day).
here is what you would have to do....
i dont have access to tos right now, but here is the general idea assuming you meant high>high[1]

Code:
def sohighitshigh = highest(high) ;
def var = GetDay() == GetLastDay() and sohighitshigh >= sohighitshigh[1];
def barUpCount = CompoundValue(1, if var then barUpCount[1] + 1 else 0, 0);
def study = if GetDay() == GetLastDay() and high252 (aggregation period=day) then count else study[1];
plot scan = study;
 
here is the code
Column for Counting the number of consecutive 52 Week High bars
(Consecutive Bars a new high was made during a 1 year period)


Code:
declare lower;
#Column for Counting the number of consecutive 52 Week High bars
#(Consecutive Bars a new high was made during a 1 year period)
#By XeoNoX
#6-19-2023
#version v1.4
#updated to add custom aggregation
#Match agreggation in BOTH this indicator settings and on the chart.. Yes B O T H.. BOTH!
input Agregation = {default WEEK, DAY, MONTH, "OPT EXP"};
input bars_back = 52;
#HELPFUL HINT: 252 trading days in a year, 52 weeks in a year, 12 months in a year
def yearhigh = Highest(high(period = Agregation), bars_back);
#previous bar is previous year high and current bar is higher making it the new 52 week high is TRUE
def scan_is_true = yearhigh > yearhigh[1];
def barUpCount = CompoundValue(1, if scan_is_true then barUpCount[1] + 1 else 0, 0);
AddLabel (yes, "COUNT " + barUpCount );
plot finalscan = barupcount;
 
Last edited:
Sorry I did mean high>high[1] :oops: Thanks! I was trying to format that high252 but I was wayyyy off. I would have never figured this out on my own haha

Assuming this only works during market hours?
 
it works all the time, assuming you mean if its going to show a number then thats only going to happen when there is a new 52 week high, LoL.
however, you can see it works by plotting it as a lower study... i just checked it with symbol AAP on March 5-March 9

UPDATE: i cleaned up the code a bit, version 1.3
 
Last edited:
oh I see what's happening. Dell was at the top of the new yearly highs list and your column registered a 10 but I got all confused because I was I was looking at a 1min chart.

Can it tally up 1min high>high[1] or is the secondary aggregation going to be a problem.

symbol hits a 52 week high + 1
symbol high>high[1] 1min candles + 1
Total = 2 consecutive 52 week highs

same symbol high<high[1] 1min - counter resets to zero

does that make sense?
 
I've used the following script:

Code:
plot signal = if close <= SimpleMovingAvg(length=100) then 1 else 0;

The problem is that it scans and usually the tickers are way above the 100 day high already. I need something that's within a small percentage of the 100 day high. Any help in this matter will be beneficial. Thanks!
 
I've used the following script:

Code:
plot signal = if close <= SimpleMovingAvg(length=100) then 1 else 0;

The problem is that it scans and usually the tickers are way above the 100 day high already. I need something that's within a small percentage of the 100 day high. Any help in this matter will be beneficial. Thanks!
youre saying price 100 day high but your script shows price above 100 moving average . those are two different things
 
Ok after extensive research, I have figured it out if anyone is interested...

Code:
def hi52 = Highest(high(period = AggregationPeriod.Week),52);
addlabel(1, "52Wk HI: $" + Round(hi52, 2), color.green);

def low52 = Lowest(low(period = AggregationPeriod.Week),52);
addlabel(1, "52Wk LOW: $" + Round(low52, 2), color.red);

This code rounds to nearest 2 digits after decimal and adds a "$".

Thanks guys!
Is there a way to show dotted lines representation the 52w H/L marks? I tried using the 52W high and low provided in the studies section, but they only show accurate when viewing a daily chart (6mon/1D; 3 mo/1D etc), but when I try to see hourly timeframe like 6mo/4hr etc, the numbers are not correct
 
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)
Is there a way to make this dynamically adjust to the chart timeframe we're using? For example, I want to see the correct High/Low lines even when I'm in a 4 hour chart
 
Is there a way to make this dynamically adjust to the chart timeframe we're using? For example, I want to see the correct High/Low lines even when I'm in a 4 hour chart

You just need to pass the period you want to the price functions (close, high, low, etc.).

Ruby:
Round((close(period=AggregationPeriod.DAY) / Highest(high(period=AggregationPeriod.DAY), 252) - 1) * 100)
 
High == Highest(High(period = "DAY"), 252)

This does not work for recent IPOs with less than 40 weeks.
Is there a way to get the 52 week High value or the max high value for the available range for new IPOs?

Thanks!
 
This worked for me as watchlist colum for new IPOs as well e.g., COIN. Aggregation Period Set to Week. Experts here can review the code. Thanks!

def C = Close; def O = Open; def H = High; def L = Low;
def lastBar = !IsNaN(C) && IsNaN(C[-1]);

def maxBars = min(if lastBar then BarNumber() else maxBars[1],52);
def hh52 = fold iH = 0 to maxBars with maxHigh=0 do max(GetValue(high,iH),maxHigh);
def ll52 = fold iL = 0 to maxBars with maxLow=max(0,close) do min(GetValue(low,iL),maxLow);
plot rng52P = Round(((C -ll52)/(hh52-ll52))*100,0);
 
Last edited:
So I created this simple study that shows a line at the 52W high mark,
BUT, I'm having trouble with it because it shows on the screen even when the current price is far below the 52W high and thus my chart is modified.
I can fix this by changing the setting on my chart to disable "fit studies" but I'd like to do it in the script by only showing the line when the last price is within say 10% of the 52W High
Is that possible?
I'd like to keep my chart of auto scale

Code:
#HINT: This study will plot a line at the 52W High mark

declare upper;

plot hi52 = Highest(high(period = AggregationPeriod.Week),52);
hi52.SetDefaultColor(GetColor(8));
hi52.SetLineWeight(1);

To clarify, I look at JETS at an example. Current price is $23. 52W High is at $28, so my chart essentially gets flattened when it shows that much of a price range
 
i modified your code to ask for a percent. if the 52 week high line is closer than 10% from the close price, it will be plotted.
variable show, is true if the price difference percent is less than variable, percent_tolerance.

Code:
# weekhi_01
#HINT: This study will plot a line at the 52W High mark
#declare upper;
def na = double.nan;
input percent_tolerance = 10.0;
def per = percent_tolerance/100;
def weekhi = Highest(high(period = AggregationPeriod.Week), 52);
def show = ( absvalue(close - weekhi)/close ) <= per;
plot hi52 = if show then weekhi else na;
hi52.SetDefaultColor(GetColor(8)); 
hi52.SetLineWeight(1);

I1f0ZdL.jpg
 
Last edited:
i modified your code to ask for a percent. if the 52 week high line is closer than 10% from the close price, it will be plotted.
variable show, is true if the price difference percent is less than variable, percent_tolerance.

Code:
# weekhi_01
#HINT: This study will plot a line at the 52W High mark
#declare upper;
def na = double.nan;
input percent_tolerance = 10.0;
def per = percent_tolerance/100;
def weekhi = Highest(high(period = AggregationPeriod.Week), 52);
def show = ( absvalue(close - weekhi)/close ) <= per;
plot hi52 = if show then weekhi else na;
hi52.SetDefaultColor(GetColor(8)); hi52.SetLineWeight(1);

I1f0ZdL.jpg
Thank you. I appreciate the assist. I'll definitely learn from this.
Question: Any idea why the line does not show up on a daily or 2 day chart but shows up on the 5 day chart...
1D1M = no show
1D3M = no show
2D3M = no show
5D3m = show
 
Good morning everyone!

I'm using the following code to display the 52WHigh and 52WLow prices on my chart. Is there a way to add the dates of the Highs and Lows that show up?
Example: "52W High: $100 on 08/10/2021"

Thank you in advance
Code:
def hi52 = Highest(high(period = AggregationPeriod.Week),52);
addlabel(1, " 52Wk HI: $" + Round(hi52, 2) +" ", color.green);

def low52 = Lowest(low(period = AggregationPeriod.Week),52);
addlabel(1, " 52Wk LOW: $" + Round(low52, 2) +" ", color.red);
#spacer
input Spacer = yes;
#spacer label
addlabel(Spacer, " ", color.BLACK);


 
Good morning everyone!

I'm using the following code to display the 52WHigh and 52WLow prices on my chart. Is there a way to add the dates of the Highs and Lows that show up?
Example: "52W High: $100 on 08/10/2021"

Thank you in advance
Code:
def hi52 = Highest(high(period = AggregationPeriod.Week),52);
addlabel(1, " 52Wk HI: $" + Round(hi52, 2) +" ", color.green);

def low52 = Lowest(low(period = AggregationPeriod.Week),52);
addlabel(1, " 52Wk LOW: $" + Round(low52, 2) +" ", color.red);
#spacer
input Spacer = yes;
#spacer label
addlabel(Spacer, " ", color.BLACK);



Since it appears that the TOS aggregationperiod.week can lookback as in your code to a value even though the bar that has that value is not displayed on the chart. To lookup the date associated with your aggregationperiod.week, the bar having that value must be shown on that chart. On your 10 day, 3min chart, that bar is not for that date is not on your chart and therefore cannot be displayed. Since the week aggregation set at a length of 52 does not exist on most intraday charts unless it is within the days displayed, most of the results for your requested date will be N/A.
 
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
321 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