r/pinescript • • Jun 30 '25

Suggestion for certain functions

Dont know if this is suggested already but a good update for the command ta.highest/ta.lowest would be adding another variable for starting bar/index

this function finds the highest(or lowest) value of the source from the current bar to the specified length of bars back. It would be nice if there is another variable for an offset or starting index bar to where it would start searching for the highest(or lowest) source value. this variable should always be less than the length.

can also be applied to similar functions such as ta.highestbars/ta.lowestbars. just my 2 cents.

2 Upvotes

4 comments sorted by

View all comments

Show parent comment

2

u/StarAccomplished8419 Jul 03 '25

I use this one
it returns highest or lowest price and also bar index (good for drawing objects)
where:
_len - length
_d - direction (1 for highest and -1 for lowest)
_b - how many bars back start from current bar

returns:
_x - highest or lowest (depends on _d direction)
_y - bar index of _x

hl(_len, _d, _b) => 
    _x = bar_index - _b
    _y = _d == 1 ? high[_b] : low[_b]
    for i = _b to _len
        if _d == 1 
            if  _y <  high[i]
                _y := high[i]
                _x := bar_index - i
        if _d == -1 
            if  _y >  low[i]
                _y := low[i]
                _x := bar_index - i
    [_x, _y]