color reference
Color constructors, channel accessors, interpolation helpers, and named colors; channels and alpha are 0-255 and out-of-range values clamp.
Color constructors, channel accessors, interpolation helpers, and named colors; channels and alpha are 0-255 and out-of-range values clamp.
Accepted values
These named values are the complete choices accepted by parameters of each type.
ColorSpace
colorspace.rgbRGB color-scale interpolation by channel.colorspace.hslHSL color-scale interpolation with shortest-path hue.Easing
easing.linearLinear segment easing, leaving the local position unchanged.easing.smoothstepSmoothstep segment easing with t*t*(3-2t).easing.smootherstepSmootherstep segment easing with t*t*t*(t*(6t-15)+10).Named colors
Use these constants anywhere a color value is accepted. Select a hex value to copy it.
| Constant | Value |
|---|---|
color.up | |
color.down | |
color.red | |
color.maroon | |
color.brown | |
color.orange | |
color.amber | |
color.yellow | |
color.olive | |
color.green | |
color.emerald | |
color.teal | |
color.cyan | |
color.lightskyblue | |
color.blue | |
color.indigo | |
color.navy | |
color.purple | |
color.magenta | |
color.pink | |
color.white | |
color.silver | |
color.gray | |
color.black | |
color.transparent |
color.rgb
color.rgb(r: int, g: int, b: int, a: int = 255) -> colorCreates a color from red, green, blue, and opacity values.
r, g, and b each use an integer from 0 to 255. Out-of-range values are
clamped to the nearest end of that range.
a sets opacity from 0 (transparent) to 255 (opaque) and defaults to 255.
For example, color.rgb(17, 34, 51) equals #112233. All inputs must be
non-null integers; fractions are not accepted.
Contracts
r: Accepted range: 0 to 255. Values outside the range are adjusted to the nearest allowed value.g: Accepted range: 0 to 255. Values outside the range are adjusted to the nearest allowed value.b: Accepted range: 0 to 255. Values outside the range are adjusted to the nearest allowed value.a: Accepted range: 0 to 255. Values outside the range are adjusted to the nearest allowed value.
Example
script "RGB Color"
data chart = subscribe(data.ohlcv)
plot ma = plot.line(title: "MA", color: color.rgb(33, 150, 243, 192))
on chart.update {
ma.plot(ta.sma(chart.close, 20))
}color.withAlpha
color.withAlpha(c: color, a: int) -> colorChanges a color's opacity.
c supplies the color. a sets opacity from 0 (transparent) to 255 (opaque).
It is an integer, not a percentage. Out-of-range values are clamped to 0 or 255.
Check for null or use ?? before passing a nullable color.
Contracts
a: Accepted range: 0 to 255. Values outside the range are adjusted to the nearest allowed value.
Example
script "Alpha Color"
data chart = subscribe(data.ohlcv)
plot closeLine = plot.line(title: "Close")
on chart.update {
let shade = color.withAlpha(chart.close >= chart.open ? color.green : color.red, 96)
closeLine.plot(chart.close, color: shade)
}color.r
color.r(c: color) -> intReturns the red channel from a color.
Returns the red value of c as an integer from 0 to 255.
Check for null or use ?? before passing a nullable color.
Example
script "Red Channel"
data chart = subscribe(data.ohlcv)
on chart.update {
let shade = chart.close >= chart.open ? color.green : color.red
let red = color.r(shade)
}color.g
color.g(c: color) -> intReturns the green channel from a color.
Returns the green value of c as an integer from 0 to 255.
Check for null or use ?? before passing a nullable color.
Example
script "Green Channel"
data chart = subscribe(data.ohlcv)
on chart.update {
let shade = chart.close >= chart.open ? color.green : color.red
let green = color.g(shade)
}color.b
color.b(c: color) -> intReturns the blue channel from a color.
Returns the blue value of c as an integer from 0 to 255.
Check for null or use ?? before passing a nullable color.
Example
script "Blue Channel"
data chart = subscribe(data.ohlcv)
on chart.update {
let shade = chart.close >= chart.open ? color.blue : color.gray
let blue = color.b(shade)
}color.a
color.a(c: color) -> intReturns the alpha channel from a color.
c must be a non-null color. The result is the non-null alpha channel as an
integer in the 0..=255 range. Six-digit hex colors have alpha 255;
eight-digit hex colors carry their explicit alpha value.
Example
script "Alpha Channel"
data chart = subscribe(data.ohlcv)
on chart.update {
let faded = color.withAlpha(color.blue, 96)
let alpha = color.a(faded)
}color.lighten
color.lighten(c: color, percent: float) -> colorLightens a color by mixing it toward white.
c is the starting color. percent sets how much to mix it toward white.
The result is a non-null color with valid color-channel values.
Check for null or use ?? before passing nullable inputs.
Example
script "Lighten Color"
data chart = subscribe(data.ohlcv)
plot closeLine = plot.line(title: "Close")
on chart.update {
let shade = color.lighten(color.blue, chart.close >= chart.open ? 20.0 : 0.0)
closeLine.plot(chart.close, color: shade)
}color.darken
color.darken(c: color, percent: float) -> colorDarkens a color by mixing it toward black.
c is the starting color. percent sets how much to mix it toward black.
The result is a non-null color with valid color-channel values.
Check for null or use ?? before passing nullable inputs.
Example
script "Darken Color"
data chart = subscribe(data.ohlcv)
plot closeLine = plot.line(title: "Close")
on chart.update {
let shade = color.darken(color.orange, chart.close < chart.open ? 20.0 : 0.0)
closeLine.plot(chart.close, color: shade)
}color.gradient
color.gradient(value: float, bottom: float, top: float, start: color, end: color) -> colorBlends between two colors based on a number.
value chooses a position between bottom and top. Values are clamped to
that range without an error.
Returns start below the range or when bottom == top, and end above the
range. Between the bounds, red, green, blue, and opacity change linearly.
The result uses valid color-channel values.
Check for null or use ?? before passing nullable numbers or colors.
Example
script "Gradient Color"
data chart = subscribe(data.ohlcv)
plot momentum = plot.line(title: "Momentum")
on chart.update {
let score = ta.roc(chart.close, 10) ?? 0.0
let shade = color.gradient(score, -5.0, 5.0, color.red, color.green)
momentum.plot(score, color: shade)
}color.scale
color.scale(at: float[], colors: color[], space: ColorSpace = 2, easing: Easing = 1) -> ColorScaleCreates a color scale from a list of positions and colors.
Define the scale during setup, then read colors with .sample.
atlists positions in ascending order.colorslists the matching colors. Both setup arrays need the same length and at least two entries.spacechoosescolorspace.rgborcolorspace.hsl, defaulting to HSL.easingchooses how colors change between positions:easing.linear,easing.smoothstep, oreasing.smootherstep. The default is linear.
Positions must be finite and cannot descend; invalid lists are rejected before the script runs. Equal adjacent positions create a sharp color change: the earlier color applies at that position, and the later color applies beyond it. Opacity always changes linearly.
The scale cannot be saved in state or passed to other calls. Use its .sample
method to read it.
Example
script "Color Scale"
setup heat = color.scale(
at: [-1.0, 0.0, 1.0],
colors: [color.red, color.gray, color.green],
easing: easing.smoothstep,
)
data chart = subscribe(data.ohlcv)
plot out = plot.line(title: "out")
on chart.update {
out.plot(chart.close, color: heat.sample(ta.roc(chart.close, 10) ?? 0.0))
}Accepted values
space:ColorSpacevalues — 2 available.easing:Easingvalues — 3 available.
Midpoint stays muddy olive because the channels blend directly.
Midpoint passes through bright yellow because hue rotates through the shortest path.
Color changes at a constant rate across the bar.
The ends ease in and out, so the middle transitions faster.
The same shape, but with even softer acceleration at both ends.
colorscale.sample
colorscale.sample(t: float) -> colorReads a color from a scale at a position.
t chooses the position. Values outside the scale are clamped: below it returns
the first color, above it returns the last. Null or NaN also returns the first
color without an error.
Between positions, the scale's easing and color space determine the blend. HSL takes the shortest path around the color wheel. A gray endpoint uses the other endpoint's hue. Opacity changes linearly in every color space.
Example
script "Sample Color Scale"
setup heat = color.scale(
at: [-1.0, 0.0, 1.0],
colors: [color.red, color.gray, color.green],
)
data chart = subscribe(data.ohlcv)
plot momentum = plot.line(title: "Momentum")
on chart.update {
let value = ta.roc(chart.close, 10) ?? 0.0
momentum.plot(value, color: heat.sample(value))
}colorspace.rgb
colorspace.rgb: ColorSpace = 1RGB color-scale interpolation by channel.
colorspace.hsl
colorspace.hsl: ColorSpace = 2HSL color-scale interpolation with shortest-path hue.
easing.linear
easing.linear: Easing = 1Linear segment easing, leaving the local position unchanged.
easing.smoothstep
easing.smoothstep: Easing = 2Smoothstep segment easing with tt(3-2t).
easing.smootherstep
easing.smootherstep: Easing = 3Smootherstep segment easing with ttt*(t*(6t-15)+10).
color.up
color.up: color = #00ff00Bullish green (#00ff00).
color.green
color.green: color = #00ff00Green (#00ff00).
color.down
color.down: color = #e81f59Bearish red (#e81f59).
color.red
color.red: color = #e81f59Red (#e81f59).
color.maroon
color.maroon: color = #800000Maroon (#800000).
color.brown
color.brown: color = #a52a2aBrown (#a52a2a).
color.orange
color.orange: color = #ffa500Orange (#ffa500).
color.amber
color.amber: color = #f59e0bAmber (#f59e0b).
color.yellow
color.yellow: color = #ffff00Yellow (#ffff00).
color.olive
color.olive: color = #808000Olive (#808000).
color.emerald
color.emerald: color = #16c784Emerald (#16c784).
color.teal
color.teal: color = #008080Teal (#008080).
color.cyan
color.cyan: color = #00eeffCyan (#00eeff).
color.lightskyblue
color.lightskyblue: color = #87cefaLight sky blue (#87cefa).
color.blue
color.blue: color = #466be5Blue (#466be5).
color.indigo
color.indigo: color = #2962ffIndigo (#2962ff).
color.navy
color.navy: color = #000080Navy (#000080).
color.purple
color.purple: color = #800080Purple (#800080).
color.magenta
color.magenta: color = #ff00ffMagenta (#ff00ff).
color.pink
color.pink: color = #ffc0cbPink (#ffc0cb).
color.white
color.white: color = #ffffffWhite (#ffffff).
color.silver
color.silver: color = #9e9e9eSilver (#9e9e9e).
color.gray
color.gray: color = #808080Gray (#808080).
color.black
color.black: color = #000000Black (#000000).
color.transparent
color.transparent: color = #00000000Fully transparent black (#00000000).