color namespace
Overview
Section titled “Overview”Use the color namespace to construct and manipulate colors in Pine Script. You can build colors from RGB or HSL components, adjust transparency, blend gradients, or extract per-channel values.
Common helpers
Section titled “Common helpers”color.rgb(r, g, b, transp)→ Build a color from 0–255 RGB values and optional transparency.color.new(color, transp)→ Clone a color with a new transparency level (0 = opaque, 100 = invisible).color.from_gradient(position, color1, color2)→ Blendcolor1andcolor2using a 0–1 position value.color.from_hsb(hue, sat, bright, transp)→ Create colors from hue/saturation/brightness.color.to_int(color)/color.from_int(value)→ Convert between color objects and integer representation.color.r/g/b/a(color)→ Extract individual channels.
Example
Section titled “Example”//@version=5indicator("Color namespace example", overlay=true)
baseColor = color.rgb(30, 144, 255) // Dodger bluefadeColor = color.new(baseColor, 70)
gradient = color.from_gradient(math.max(close - open, 0) / math.max(high - low, 0.0001), color.red, color.green)
plot(close, "Close", color=gradient, linewidth=2)bgcolor(fadeColor)