Returns a color with the same red, green and blue as the one you pass but a new transparency.
color.new(color, transp) keeps the hue and sets how see-through it is. Transparency runs from 0, fully solid, to 100, fully invisible.
It is the usual way to soften a built-in color for fills and backgrounds: color.new(color.blue, 85) is a faint blue wash. The new transparency replaces the old one rather than adding to it.
Syntax
color.new(color: const color, transp: const int/float) -> const color
color.new(color: series color, transp: series int/float) -> series color
color.new(color: input color, transp: input int/float) -> input color
color.new(color: simple color, transp: simple int/float) -> simple colorArguments
| Name | Type | Default | Description |
|---|---|---|---|
| color | const/ | required | The color to start from, such as color.red or a color.rgb result. |
| transp | const/ | required | New transparency from 0 (solid) to 100 (invisible). Values outside the range are clamped. |
Returns
const/input/simple/series color: the color with the new transparency; na if the color is na.
Remarks
- Plot and fill colors accept the result directly.
- Colors of series type are allowed, so the transparency can change on every bar.
Example
//@version=6
indicator("Soft background", overlay = true)
fast = ta.ema(close, 10)
slow = ta.ema(close, 30)
bgcolor(fast > slow ? color.new(color.green, 88) : color.new(color.red, 88))
plot(fast, "Fast", color = color.green)
plot(slow, "Slow", color = color.red)See also
Runs on Sidechair