TradingCharts

Colors

Colors are 24-bit RGB values, optionally with an 8-bit alpha channel.

Literals

color opaqueRed   = #FF5252
color halfRed     = #80FF5252       // 50% opaque red (alpha first)

Named constants

The following names are available under color.*. The hex values are stable across runs:

Name Hex
red #FF5252
green #4CAF50
blue #2196F3
orange #FF9800
yellow #FFEB3B
teal #00897B
aqua #00BCD4
lime #00E676
purple #9C27B0
maroon #880E4F
navy #311B92
gray #787B86
silver #B2B5BE
white #FFFFFF
black #363A45

Bare legacy names (aqua, silver, red, …) also resolve, so scripts written in older style compile without changes.

color.new(color, transparency)

Produce a translucent version of a colour:

tint = color.new(color.aqua, 85)   // 85% transparent

Transparency is a 0–100 integer where 0 is opaque and 100 is fully invisible.

color.rgb(r, g, b, transparency = 0)

Build a colour from numeric channel values:

custom = color.rgb(255, 180, 40, 0)

Each channel is 0–255; transparency 0–100.

Gradients

score = ta.rsi(close, 14)
tint  = color.from_gradient(score, 30, 70, color.red, color.lime)
plot(close, color=tint)
  • color.from_gradient(x, low, high, cLow, cHigh) returns cLow when x <= low, cHigh when x >= high, and a linearly interpolated colour between.
  • When your anchors must bracket, prefer math.max(low, math.min(x, high)) to clamp before calling.

Theme-aware colours

Two theme-driven sentinels are available:

  • chart.fg_color — the chart's foreground text colour (adapts to light/dark theme at render time).
  • chart.bg_color — the chart's background colour.
hline(0, "Zero", color=color.new(chart.fg_color, 75), linestyle=hline.style_solid)

Both can be used as a const-colour argument; the host substitutes the real theme colour just before rendering.

Channel accessors

Call Returns
color.r(c) red channel 0–255
color.g(c) green
color.b(c) blue
color.t(c) transparency 0–100

Palettes

A plot can declare a palette whose entries are coloured independently from the Style tab:

// Four-state regime
regime = switch
    close > ta.ema(close, 50)  and close > ta.ema(close, 200) => 3
    close > ta.ema(close, 200)                                => 2
    close < ta.ema(close, 50)  and close < ta.ema(close, 200) => 0
    => 1

palette = switch regime
    0 => color.red
    1 => color.orange
    2 => color.aqua
    3 => color.lime
    => color.gray

plot(close, "Regime close", color=palette, linewidth=2)

When all branches of a ternary / switch produce color.<name> values, the dialog shows a swatch per branch using the variable's name as the swatch title.

See also

  • Plots — color= and dynamic colouring
  • Fills — gradient fills between plots
  • Backgrounds — tinting a bar's background