• Get $40 off VIP by signing up for a free account! Sign Up

Find High / Low + Range For Last x Number of Bars


Is there an indicator, website, app, or platform that shows the Hi/Low and Range for the last "x" days?

Looking for a more convenient way of doing this.
Found this in the TSL, give it a try.

# Paris: Here's a simple prior day high/low

plot PrevHigh = high("period" = AggregationPeriod.DAY)[1];

plot PrevLow = low("period" = AggregationPeriod.DAY)[1];

If you just want to look for the highest and lowest within the last 5 days (for example), then just turn on the "Show high/low bubbles" in ThinkorSwim's settings. Change the timeframe to the corresponding X days you want to check.

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

@BenTen Thanks. I was thinking of using examples like the code you posted to turn them into labels for the desired number of days.

I like the way Discord bots can show a table with data like S&R, float, etc.

Time Frame: D and up
Label Range: <high - low>
Label Hi: <high>
Label Low: <low>

The good thing about it is that you can see general price movement independent of chart time frame. Need to figure out the offset.
Last edited:
Almost there, only need to add offset and conditional color coding.


Last edited:
@korygill Thanks! Did finish the one I started and was comparing them both. This one has 2 plots and shows the most recent (last n days). I used an offset/index and length to create a subset then find highest/lowest, but need to use n-1 in length to get same values as yours.

Will take a closer look at your code and see what I can learn from it.

@korygill Is there a way to operate on a specific bar (knowing its number) rather than going through a loop to find it? Want to mark the first and last bars in a range determined by the user-selectable inputs.

Don't want to paint the entire bar per se because there are other indicators doing that, and prefer a dot/arrow to a bubble.
Not sure I fully understand. Doesn't the bar number change with each new tick? Also, scripts run at least once on every bar, and depend on 'declare once_per_bar' setting. If you don't want a chart bubble, then plot a value using PaintingStrategy.ARROW_DOWN for example.
@korygill Because the user selects the range of bars to search for the Hi/Low, I know the numbers/position of the two bars I want to mark.

All of the thinkscript examples I've seen use a function call that loops through all the bars when there's a change (unless you use once per bar, or even only on daily/intraday charts) and with conditional statements (If-then-else) do something else besides getting the return value of the function.

You can use a function like this, "high[1]" but I don't need a value, I need to operate/plot on that bar alone and don't need the value of a function.

Want to visually put a mark on the first and last bars of the range/group of bars used to obtain the Hi&Low, but thinkscript seems oriented towards loop statements, seems like you can't simply "plot bar[3].arrow" (or somehting like that).

In other words, I don't need to calculate Hi&Low, I want to draw a mark on Bar[x] and Bar[y].
Last edited:
Do you mean BOOLEAN_ARROW_UP/DOWN like this?
In this case you only plot your value on the bar the meets your condition and plot double.NaN on all the others. Remember, your script runs and evaluates on every bar.



  • r5BQk3o.png
    47.7 KB · Views: 178
Last edited by a moderator:
@thinky Trying to understand the practical use of this. Looks like you are finding the high and low for the selected range of bars and drawing support/resistance lines based on those. Correct?
Why would not just using one of the automatic studies that draw support/resistance lines do the same?
@horserider The S&R lines and the trendlines are manually drawn, not part of the study. Only the things with red outlines/arrows are part of the study (plus some of the labels). I prefer to keep charts as clean as possible and avoid conflicts with other studies that paint the bars.

It only marks the user selected period with its hi/lo values, and shows the price movement range for the same period.
I use the high/low lookback so I can see what effect "losing" a bar on a stochastic will do to its calculation and try to predict what the next value might be, especially on a 4hr stochastic (bars only change every 4hrs). If I see a high or low bar is gonna "fall off", then that will affect the stochastic. If the high/low bar is not near the Length, then the stochastic will prob remain unchanged. Useful when wondering if it will drop under 80 or over 20 for example.
Last edited:
@korygill Very different uses. Thanks for the example, I had misconceptions about how thinkscript works and the online manual wasn't good enough.

@horserider Wanted to visualize price ranges in a convenient way and make it generic enough to be of use in any future projects, while at the same time learning thinkscript, if only to modify other studies (eg., create settings for parameters instead of editing their code).
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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