Recent All Time Highs?

Airtower

New member
Hello, I have found some coding that is close to what I am looking for but not sure how to incorporate the recency of hitting an All Time High.
Simply put, I am just looking to create a script that checks a Daily chart over the last 500 trading days, that is looking for an New All Time High created in the last 15 days. I sued this code from a previous post to find if a stock is close to the All Time High but not sure how I can modify it (or create a new custom code) to find what i am looking for above...

Code:
# Cond = at least 95%-99% of all time high that is from at least 6 to 52 weeks ago....and is now advancing towards all time high again.
def thisBar = if isNaN(close[-1]) and !isNaN(close)
then barNumber()
else thisBar[1];
def hhBar = if high == highest(high, 350)
then barNumber()
else hhBar[1];
def hh = if high == highest(high, 350)
then high
else hh[1];
plot Cond = highestAll(thisBar) - highestAll(hhBar) > 5 and
between(close, hh * .975, hh * .9995) and
isAscending(close, 5);
 
Solution
Hello, I have found some coding that is close to what I am looking for but not sure how to incorporate the recency of hitting an All Time High.
Simply put, I am just looking to create a script that checks a Daily chart over the last 500 trading days, that is looking for an New All Time High created in the last 15 days. I sued this code from a previous post to find if a stock is close to the All Time High but not sure how I can modify it (or create a new custom code) to find what i am looking for above...

Code:
# Cond = at least 95%-99% of all time high that is from at least 6 to 52 weeks ago....and is now advancing towards all time high again.
def thisBar = if isNaN(close[-1]) and !isNaN(close)
then barNumber()
else thisBar[1];
def...
Hello, I have found some coding that is close to what I am looking for but not sure how to incorporate the recency of hitting an All Time High.
Simply put, I am just looking to create a script that checks a Daily chart over the last 500 trading days, that is looking for an New All Time High created in the last 15 days. I sued this code from a previous post to find if a stock is close to the All Time High but not sure how I can modify it (or create a new custom code) to find what i am looking for above...

Code:
# Cond = at least 95%-99% of all time high that is from at least 6 to 52 weeks ago....and is now advancing towards all time high again.
def thisBar = if isNaN(close[-1]) and !isNaN(close)
then barNumber()
else thisBar[1];
def hhBar = if high == highest(high, 350)
then barNumber()
else hhBar[1];
def hh = if high == highest(high, 350)
then high
else hh[1];
plot Cond = highestAll(thisBar) - highestAll(hhBar) > 5 and
between(close, hh * .975, hh * .9995) and
isAscending(close, 5);

here is something to experiment with

Code:
declare lower;
input days_back = 500;
input within_days = 15;
def x = GetMaxValueOffset(high, days_back);
plot z = x <= within_days;
addchartbubble(0, -.3, x, color.yellow, no);
#
 

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

Hello, I have found some coding that is close to what I am looking for but not sure how to incorporate the recency of hitting an All Time High.
Simply put, I am just looking to create a script that checks a Daily chart over the last 500 trading days, that is looking for an New All Time High created in the last 15 days. I sued this code from a previous post to find if a stock is close to the All Time High but not sure how I can modify it (or create a new custom code) to find what i am looking for above...

Code:
# Cond = at least 95%-99% of all time high that is from at least 6 to 52 weeks ago....and is now advancing towards all time high again.
def thisBar = if isNaN(close[-1]) and !isNaN(close)
then barNumber()
else thisBar[1];
def hhBar = if high == highest(high, 350)
then barNumber()
else hhBar[1];
def hh = if high == highest(high, 350)
then high
else hh[1];
plot Cond = highestAll(thisBar) - highestAll(hhBar) > 5 and
between(close, hh * .975, hh * .9995) and
isAscending(close, 5);

why mention 500 days, if you only care about the last 15 days?
forget my previous post. i had an idea, but didn't test it thoroughly.

here is a version that works
it looks at the past 15 bars and draws 2 pulse lines, that go to 1.
. higher , =1 each time a new high happens
. recenthi , =1 when a new high happens in the last 15 bars


Code:
declare lower;
def na = double.nan;
def bn = barnumber();
#input bars_back = 500;
input within_bars = 15;
def hi = if bn == 1 then high
 else max(high, hi[1]);

def higher = if bn == 1 then 0
 else (hi != hi[1]);
def recenthi = sum(higher,within_bars)>0;

plot z = higher;
plot y = recenthi;
#
 

Attachments

  • Capture.JPG
    Capture.JPG
    70.4 KB · Views: 81
Solution
Thank you again for the quick reply!
Mainly, I was using 500 days to determine the actual All Time High in the stock. I could go further back but 500 seems to capture enough of a significant All Time High for my purposes. Its a simple strategy. Basically looking for a recent or (about to happen) new All Time High in the stock and entering a position Long on it on the day it breaks out, if it is strong through that day. So I was working on creating a scanner that I could have running to show me any Stock that is near or has just broken out to new All Time Highs. Then, I would use discretion to enter Long or not.
 
Thank you again for the quick reply!
Mainly, I was using 500 days to determine the actual All Time High in the stock. I could go further back but 500 seems to capture enough of a significant All Time High for my purposes. Its a simple strategy. Basically looking for a recent or (about to happen) new All Time High in the stock and entering a position Long on it on the day it breaks out, if it is strong through that day. So I was working on creating a scanner that I could have running to show me any Stock that is near or has just broken out to new All Time Highs. Then, I would use discretion to enter Long or not.
i am starting to understand what you are after. your words were confusing, and i just realized why.
saying all time high and 500 day high is confusing. then your code used 350....

if you want a 500 day high, then say just that. don't say all time high.
working on another ver....

a lower code for experimenting with
Code:
#higher_hi_all_time_01

#https://usethinkscript.com/threads/recent-all-time-highs.18536/
#Recent All Time Highs?

declare lower;
def na = Double.NaN;
def bn = BarNumber();

input bars_back = 500;
input within_bars = 15;

# skip over within bars to find long term highest hi
def hi_long = highest(high[within_bars], bars_back);
def hi_recent = highest(high, within_bars);
def new_hi = hi_recent > hi_long;

plot z = new_hi;

#----------------------------
# following code is not needed, just for experimenting

input test1 = no;
addlabel(test1, bars_back, color.cyan);
addlabel(test1, within_bars, color.cyan);

addchartbubble(test1 and !isnan(close), 0,
 hi_long + " L\n" +
 hi_recent + " R\n" +
 new_hi 
, color.yellow, no);

# w is true during a 'qty' group of bars, that is 'from_last_bar' bars away from the last bar
#input bar_qty = 7;
#input from_last_bar = 11;
def bar_qty = bars_back;
def from_last_bar = within_bars;
def w = !isnan(close[-from_last_bar]) and isnan(close[-(bar_qty+from_last_bar)]);
plot z1 = if test1 and w then 0.5 else na;
z1.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
#
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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