# Function Highest/Lowest

3488 views
3488
Function for highest() and lowest()
```//@version=2
study(title='Function Highest/Lowest', overlay=true)
src = input(close)
length = input(10)

f_highest(_src, _length)=>
_adjusted_length = _length < 1 ? 1 : _length
_value = _src
for _i = 0 to (_adjusted_length-1)
_value := _src[_i] >= _value ? _src[_i] : _value
_return = _value

f_lowest(_src, _length)=>
_adjusted_length = _length < 1 ? 1 : _length
_value = _src
for _i = 0 to (_adjusted_length-1)
_value := _src[_i] <= _value ? _src[_i] : _value
_return = _value

h = f_highest(src, length)
l = f_lowest(src, length)

plot(h)
plot(l)```
hi thank you, is it possible to add range of period ? I mean for exemple from -20 period to -5 from actual candle ?

ibobo
@ibobo, f_highest(high, 20) like this?

RicardoSantos
@RicardoSantos, oops the square brackets got deleted:
f_highest(high<5>, 20)
replace <> with square brackets

RicardoSantos
@RicardoSantos, Thank you Ricardo, you mean like this ?

f_highest(high, 20) =>
_adjusted_length = _length < 1 ? 1 : _length
_value = _src
for _i = 0 to (_adjusted_length-1)
_value := _src >= _value ? _src : _value
_return = _value

ibobo
got deleted too )))

f_highest(high<5>, 20) =>
_adjusted_length = _length < 1 ? 1 : _length
_value = _src
for _i = 0 to (_adjusted_length-1)
_value := _src >= _value ? _src : _value
_return = _value

ibobo
@ibobo, you dont need to change the function, just how you call it:

These two pieces of code are probably the most used functions in Pine outside the built-ins, so thanks for them, Ricardo.

LucF
@LucF, discovered it today.... but was looking for them all my life. True story

This is great.. as I've noticed in version 3.. highest() and lowest() do not like taking in variables for length.. often results in:

line 34: Cannot call `highest` with arguments (series, series); available overloads: highest(series, integer) => series; highest(integer) => series;