Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get max of subseries in Pine script

Lets suppose we have series of numbers. It contains some values [..., 3, 6, 4, 7]. I would like to get maximum of 100 last elements.

I tried max(series[100]), but it looks like series[100] operator returns sub-series discarding last 100 elements.

like image 315
flgdev Avatar asked Dec 07 '25 08:12

flgdev


1 Answers

That's correct. In Pine-script everything become a series, even a constant once you are using it, since all functions return a series. This means, that you can always put (non-series) constants in, but you can never get them out.

I think what you want is:

//@version=3
study("Max of N", shorttitle="max", overlay=false)
nmax = highest(n, 100) // n is the series of ALL bars
plot(nmax, style=line)
like image 111
not2qubit Avatar answered Dec 12 '25 12:12

not2qubit