Future bars - find Highest price and lowest price

hbsopen

New member
VIP
Hi all - I gave up trying this. Essentially, what I am looking to do is:

- Take input = fwd_bars (let's say 11).

- let's say today is Jan 1st 2025.

- then looking forward for 11 bars (on a daily chart or for intra-day convert it to the appropriate number of bars equivalent for 11 days).

- find the highest price within the future bars and the lowest price. Subtract each from Jan 1st (meaning current bar) close and plot the two values.

I have tried Highest(high()) and used the Offset, but Highest() seems to be going forward to 11th day and getting the highest. Which is not what I want, because highest value could have occured in between.

I tried LookUp highest but this looks at the previous 11 bars!

I do understand that for the most recent 11 days there will not be a plot, which is fine.

Code:
declare lower;

input Look_fwd = 11;


#def hi = highest(high()[-look_fwd]);

def hi = LookUpHighest(length = -look_fwd);
def hi_diff = hi - close();

def low = Lowest(low()[-Look_fwd]);
def lo_diff = low - close();

plot hidiff = hi_diff;
plot lodiff = lo_diff;
 
Last edited by a moderator:
Solution
Hi all - I gave up trying this. Essentially, what I am looking to do is:

- Take input = fwd_bars (let's say 11).

- let's say today is Jan 1st 2025.

- then looking forward for 11 bars (on a daily chart or for intra-day convert it to the appropriate number of bars equivalent for 11 days).

- find the highest price within the future bars and the lowest price. Subtract each from Jan 1st (meaning current bar) close and plot the two values.

I have tried Highest(high()) and used the Offset, but Highest() seems to be going forward to 11th day and getting the highest. Which is not what I want, because highest value could have occured in between.

I tried LookUp highest but this looks at the previous 11 bars!

I do understand that for the...

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

Hi all - I gave up trying this. Essentially, what I am looking to do is:

- Take input = fwd_bars (let's say 11).

- let's say today is Jan 1st 2025.

- then looking forward for 11 bars (on a daily chart or for intra-day convert it to the appropriate number of bars equivalent for 11 days).

- find the highest price within the future bars and the lowest price. Subtract each from Jan 1st (meaning current bar) close and plot the two values.

I have tried Highest(high()) and used the Offset, but Highest() seems to be going forward to 11th day and getting the highest. Which is not what I want, because highest value could have occured in between.

I tried LookUp highest but this looks at the previous 11 bars!

I do understand that for the most recent 11 days there will not be a plot, which is fine.

Code:
declare lower;

input Look_fwd = 11;


#def hi = highest(high()[-look_fwd]);

def hi = LookUpHighest(length = -look_fwd);
def hi_diff = hi - close();

def low = Lowest(low()[-Look_fwd]);
def lo_diff = low - close();

plot hidiff = hi_diff;
plot lodiff = lo_diff;

EDIT
i didn't include any aggregation in this.
the chart has to be set to day, if you want to get data for days.

Code:
declare lower;

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

def lastbn = HighestAll(if IsNaN(close) then 0 else bn);
def lastbar = bn == lastbn;
input Look_fwd = 11;

#   these stop drawing a line  (Look_fwd)  bars from last bar
#def hi = highest(high[-(look_fwd-1)],look_fwd);
#def lo = lowest(low[-(look_fwd-1)],look_fwd);

#   these draw a line all the way to the last bar
def offset = Min(look_fwd - 1, lastbn - bn);
def hi = getvalue(Highest(high, Look_fwd), -offset);
def lo = getvalue(lowest(low, Look_fwd), -offset);

def hi_diff = hi - close();
def lo_diff = lo - close();

plot hidiff = hi_diff;
plot lodiff = lo_diff;
#
 
Last edited:
Solution
@halcyonguy --> Very many thanks. This is perfect, exactly what I was looking for. Could I please extend this thread with one more question - to educate myself with ThinkScript. You have used syntax Highest() and it worked .. however when I read the documentation 'Returns the highest value of data for the last length bars.' .. the way I understood is that it returns the value for the last length bar and not in between if highest or lowest occured sometime in between. But the way you have coded it works!
 
@halcyonguy --> Very many thanks. This is perfect, exactly what I was looking for. Could I please extend this thread with one more question - to educate myself with ThinkScript. You have used syntax Highest() and it worked .. however when I read the documentation 'Returns the highest value of data for the last length bars.' .. the way I understood is that it returns the value for the last length bar and not in between if highest or lowest occured sometime in between. But the way you have coded it works!
Highest() returns the highest value within the range desired, just as HighestAll() would return the highest value with the current Chart range history...
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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