Colors and gradients
Build readable palettes, transparency, conditional colors, and value-driven scales.
Color carries meaning. Use it to distinguish direction, show intensity, and separate primary information from context—not merely to decorate a chart.
Choose a color
Scripting v3 includes named colors:
color.green
color.red
color.orange
color.blue
color.grayUse a hex literal for an exact value:
setup brandBlue = #466BE5
setup translucentBlue = #466BE560Hex colors use #RRGGBB or #RRGGBBAA. The last two digits are alpha.
You can also construct a color from numeric channels:
setup teal = color.rgb(20, 184, 166)
setup softTeal = color.rgb(20, 184, 166, 72)Red, green, blue, and alpha channels all use values from 0 to 255. Alpha 0 is invisible; 255 is fully opaque.
Let users choose
Expose important palette choices as inputs:
input (
bullishColor = input.color(color.green, title: "Bullish")
bearishColor = input.color(color.red, title: "Bearish", sameLine: true)
)Keep structural colors—subtle grid fills or neutral context—inside the script unless changing them is genuinely useful.
Color individual values
A plot declaration sets the default. A plot call can choose a color for the current value:
plot momentum = plot.histogram(title: "Momentum", color: color.gray)
on chart.update {
let value = ta.roc(chart.close, 10)
let shade = (value ?? 0.0) >= 0.0 ? bullishColor : bearishColor
momentum.plot(value, color: shade)
}This works well for discrete states such as bullish/bearish, above/below, or active/inactive.
Add transparency
Use color.withAlpha when the same base color needs different visual weight:
on chart.update {
let lineColor = bullishColor
let fillColor = color.withAlpha(bullishColor, 32)
}Opaque colors suit primary lines and labels. Lower alpha works better for fills and chart backgrounds because it preserves the candles beneath them.
Use a continuous gradient
color.gradient blends between two colors from a numeric value:
on chart.update {
let score = math.clamp(ta.roc(chart.close, 10) ?? 0.0, -5.0, 5.0)
let shade = color.gradient(score, -5.0, 5.0, color.red, color.green)
momentum.plot(score, color: shade)
}Values below the range use the first color; values above it use the last. Choose bounds that have a clear meaning, such as a normalized score or known threshold.
Build a multi-stop scale
For more than two states, define a reusable scale during setup:
setup pressureScale = color.scale(
at: [-2.0, 0.0, 2.0],
colors: [color.red, color.gray, color.green],
easing: easing.smoothstep,
)
on chart.update {
let pressure = ta.roc(chart.close, 10) ?? 0.0
momentum.plot(pressure, color: pressureScale.sample(pressure))
}A scale is a good fit for heatmaps, strength scores, relative volume, and order-flow intensity. Keep stops ordered and make the neutral point visually obvious.
Design for readability
- Use the same color for the same meaning throughout one script.
- Reserve vivid colors for actionable or unusual states.
- Use alpha instead of a second unrelated color for secondary context.
- Avoid red/green as the only distinction when a marker shape or sign can reinforce it.
- Check the result on both dense and quiet sections of market data.
See the color reference for every named color and color operation.