Second highest high within 42 days

mark91345

New member
It's easy to draw the "highest high" over a 42-day period (approx 2 months); instead, I want to draw the "second highest" high over a 42-day period. I appreciate the help.


0WxbsQg.jpg
 
Solution
It's easy to draw the "highest high" over a 42-day period (approx 2 months); instead, I want to draw the "second highest" high over a 42-day period. I appreciate the help.

this can plot 3 price levels,
the highest price over x past bars
the highest price over x past bars, that is less than highest
the highest price over x past bars, that is less than 2nd highest

default is 42 bars
set chart to day

Code:
# second_hi_xdays_00

#https://usethinkscript.com/threads/second-highest-high-within-42-days.15009/
# set chart to day

def na = double.nan;
def bn = barnumber();

input days = 42;
def hi1 = highest(high, days);

def hi2 = fold i2 = 0 to days
 with p2
 do if getvalue(high, i2) < hi1 and getvalue(high, i2) > p2 then...
It's easy to draw the "highest high" over a 42-day period (approx 2 months); instead, I want to draw the "second highest" high over a 42-day period. I appreciate the help.

this can plot 3 price levels,
the highest price over x past bars
the highest price over x past bars, that is less than highest
the highest price over x past bars, that is less than 2nd highest

default is 42 bars
set chart to day

Code:
# second_hi_xdays_00

#https://usethinkscript.com/threads/second-highest-high-within-42-days.15009/
# set chart to day

def na = double.nan;
def bn = barnumber();

input days = 42;
def hi1 = highest(high, days);

def hi2 = fold i2 = 0 to days
 with p2
 do if getvalue(high, i2) < hi1 and getvalue(high, i2) > p2 then getvalue(high, i2) else p2;

def hi3 = fold i3 = 0 to days
 with p3
 do if getvalue(high, i3) < hi2 and getvalue(high, i3) > p3 then getvalue(high, i3) else p3;

input line1 = no;
input line2 = yes;
input line3 = no;

plot z1 = if line1 then hi1 else na;
z1.SetDefaultColor(getColor(1));
z1.hidebubble();
plot z2 = if line2 then hi2 else na;
z2.SetDefaultColor(getColor(2));
z2.hidebubble();
plot z3 = if line3 then hi3 else na;
z3.SetDefaultColor(getColor(3));
z3.hidebubble();


#--------------------------

input test_bubble = no;
addchartbubble(test_bubble, low,
hi1 + "  1\n" +
hi2 + "  2\n" +
hi3 + "  3"
, color.yellow, no);
#
 
Solution

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
413 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