RicardoSantos

Function Highest/Lowest

3048 views
148
3048 3
Function for highest() and lowest()
Remove from Favorite Scripts Add to Favorite Scripts
//@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)
These two pieces of code are probably the most used functions in Pine outside the built-ins, so thanks for them, Ricardo.
+1 Reply
@LucF, discovered it today.... but was looking for them all my life. True story
Reply
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;
+6 Reply
Home Stock Screener Forex Screener Crypto Screener Economic Calendar Shows How It Works Chart Features Pricing House Rules Moderators Website & Broker Solutions Widgets Charting Solutions Lightweight Charting Library Help Center Refer a friend Feature Request Blog & News FAQ Wiki Twitter
Profile Profile Settings Account and Billing Refer a friend My Support Tickets Help Center Ideas Published Followers Following Private Messages Chat Sign Out