Skip to content

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 float

The blue channel of a colour, from 0 to 255, or na for a na colour.

Parameter
color
const color

color.from_gradient ​

pine
color.from_gradient(value, bottom_value, top_value, bottom_color, top_color) → series color

The 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.

ParameterDescription
value
series int/float
Where to read the gradient.
bottom_value
series int/float
The value that gets bottom_color.
top_value
series int/float
The value that gets top_color.
bottom_color
series color
The colour at the bottom.
top_color
series color
The colour at the top.

color.g ​

pine
color.g(color) → series float

The green channel of a colour, from 0 to 255, or na for a na colour.

Parameter
color
const color

color.new ​

pine
color.new(color, transp) → series color

The 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.

ParameterDefaultDescription
color
const color
The colour to start from.
transp
series int/float
0AmenoScript onlyThe transparency, from 0 (opaque) to 100 (invisible).

color.r ​

pine
color.r(color) → series float

The red channel of a colour, from 0 to 255, or na for a na colour.

Parameter
color
const color

color.rgb ​

pine
color.rgb(red, green, blue, transp) → series color

A 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.

ParameterDefaultDescription
red
const int/float
The red channel, from 0 to 255.
green
const int/float
The green channel, from 0 to 255.
blue
const int/float
The blue channel, from 0 to 255.
transp
const int/float
0The transparency, from 0 (opaque) to 100 (invisible).

color.t ​

pine
color.t(color) → series float

The transparency of a colour, from 0 (opaque) to 100 (invisible), as a whole number.

Parameter
color
const color

color.* ​

The named colours, the same hex codes TradingView draws.

Each is a const color.

NameValue
color.aqua#00BCD4
color.black#363A45
color.blue#2962FF
color.fuchsia#E040FB
color.gray#787B86
color.green#4CAF50
color.lime#00E676
color.maroon#880E4F
color.navy#311B92
color.olive#808000
color.orange#FF9800
color.purple#9C27B0
color.red#F23645
color.silver#B2B5BE
color.teal#089981
color.white#FFFFFF
color.yellow#FDD835

AmenoScript is compatible with Pine Script v6. Pine Script is a trademark of TradingView, Inc., which has no part in AmenoScript.