Plot Lowest and Highest using IDataHolder()


I'm trying to figure out what Thinkscript is referencing when it uses these 'Lowest' and 'Highest' functions? Is this the lowest low at that close? is it the highest high since whatever that length is(so say 14, the highest high in the last 14 periods?) etc

plot LowerBand = Lowest(low, length);
plot UpperBand = Highest(high, length);
llow = Lowest(low, perioda)
hhigh = Highest(high, perioda)


Well-known member
Highest (IDataHolder data, int length);
Default values: length: 12
Returns the highest value of data for the last length bars.
Input parameters

ParameterDefault valueDescription
data-Defines data for which the highest value is found.
length12Defines period on which the highest value is found.

The example shows the Williams %R calculation. In particular, it is required to define the minimum low for the last length bars including the current bar. Therefore, to define the minimum, the example uses the Lowest function.

input length = 10;
def HH = Highest(high, length);
def LL = Lowest(low, length);
plot "Williams %R" = if HH == LL then -100 else (HH - close) / (HH - LL) * (-100);
Last edited by a moderator:


Well-known member
I took a look at your short code segment above and noted a couple of things to highlight. Please note that all statements should end with a ";" otherwise the code editor will flag an error.

You have also used two variables called llow and hhigh without using the "def" statement.

Here then is the corrected sequence of statements to make it pass through the code editor

input length = 14;
input perioda = 21;
plot LowerBand = Lowest(low, length);
plot UpperBand = Highest(high, length);
def llow = Lowest(low, perioda);
def hhigh = Highest(high, perioda);

That said, consider the following statement, I have assigned an arbitrary length of 21.

def llow = Lowest(low, length);

All this does is to determine the low for the last 21 bars, and assign that value to the variable llow;

Now if you wish to plot these values on your chart, you'll need to use the plot statement like so:

plot llow = Lowest(low, length);

Hope this helps


New member
When using GetValue (IDataHolder data, IDataHolder dynamic offset, int max offset) and setting synamicoffset > 5 and max offset to a value > 0, with chart aggregationperiod set to minute, the function seems to fail to deliver a result. Simply changing the max offset to 0 fixes my issue.


New member

I am trying to find the highest of several values for a scanner I am working on. I want to do something like
plot highestHigh = Highest(high, 100);
Which works fine until I come across stock that are recently IPO'd and do not have 100 days of data yet. In this case Highest returns N/A. If there a way to work around this. I tried to calculate the number of bars available however it doesn't seem like a variable number can be passed to the Highest function.

Any help would be greatly appreciated.


Similar threads