current week's price has crossed 52 week high

shakib3585

Active member
VIP
Hello All,

I need help in creating a scan script to identify instances where the closing price for the current week crosses either the current or previous 52-week high. The term "current 52-week high" refers to the active 52-week high. Can anyone please help me with a scan script? @SleepyZ I know you will be watching this thread 👑👑.

Thanks

@SleepyZ would you please care to step in to resolve my problem.

Thank you so much!
 
Last edited by a moderator:
Solution
@SleepyZ would you please care to step in to resolve my problem.

Thank you so much!

This seems to work.

Put this in the scanner, set to weekly, and in a weekly chart, move it to a lower panel to see the true (1) scan results
Screenshot 2024-02-14 083513.png
Code:
input agg = aggregationPeriod.WEEK;
def  w52h = highest(high(period=agg)[1],52);
plot scan = close(period=agg) crosses w52h;

Put this in the weekly chart to see the plot of the 52w high and close crossings
Screenshot 2024-02-14 083607.png
Code:
input agg = aggregationPeriod.WEEK;
plot w52h = highest(high(period=agg)[1],52);
plot scan = close(period=agg) crosses w52h;
@SleepyZ would you please care to step in to resolve my problem.

Thank you so much!

This seems to work.

Put this in the scanner, set to weekly, and in a weekly chart, move it to a lower panel to see the true (1) scan results
Screenshot 2024-02-14 083513.png
Code:
input agg = aggregationPeriod.WEEK;
def  w52h = highest(high(period=agg)[1],52);
plot scan = close(period=agg) crosses w52h;

Put this in the weekly chart to see the plot of the 52w high and close crossings
Screenshot 2024-02-14 083607.png
Code:
input agg = aggregationPeriod.WEEK;
plot w52h = highest(high(period=agg)[1],52);
plot scan = close(period=agg) crosses w52h;
 
Solution
Hi sleepyZ, can you please add chartbubble at the 52 week high and low on the chart? Thanks,

This is meant to work on Daily and Weekly Chart Aggregations ONLY

Screenshot 2024-02-15 061128.png
Code:
#_52week_HL_Bubbles
# Use on Day or Week Charts Only


def agg    = if GetAggregationPeriod() == AggregationPeriod.WEEK
             then AggregationPeriod.WEEK
             else AggregationPeriod.DAY;
def length = if GetAggregationPeriod() == AggregationPeriod.WEEK
             then 52 else 252;
def bn = BarNumber();
def lastbar     = (if IsNaN(close[-1]) and !IsNaN(close) then bn else Double.NaN);
def Last52wHigh = GetMaxValueOffset((high(period = agg)), length);
def last52wLow  = GetMinValueOffset((low(period = agg)), length);

AddChartBubble(bn == HighestAll(lastbar - GetValue(Last52wHigh, 1) - 1), high,
asdollars(high) + "\n" + getmonth()+"/"+getdayOfMonth(getyyyYMMDD()), Color.GREEN);

AddChartBubble(bn == LowestAll(lastbar - GetValue(last52wLow, 1) - 1), low,
asdollars(low) + "\n" + getmonth()+"/"+getdayOfMonth(getyyyYMMDD()), Color.LIGHT_RED, no);

input verticals = no;
AddVerticalLine(verticals and bn == HighestAll(lastbar), bn, color.white);
AddVerticalLine(verticals and bn == HighestAll(lastbar) - length, bn, color.white);

#
 
Last edited:
That is great, Thanks SleepyZ,


SleepyZ, Can you also please provide the scan for 52 week high and low, I really appreciate your help.
I used the following but it it did not work
plot scanL = if Last52Wlow then 1 else 0;
Plot scanH = if Last52wHigh then 1 else 0;

There are 2 scan plots in this code to be used with a WEEKLY scan setting.
Use 1 at a time by commenting out the other you are not using.
It is meant to find if TODAY's weekly is equal to or a NEW 52 week High or Low
The images are scan Highs/Lows on S&P 500

Screenshot 2024-02-15 135236.png
Screenshot 2024-02-15 135015.png
Code:
def agg    = if GetAggregationPeriod() == AggregationPeriod.WEEK
             then AggregationPeriod.WEEK
             else AggregationPeriod.DAY;
def length = if GetAggregationPeriod() == AggregationPeriod.WEEK
             then 52 else 252;
def bn = BarNumber();
def lastbar     = (if IsNaN(close[-1]) and !IsNaN(close) then bn else Double.NaN);
def Last52wHigh = GetMaxValueOffset((high(period = agg)), length);
def last52wLow  = GetMinValueOffset((low(period = agg)), length);

plot scanhigh = Last52wHigh == 0;
#plot scanlow = last52wlow == 0;

#
 
Last edited by a moderator:
There are 2 scan plots in this code to be used with a WEEKLY scan setting.
Use 1 at a time by commenting out the other you are not using.
It is meant to find if TODAY's weekly is equal to or a NEW 52 week High or Low
The images are scan Highs/Lows on S&P 500
Thank you SleepyZ for all your help!
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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