Sidechair

series

Browse the reference

The qualifier for a value that can change on every bar. Prices, indicator results and anything computed per bar are series.

Try it in the editor

Pine Script ranks every value by when it is known. The qualifiers, from earliest to latest, are const < input < simple < series. A const value is fixed when the script compiles, an input value is chosen in the settings before the script runs, a simple value is known on the first bar and then never changes, and a series value can be different on every bar.

A value can always move to a later qualifier, but never to an earlier one. A const int works wherever a simple int or series int is expected, but a series int cannot be used where a function needs a simple int. close, volume, bar_index and the result of every ta.* function are series.

Remarks

  • Series values keep their history: close[1] is the value on the previous bar. A series is na before its first value.
  • Write the keyword before a type to be explicit, as in series float x = close. Leaving it off is normal, because the compiler picks the qualifier from the expression.
  • A function argument typed simple, such as the length of some request.* calls, rejects a series value. Use an input or a const there instead.
  • On Sidechair: a qualifier written in a declaration is accepted and not enforced. Calls to built-in functions are checked, so passing a series where a simple is required is a compile error with the line and column.

Example

Pine ScriptSeries and input valuesOpen in editor
//@version=6
indicator("Series vs input", overlay = true)
len = input.int(20, "Length", minval = 2)
src = close
avg = ta.sma(src, len)
plot(src, "Close", color.gray)
plot(avg, "Average", color.blue, 2)

See also

Runs on Sidechair