如何在 Pine 脚本中获取子系列的最大值

How to get max of subseries in Pine script

假设我们有一系列数字。它包含一些值 [..., 3, 6, 4, 7]。我想获得最多 100 个最后的元素。

我尝试了 max(series[100]),但看起来系列 [100] 运算符 returns 子系列丢弃了最后 100 个元素。

没错。在 Pine-script 中,所有东西 都变成一个系列,一旦你使用它甚至是一个常量,因为所有函数 return a series。这意味着,您始终可以将(非系列)常量 放入 ,但您永远无法将它们放入 out.

我想你想要的是:

//@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)