How to get max of subseries in Pine script
11,501
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)
Related videos on Youtube
Author by
flgdev
Updated on June 04, 2022Comments
-
flgdev about 2 years
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. -
Jan about 3 yearsHi, thank you for answer. Is it possible to get highest of last n candles without current bar (closed only)? And what about skipping weekend candles?
-
not2qubit about 3 years@Jan Those are two different questions. Just search for them here first, and if there are no such questions then make sure to ask them in it's own separate question.
-
karatedog over 2 years@Jan: in Pine everything is a series.
close
is a series, andclose[1]
is a series as well, that is just shifted 1 item and start from[1]
. Asclose[1]
is a series in itself, and you can have the previous value from a series by using index[1]
, it is perfectly valid to write this:price_val = (close[1])[1]
.