Non-Complex HighestAll() Alternative?

Quant1

New member
Plus
Having some difficulty here- I've been trying to get around usage of the HighestAll function to determine the last bar on a given chart frame, however, this is quite baffling. Here's the simple call with HighestAll():

def lastBar = HighestAll(BarNumber());

Little baffled by the need to use the call to HighestAll(); if I manually enter an integer into lastBar (that is, in fact, the last bar on the chart), function works as expected. Any other attempts I have tried to get around usage of HighestAll() without manually updating do not work. Just using BarNumber() (which should give just the last bar in the chart anyway???) also does not work. Feel like there is a class mismatch here that isn't really present in the description of each of these functions.

For example, the alternative:

def bar = !IsNaN(close[-1]);
rec bars = if bar then bars[1]+1 else bars[1];
def lastBar = bars;

When plotted against HighestAll(BarNumber()) is functionally equivalent... Yet when used with, say, Robert Payne's Quadratic Polynomial script, does not yield the same result (?).

As above, I feel like this is a noob mistake, or that I'm missing something. Anything here is appreciated!
 
Solution
Having some difficulty here- I've been trying to get around usage of the HighestAll function to determine the last bar on a given chart frame, however, this is quite baffling. Here's the simple call with HighestAll():

def lastBar = HighestAll(BarNumber());

Little baffled by the need to use the call to HighestAll(); if I manually enter an integer into lastBar (that is, in fact, the last bar on the chart), function works as expected. Any other attempts I have tried to get around usage of HighestAll() without manually updating do not work. Just using BarNumber() (which should give just the last bar in the chart anyway???) also does not work. Feel like there is a class mismatch here that isn't really present in the description of each...
Having some difficulty here- I've been trying to get around usage of the HighestAll function to determine the last bar on a given chart frame, however, this is quite baffling. Here's the simple call with HighestAll():

def lastBar = HighestAll(BarNumber());

Little baffled by the need to use the call to HighestAll(); if I manually enter an integer into lastBar (that is, in fact, the last bar on the chart), function works as expected. Any other attempts I have tried to get around usage of HighestAll() without manually updating do not work. Just using BarNumber() (which should give just the last bar in the chart anyway???) also does not work. Feel like there is a class mismatch here that isn't really present in the description of each of these functions.

For example, the alternative:

def bar = !IsNaN(close[-1]);
rec bars = if bar then bars[1]+1 else bars[1];
def lastBar = bars;

When plotted against HighestAll(BarNumber()) is functionally equivalent... Yet when used with, say, Robert Payne's Quadratic Polynomial script, does not yield the same result (?).

As above, I feel like this is a noob mistake, or that I'm missing something. Anything here is appreciated!

all the candles are regularly redrawn on the chart. during this time, every candle will be 'the highest numbered bar' for a split second. this results in what you are seeing.

there is a way to use a large negative offset and a couple formulas, to find stats on the last candle ( like barnumber). look at the posts in this thread.
https://usethinkscript.com/threads/current-price-line-indicator-for-thinkorswim.8793/
 

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

Having some difficulty here- I've been trying to get around usage of the HighestAll function to determine the last bar on a given chart frame, however, this is quite baffling. Here's the simple call with HighestAll():

def lastBar = HighestAll(BarNumber());

Little baffled by the need to use the call to HighestAll(); if I manually enter an integer into lastBar (that is, in fact, the last bar on the chart), function works as expected. Any other attempts I have tried to get around usage of HighestAll() without manually updating do not work. Just using BarNumber() (which should give just the last bar in the chart anyway???) also does not work. Feel like there is a class mismatch here that isn't really present in the description of each of these functions.

For example, the alternative:

def bar = !IsNaN(close[-1]);
rec bars = if bar then bars[1]+1 else bars[1];
def lastBar = bars;

When plotted against HighestAll(BarNumber()) is functionally equivalent... Yet when used with, say, Robert Payne's Quadratic Polynomial script, does not yield the same result (?).

As above, I feel like this is a noob mistake, or that I'm missing something. Anything here is appreciated!


here is a code using a big negative offset, to find the last barnumber

2nd half shows that a loop doesn't work

Code:
# alt_barnum_lastbar2

# find the last barnumber

#  modified version of
#  Line At Price
#  Mobius
#  Alternative to using the HighestAll() function
# https://usethinkscript.com/threads/current-price-line-indicator-for-thinkorswim.8793/

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

#def lox = if !isnan(close) then low else if isnan(close) then lox[1] else low[1];
def lox = if !isnan(close) then low else lox[1];

input barsBack = 1000;

def lastbn1 = if !IsNaN(close) and IsNaN(close[-1])
    then barnumber()
    else lastbn1[1];

def lastbn2 = if isNaN(close[-barsBack])
    then lastbn1[-barsBack]
    else Double.NaN;


input test1 = yes;
addchartbubble(test1, lox,
"offset\n" +
bn + "  bn\n" +
lastbn1 + "\n" +
lastbn2 + "\n" 
,color.yellow, no);

addlabel(1, "last bar# " + lastbn2, color.yellow);


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

# example to show that using a loop, doesn't work.
#  on every bar, it thinks it is the last bar.
def last;
if bn == 1 then {
  last = fold i = 1 to bn
  with p
  do if getvalue(bn, -i ) > p then getvalue(bn, -i ) else p;
} else {
  last = last[1];
};

input test_loop = yes;
addchartbubble(test_loop, lox,
 "loop\n" +
 bn + "\n" +
 last
, color.cyan, no);
#
 
Solution

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