Appearance
Color
Kind: module
Namespace: color
Provides named color constants and functions for creating custom colors with transparency.
color.create()
Kind: func
Creates a color from hex string, RGBA components, or applies transparency to an existing color.
Syntax
color.create(hex) → color
color.create({r, g, b, a}) → color
color.create(baseColor, transparency) → colorOverloads
Creates a color from hex string or named color:
color.create(hex) → color
| Name | Type | Description |
|---|---|---|
| hex | string | Hex string ("#RGB", "#RRGGBB", "#RRGGBBAA") or name ("red") |
Creates a color from RGBA components:
color.create({r, g, b, a}) → color
| Name | Type | Default | Description |
|---|---|---|---|
| r? | int | 0 | Red (0-255) |
| g? | int | 0 | Green (0-255) |
| b? | int | 0 | Blue (0-255) |
| a? | int | 255 | Alpha (0-255) |
Applies transparency to existing color:
color.create(baseColor, transparency) → color
| Name | Type | Description |
|---|---|---|
| baseColor | color | Base color to modify |
| transparency | int | 0 (opaque) to 100 (fully transparent) |
Returns
The color value.
Example
javascript
// Create from hex string
const c1 = color.create("#FF0000"); // red
const c2 = color.create("#FF000080"); // red, 50% opacity
const c3 = color.create("#F00"); // shorthand red
// Create from RGBA components
const c4 = color.create({r: 255, g: 0, b: 0}); // red
const c5 = color.create({r: 255, g: 0, b: 0, a: 128}); // red, 50% opacity
// Apply transparency
const c6 = color.create(color.RED, 50); // red, 50% transparent
const c7 = color.create(color.BLUE, 90); // blue, 90% transparentjavascript
// Conditional coloring
function onTick() {
const sma = ta.sma(close, 20);
const priceColor = close > sma ? color.GREEN : color.RED;
spline(close, {title: "Price", color: priceColor});
}Named Colors
Predefined color constants. Values follow the CSS Color specification.
color.BLACK
Kind: constant
Value: black (#000000)
Predefined black color.
color.SILVER
Kind: constant
Value: silver (#C0C0C0)
Predefined silver color.
color.GRAY
Kind: constant
Value: gray (#808080)
Predefined gray color.
color.WHITE
Kind: constant
Value: white (#FFFFFF)
Predefined white color.
color.MAROON
Kind: constant
Value: maroon (#800000)
Predefined maroon color.
color.RED
Kind: constant
Value: red (#FF0000)
Predefined red color.
color.PURPLE
Kind: constant
Value: purple (#800080)
Predefined purple color.
color.FUCHSIA
Kind: constant
Value: fuchsia (#FF00FF)
Predefined fuchsia color.
color.MAGENTA
Kind: constant
Value: magenta (#FF00FF)
Predefined magenta color. Alias for FUCHSIA.
color.GREEN
Kind: constant
Value: green (#008000)
Predefined green color.
color.LIME
Kind: constant
Value: lime (#00FF00)
Predefined lime color.
color.OLIVE
Kind: constant
Value: olive (#808000)
Predefined olive color.
color.YELLOW
Kind: constant
Value: yellow (#FFFF00)
Predefined yellow color.
color.ORANGE
Kind: constant
Value: orange (#FFA500)
Predefined orange color.
color.NAVY
Kind: constant
Value: navy (#000080)
Predefined navy color.
color.BLUE
Kind: constant
Value: blue (#0000FF)
Predefined blue color.
color.TEAL
Kind: constant
Value: teal (#008080)
Predefined teal color.
color.AQUA
Kind: constant
Value: aqua (#00FFFF)
Predefined aqua color.
color.CYAN
Kind: constant
Value: cyan (#00FFFF)
Predefined cyan color. Alias for AQUA.
color.CRIMSON
Kind: constant
Value: crimson (#DC143C)
Predefined crimson color.
color.CORAL
Kind: constant
Value: coral (#FF7F50)
Predefined coral color.
color.GOLD
Kind: constant
Value: gold (#FFD700)
Predefined gold color.
color.DODGER_BLUE
Kind: constant
Value: dodgerblue (#1E90FF)
Predefined dodger blue color.
color.SKY_BLUE
Kind: constant
Value: skyblue (#87CEEB)
Predefined sky blue color.
color.VIOLET
Kind: constant
Value: violet (#EE82EE)
Predefined violet color.
color.PINK
Kind: constant
Value: pink (#FFC0CB)
Predefined pink color.