Sidechair

const

Browse the reference

The qualifier for a value fixed when the script is compiled: a literal, or an expression made only of literals and other constants.

Try it in the editor

A const value is known before the script runs and cannot change. A literal such as 14, "Close" or #2962FF is const, and so is any expression built only from consts. const is the lowest of the qualifiers: const < input < simple < series.

Some arguments must be const, for example the title strings of indicator() and plot(), and the default values in input.*(). Write const before the type to declare one yourself: const int LEN = 14. You can then use LEN in any place that wants a const, simple or series int.

Remarks

  • A const cannot be reassigned. A name in capitals is the usual convention for a const.
  • A built-in cast such as float(14) of a const argument is still const. Mixing in any series value, such as close, makes the result a series.
  • On Sidechair: a const qualifier written in a declaration is accepted and not enforced. A non-const value passed to an argument of a built-in function that requires a const is a compile error.

Example

Pine ScriptNamed constantsOpen in editor
//@version=6
indicator("Constants", overlay = true)
const int LEN = 20
const float WIDTH = 2.0
const color BAND = color.blue
basis = ta.sma(close, LEN)
dev = ta.stdev(close, LEN) * WIDTH
plot(basis, "Basis", BAND)
plot(basis + dev, "Upper", color.new(BAND, 50))
plot(basis - dev, "Lower", color.new(BAND, 50))

See also

Runs on Sidechair