Previous High is the highest bar within 5 bars ago

Im trying to get a plot code which states for example:

The previous sixth 15 min bar high is the highest bar within 6 bars ago and 6 bars after...intraday chart on the 15 min chart. I attached a picture of it..As of can see 10.43 is the highest bar..

I would like to condense my code that has the high bar to be highest with 6 bars ago than the six bars behind it instead of writing it this

def LPP15 = H15[6] >= H15[1] and H15[6] >= H15[2] and H15[6] >= H15[3] and H15[6] >= H15[4] and H15[6] >= H15[7] and H15[6] >= H15[8] and H15[6] >= H15[9] and H15[6] >= H15[10] and H15[6] >= H15[11] and H15[6] >= H15[12] ;

Plot Data: LP15 is true;

xbL10wh.png
 
Last edited:

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

Im trying to get a plot code which states for example:

The previous sixth 15 min bar high is the highest bar within 6 bars ago and 6 bars after...intraday chart on the 15 min chart. I attached a picture of it..As of can see 10.43 is the highest bar..

I would like to condense my code that has the high bar to be highest with 6 bars ago than the six bars behind it instead of writing it this

def LPP15 = H15[6] >= H15[1] and H15[6] >= H15[2] and H15[6] >= H15[3] and H15[6] >= H15[4] and H15[6] >= H15[7] and H15[6] >= H15[8] and H15[6] >= H15[9] and H15[6] >= H15[10] and H15[6] >= H15[11] and H15[6] >= H15[12] ;

Plot Data: LP15 is true;

this will find peaks and valleys, and draw arrows.
it is based on x number of bars before and after the bar. default is 7 bars.

the offset formula allows it to find a peak or valley, within 7 bars of the last bar. without this, the last 7 bars would be ignored.

Code:
#peaksvalleys_robert_03_updated

#https://usethinkscript.com/threads/zigzag-high-low-with-supply-demand-zones-for-thinkorswim.172/#post-7048
# post10
# Robert Payne

# define peaks / valleys
def na = double.nan;
def bn = BarNumber();

#def lastBar = HighestAll(if IsNaN(close) then 0 else bn);
def lastbn = HighestAll(if IsNaN(close) then 0 else bn);
def lastbar = bn == lastbn;
#def lastbar = (!isnan(close) and isnan(close[-1]));

def highx = high;
def lowx = low;
input length = 7;

def offset = Min(length - 1, lastbn - bn);
def peak = highx > Highest(highx[1], length - 1) and highx == GetValue(Highest(highx, length), -offset);
def valley = lowx < Lowest(lowx[1], length - 1) and lowx == GetValue(Lowest(lowx, length), -offset);

plot zhi = if peak then high*1.001 else na;
plot zlo = if valley then low*0.999 else na;

zlo.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
zlo.SetDefaultColor(Color.red);
zlo.setlineweight(1);
zlo.hidebubble();

zhi.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
zhi.SetDefaultColor(Color.green);
zhi.setlineweight(1);
zhi.hidebubble();
#
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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