color. You write one as a constant, a hex literal or a call, and every drawing and plot takes one.
Constants and hex
The constants arecolor.aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, orange, purple,
red, silver, teal, white and yellow. A plot without a color is #483D8B.
A hex literal is #RRGGBB or #RRGGBBAA, where the last pair is the alpha: FF is solid, 00 invisible. #F00 (three digits) is
not a color:
#FF0000.
Opacity
color.new(color, alpha) returns the color with a new opacity. alpha runs from 0 to 1, and 1 is solid. There is no
transp argument and no 0 to 100 scale. A value outside 0..1 is clamped when the script runs; a literal or const one also gives a
warning when you check the script, for example color.new(color.red, 80): opacity 80 is outside 0–1; 1 is solid.
color.rgb(r, g, b, a) builds a color from integers 0 to 255 for r, g, b and, optionally, an opacity a from 0 to 1
(default solid). A literal component outside 0..255 warns: component r value 300 is outside 0–255.
Colors that change by bar
A color argument that isseries may differ on every bar, so a condition decides the color:
na as a color means no color. The opacity of color.new may itself be a series.
Gradients
color.from_gradient(value, bottom_value, top_value, bottom_color, top_color) blends the two colors by where value lies between
the two bounds (clamped to them). It returns na when the bounds are equal. All five arguments are required.
Reading a color
color.r(c), color.g(c) and color.b(c) return 0 to 255; color.a(c) returns the opacity from 0 to 1.
Matching the chart’s theme
chart.bg_color is the chart’s background and chart.fg_color a color that contrasts with it, so text and lines stay readable on a light or a dark chart. Both are input colors: use them where a fixed value is required, such as plot(color=...).