'How to address a color transparency/opacity without touching the color itself? V5
For example I have these color variables:
Color1 = #334455FF
Color2 = #33445588
The only difference is the opacity/transparency component. Can we address this component only, without touching the RGB comps.? For example (improvised obvious syntax concept):
Color1 = #334455FF
Color2 = @Color1, opacity=50
I think there was some similar function in V4 … (I just wasn't here in that era.)
Solution 1:[1]
transp = input.int(0, minval=0,maxval=100)
colbase = input.color(color.yellow)
var color _col = na
_col := color.new(colbase, transp)
plot(close,'close',_col,3)
Solution 2:[2]
I believe you are looking for the color.t() function.
Retrieves the color's transparency.
//@version=5
indicator("color.t", overlay=true)
plot(color.t(color.new(color.red, 50)))
Edit:
You can use the color.r(), color.g(), color.b() functions to get the r, g, b components of a color. Then use the color.rgb() function to create a new color.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © vitruvius
//@version=5
indicator("My script")
color1 = color.new(#c9ff73, 0)
color_r = color.r(color1)
color_g = color.g(color1)
color_b = color.b(color1)
color2 = color.rgb(color_r, color_g, color_b, 25)
color3 = color.rgb(color_r, color_g, color_b, 50)
color4 = color.rgb(color_r, color_g, color_b, 75)
plot(0, "1", color1, linewidth=5)
plot(5, "2", color2, linewidth=5)
plot(10, "3", color3, linewidth=5)
plot(15, "4", color4, linewidth=5)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Kai Gouthro |
| Solution 2 |

