Find Hi/Low + Range For Last x Bars?

T

thinky

Member
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.
 
BenTen

BenTen

Administrative
Staff
VIP
Warehouse
Found this in the TSL, give it a try.

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

plot PrevHigh = high("period" = AggregationPeriod.DAY)[1];
PrevHigh.SetDefaultColor(Color.CYAN);
PrevHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot PrevLow = low("period" = AggregationPeriod.DAY)[1];
PrevLow.SetDefaultColor(Color.YELLOW);
PrevLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
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.
 
T

thinky

Member
@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>
 
Last edited:
T

thinky

Member
The good thing about it is that you can see general price movement independent of chart time frame. Need to figure out the offset.
 
markos

markos

Well-known member
VIP
Warehouse
@thinky Please look at our community OneNote. It has a plethora of scripts for what you want. It just takes a bit of hunting.
 
T

thinky

Member
Almost there, only need to add offset and conditional color coding.



 
Last edited:
T

thinky

Member
@markos Found an example that helped in figuring out the rest @ the cloud.

 
Last edited:
korygill

korygill

Active member
VIP
Warehouse
Does this help you?
 
T

thinky

Member
@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.

 
T

thinky

Member
@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.
 
korygill

korygill

Active member
VIP
Warehouse
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.
 
T

thinky

Member
@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:
korygill

korygill

Active member
VIP
Warehouse
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.

 
T

thinky

Member
@korygill So that's the use of N(ot)aN(umber), because of the plot loop. Need to get used to thinking in terms of loops when it comes to ToS charts.
 
H

horserider

Well-known member
VIP
Warehouse
@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?
 
T

thinky

Member
@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.
 
korygill

korygill

Active member
VIP
Warehouse
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:
H

horserider

Well-known member
VIP
Warehouse
@thinky Thanks for explaining. I am not seeing the purpose but if you can make it work go for it. It is a great piece of coding.
 
T

thinky

Member
@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:

Top