color reference
Colours, gradients and colour scales.
Colours are #RRGGBB or #RRGGBBAA literals or built with color.rgb. color.up and color.down follow the chart’s candle colours; color.gradient and color.scale map values to colours.
Functions
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.
| Parameter | Type |
|---|---|
c | color |
Returns int
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.
| Parameter | Type |
|---|---|
c | color |
Returns int
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.
| Parameter | Type |
|---|---|
c | color |
percent | float |
Returns color
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.
| Parameter | Type |
|---|---|
c | color |
Returns int
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.
| Parameter | Type |
|---|---|
value | float |
bottom | float |
top | float |
start | color |
end | color |
Returns color
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.
| Parameter | Type |
|---|---|
c | color |
percent | float |
Returns color
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.
| Parameter | Type |
|---|---|
c | color |
Returns int
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.
| Parameter | Type |
|---|---|
r | int |
g | int |
b | int |
a | int |
Returns color
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.
| Parameter | Type |
|---|---|
at | float[] |
colors | color[] |
space | ColorSpace |
easing | Easing |
Returns ColorScale
Available in Setup only: declarations, setup and state initialisers.
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.
| Parameter | Type |
|---|---|
c | color |
a | int |
Returns color
Methods
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.
| Parameter | Type |
|---|---|
t | float |
Returns color
Available in Handlers and functions called from handlers.
Constants
| Constant | Type | Value | Description |
|---|---|---|---|
color.amber | color | #f59e0b | Amber (#f59e0b). |
color.black | color | #000000 | Black (#000000). |
color.blue | color | #466be5 | Blue (#466be5). |
color.brown | color | #a52a2a | Brown (#a52a2a). |
color.cyan | color | #00eeff | Cyan (#00eeff). |
color.down | color | #e81f59 | Bearish red (#e81f59). |
color.emerald | color | #16c784 | Emerald (#16c784). |
color.gray | color | #808080 | Gray (#808080). |
color.green | color | #00ff00 | Green (#00ff00). |
color.indigo | color | #2962ff | Indigo (#2962ff). |
color.lightskyblue | color | #87cefa | Light sky blue (#87cefa). |
color.magenta | color | #ff00ff | Magenta (#ff00ff). |
color.maroon | color | #800000 | Maroon (#800000). |
color.navy | color | #000080 | Navy (#000080). |
color.olive | color | #808000 | Olive (#808000). |
color.orange | color | #ffa500 | Orange (#ffa500). |
color.pink | color | #ffc0cb | Pink (#ffc0cb). |
color.purple | color | #800080 | Purple (#800080). |
color.red | color | #e81f59 | Red (#e81f59). |
color.silver | color | #9e9e9e | Silver (#9e9e9e). |
color.teal | color | #008080 | Teal (#008080). |
color.transparent | color | #00000000 | Fully transparent black (#00000000). |
color.up | color | #00ff00 | Bullish green (#00ff00). |
color.white | color | #ffffff | White (#ffffff). |
color.yellow | color | #ffff00 | Yellow (#ffff00). |
colorspace.hsl | ColorSpace | 2 | HSL color-scale interpolation with shortest-path hue. |
colorspace.rgb | ColorSpace | 1 | RGB color-scale interpolation by channel. |
easing.linear | Easing | 1 | Linear segment easing, leaving the local position unchanged. |
easing.smootherstep | Easing | 3 | Smootherstep segment easing with ttt*(t*(6t-15)+10). |
easing.smoothstep | Easing | 2 | Smoothstep segment easing with tt(3-2t). |