Skip to content

color namespace

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.

  • 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) → Blend color1 and color2 using 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.
//@version=5
indicator("Color namespace example", overlay=true)
baseColor = color.rgb(30, 144, 255) // Dodger blue
fadeColor = 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)