Appearance
color
How do you colour a plot by its value? Blend two colours with color.from_gradient, or pick one with a condition and fade it with color.new. A colour is a value like any other, so it can change on every bar.
pine
//@version=6
indicator("RSI, coloured by its level")
r = ta.rsi(close, 14)
// 30 and below is red, 70 and above green, and the levels between blend
plot(r, "RSI", color.from_gradient(r, 30, 70, color.red, color.green), 2)
hline(50, "Middle", color.new(color.gray, 50))Transparency runs from 0, opaque, to 100, invisible, as on TradingView. A colour stores it as an alpha byte, round((1 - transp / 100) * 255), so color.t reads back a whole number.
color.b
pine
color.b(color) → series floatThe blue channel of a colour, from 0 to 255, or na for a na colour.
| Parameter |
|---|
colorconst color |
color.from_gradient
pine
color.from_gradient(value, bottom_value, top_value, bottom_color, top_color) → series colorThe colour at value's place between bottom_value and top_value, blended from bottom_color to top_color.
Past either end it is that end's colour. The blend mixes the ends weighted by their own transparency, so a transparent end fades the other out rather than tinting it.
A gradient with no position is a colour, not na
Where value is na, or value, bottom_value and top_value are all equal, the result is colour 0: black at transparency 100, which na() reads as false and color.r, g, b and t read as 0, 0, 0 and 100. A na bottom_value or top_value gives na.
| Parameter | Description |
|---|---|
valueseries int/float | Where to read the gradient. |
bottom_valueseries int/float | The value that gets bottom_color. |
top_valueseries int/float | The value that gets top_color. |
bottom_colorseries color | The colour at the bottom. |
top_colorseries color | The colour at the top. |
color.g
pine
color.g(color) → series floatThe green channel of a colour, from 0 to 255, or na for a na colour.
| Parameter |
|---|
colorconst color |
color.new
pine
color.new(color, transp) → series colorThe colour with its transparency set to transp, whatever it had before.
A na colour starts from black, so color.new(na, 80) is black at transparency 80. A transp of na makes it fully transparent.
| Parameter | Default | Description |
|---|---|---|
colorconst color | The colour to start from. | |
transpseries int/float | 0AmenoScript only | The transparency, from 0 (opaque) to 100 (invisible). |
color.r
pine
color.r(color) → series floatThe red channel of a colour, from 0 to 255, or na for a na colour.
| Parameter |
|---|
colorconst color |
color.rgb
pine
color.rgb(red, green, blue, transp) → series colorA colour from its red, green and blue channels and a transparency.
Each channel is held between 0 and 255 and cut to a whole number, so 2.5 is 2.
| Parameter | Default | Description |
|---|---|---|
redconst int/float | The red channel, from 0 to 255. | |
greenconst int/float | The green channel, from 0 to 255. | |
blueconst int/float | The blue channel, from 0 to 255. | |
transpconst int/float | 0 | The transparency, from 0 (opaque) to 100 (invisible). |
color.t
pine
color.t(color) → series floatThe transparency of a colour, from 0 (opaque) to 100 (invisible), as a whole number.
| Parameter |
|---|
colorconst color |
color.*
The named colours, the same hex codes TradingView draws.
Each is a const color.
| Name | Value |
|---|---|
color. | #00BCD4 |
color. | #363A45 |
color. | #2962FF |
color. | #E040FB |
color. | #787B86 |
color. | #4CAF50 |
color. | #00E676 |
color. | #880E4F |
color. | #311B92 |
color. | #808000 |
color. | #FF9800 |
color. | #9C27B0 |
color. | #F23645 |
color. | #B2B5BE |
color. | #089981 |
color. | #FFFFFF |
color. | #FDD835 |