How to get max of subseries in Pine script

14k views Asked by At

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.

1

There are 1 answers

3
not2qubit On BEST ANSWER

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)