Previous All-Time High

shakib3585

Active member
VIP
(Code attached needs correction)
Hello All,

I am trying with a script in an attempt to find the last recorded All Time High (ATH) and not the new one (if made). I have been trying with the attached code but with no luck. Can anyone please help in correcting the code to plot the previously recorded ATH?

Thank you very much

Code:
def c1 = high[1];
def ATH = highestall(c1);


plot ATH1 = ATH;


ATH1.SetDefaultColor(CreateColor(51,102,255));
ATH1.SetStyle(Curve.SHORT_DASH);
ATH1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

Addlabel(yes,"P.ATH: "+ATH1,CreateColor(51,102,255));
 
Last edited by a moderator:
(Code attached needs correction)
Hello All,

I am trying with a script in an attempt to find the last recorded All Time High (ATH) and not the new one (if made). I have been trying with the attached code but with no luck. Can anyone please help in correcting the code to plot the previously recorded ATH?

Thank you very much

Code:
def c1 = high[1];
def ATH = highestall(c1);


plot ATH1 = ATH;


ATH1.SetDefaultColor(CreateColor(51,102,255));
ATH1.SetStyle(Curve.SHORT_DASH);
ATH1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

Addlabel(yes,"P.ATH: "+ATH1,CreateColor(51,102,255));


your words are confusing.
'the last' of something on a chart, would be the current one, the one on the right side, the last candle.
do you mean the previous one?
instead of 'not the new one', do you mean 'not the current one' ?


test stocks chart 15min 10day

DOW , CSCO
the first bar is highest, on 1/26. so no previous highest, no 2nd line

DIS 15min 10day
2/8 has the highest, and 3 bars before it is a previous highest


ATH1 is the highest of all highs.
ATH2 is the previous highest high, the value before the current highest high.


Code:
#prev_hihi

#https://usethinkscript.com/threads/previous-all-time-high.17903/
#Previous All-Time High

def na = double.nan;
def bn = barnumber();
def h1 = high;
def ATH1 = highestall(h1);

# find highest high
def h2;
if bn == 1 then {
h2 =  h1;
} else {
h2 = max(h1, h2[1]);
}

# find prev highest.
# if h2 has the same high as the highest, then ignore it, by using a value of 0
def ATH2 = highestall(if h2 == ath1 then 0 else h2);

plot z1 = ath1;
plot z2 = if ath2 > 0 then ath2 else na;


#--------------------------
# test stuff

addchartbubble(0, low,
h1 + "\n" +
h2 + "\n" +
ath1 + "\n" +
ath2 + "\n"
, color.yellow, no);

#plot z3 = h2;
#

2 lines, 1 at the highest, and 1 at the previous highest
 

Attachments

  • img1.JPG
    img1.JPG
    115.6 KB · Views: 96
your words are confusing.
'the last' of something on a chart, would be the current one, the one on the right side, the last candle.
do you mean the previous one?
instead of 'not the new one', do you mean 'not the current one' ?


test stocks chart 15min 10day

DOW , CSCO
the first bar is highest, on 1/26. so no previous highest, no 2nd line

DIS 15min 10day
2/8 has the highest, and 3 bars before it is a previous highest


ATH1 is the highest of all highs.
ATH2 is the previous highest high, the value before the current highest high.


Code:
#prev_hihi

#https://usethinkscript.com/threads/previous-all-time-high.17903/
#Previous All-Time High

def na = double.nan;
def bn = barnumber();
def h1 = high;
def ATH1 = highestall(h1);

# find highest high
def h2;
if bn == 1 then {
h2 =  h1;
} else {
h2 = max(h1, h2[1]);
}

# find prev highest.
# if h2 has the same high as the highest, then ignore it, by using a value of 0
def ATH2 = highestall(if h2 == ath1 then 0 else h2);

plot z1 = ath1;
plot z2 = if ath2 > 0 then ath2 else na;


#--------------------------
# test stuff

addchartbubble(0, low,
h1 + "\n" +
h2 + "\n" +
ath1 + "\n" +
ath2 + "\n"
, color.yellow, no);

#plot z3 = h2;
#

2 lines, 1 at the highest, and 1 at the previous highest
Thank you, Mr. Rocket @halcyonguy !! I will try to be more simplified next time
 

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
395 Online
Create Post

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