Explain what this is useful for?

maslowski95

New member
Code:
def lastBar = HighestAll(if !IsNaN(close) then BarNumber() else 0);

A script was handed to me by a client and they had this line in their script. I've seen HighestAll(BarNumber()) before I'm just unsure what this value is actually holding.

They go on to use this variable in calculations later, such as:
Code:
def offset = Min(waveLength - 1, lastBar - BarNumber());

Doesn't Highest all calculate the highest value within a range, feeding it BarNumber would give up until the current time? Why assign this to 'last bar'?
 
Last edited:
Each bar is incrementally numbered from left to right. In this particular case, HighestAll will return the number of the final bar on the chart, while avoiding any potential blank bars, which are created by the right side expansion area in the time axis settings. Its forward looking.

lastBar - BarNumber() would give the number of bars remaining on each iteration of the script.

I am assuming waveLength is the number of bars to use in some other calculation.

Using Min() to get the smaller of the two, I am assuming, is used so that waveLength does not overrun the available data as it runs out on the right edge of the chart.

I should note that HighestAll(), along will all full range functions, were changed a little while back. Their inclusion will now force a ONCE_PER_BAR declaration without consent.
 
Each bar is incrementally numbered from left to right. In this particular case, HighestAll will return the number of the final bar on the chart, while avoiding any potential blank bars, which are created by the right side expansion area in the time axis settings. Its forward looking.

lastBar - BarNumber() would give the number of bars remaining on each iteration of the script.

I am assuming waveLength is the number of bars to use in some other calculation.

Using Min() to get the smaller of the two, I am assuming, is used so that waveLength does not overrun the available data as it runs out on the right edge of the chart.

I should note that HighestAll(), along will all full range functions, were changed a little while back. Their inclusion will now force a ONCE_PER_BAR declaration without consent.
so lastBar - BarNumber() will always be zero or less, no? This means they are basically asking is (12 - Znonpos) which will 100% always evaluate to true. I'm sorry I'm very unfamiliar with ThinkScript and just getting my bearings. Wavelength is =13 so that's why I say in the example it's always 12.
 
Zero or more, lastbar will be the bar number of the right most bar. BarNumber() will be the number of the current bar as the script iterates though each bar from left to right.

10 bars total, on bar 8 = 2 bars remaining.

If 2 < wavelength, then just use 2 instead of wavelength, or else you get into NaN values or something.

There is very likely an easier way to do this without highest all as well
 

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