Sidechair

color()

Browse the reference

Converts a value to the color type; color(na) gives a na that is typed as a colour.

Try it in the editor

color(x) fixes the type of a colour variable. Use it as var c = color(na) when the colour is chosen later, because plain na carries no type.

A colour is a value like color.red or color.new(color.red, 50); this cast does not build one. Use color.new() or color.rgb() to create colours.

Syntax

Pine Script
color(x: const color) -> const color
color(x: input color) -> input color
color(x: simple color) -> simple color
color(x: series color) -> series color

Arguments

NameTypeDefaultDescription
xconst/input/simple/series colorrequiredThe value to convert. A colour or na.

Returns

const/input/simple/series color: The same colour.

Remarks

  • color(na) is na, and a plot or bgcolor given na for its colour draws nothing.
  • On Sidechair: color() returns its argument as it is; the engine tracks types loosely, so the cast mainly documents intent and fixes the declared type.

Example

Pine ScriptA colour chosen laterOpen in editor
//@version=6
indicator("color(na)", overlay = true)
var tint = color(na)
tint := close > open ? color.new(color.green, 85) : color.new(color.red, 85)
bgcolor(tint)

See also

Runs on Sidechair