Skip to content
Nexus Prop LLC

NexuScript 1.5

Colors

Named colours, custom colours, transparency and gradients.

color.hex

functionNexuScript 1.0

A colour from its hex code, such as "#22c55e".

Syntax

color.hex(text::String) -> Color

Parameters

NameTypeDefaultDescription
textStringrequiredThe hex code: "#rgb", "#rrggbb" or "#rrggbbaa", where the last two digits of the long form are the opacity.

Returns

Color The colour. Without opacity digits it is fully opaque.

Details

Capital and small letters both work, and spaces around the code are ignored. When you write the code straight into the call, a wrong code is caught before the script runs.

Missing values

Text is never missing. Text that is not a colour code stops the script with NS404.

Errors

  • NS404the text is not "#rgb", "#rrggbb" or "#rrggbbaa"

Example

plot("Close", close, color = color.hex("#d9a441"))

See also

color.rgbColorinput

color.rgb

functionNexuScript 1.0

A colour from its red, green and blue amounts, with an optional opacity.

Syntax

color.rgb(r::Number, g::Number, b::Number, a::Number = 1) -> Color

Parameters

NameTypeDefaultDescription
rNumberrequiredHow much red, from 0 to 255.
gNumberrequiredHow much green, from 0 to 255.
bNumberrequiredHow much blue, from 0 to 255.
aNumber1The opacity, from 0 (invisible) to 1 (solid).

Returns

Color The colour.

Details

Amounts outside 0 to 255 are held at the nearest end, and fractions round to the nearest whole number (halves away from zero). An opacity outside 0 to 1 is held the same way. Because every part can change from bar to bar, it is handy for colours that follow a value.

Missing values

A missing red, green or blue amount counts as 0. A missing opacity makes the colour invisible.

Example

let strength = clamp(ta.rsi(close, 14), 0, 100)
background(color.rgb(255 - strength * 2.55, strength * 2.55, 0, 0.15))

See also

color.hexcolor.alphaclamp

color.fade

functionNexuScript 1.0

Makes a colour more see-through by a percentage.

Syntax

color.fade(c::Color, transparency::Number) -> Color

Parameters

NameTypeDefaultDescription
cColorrequiredThe colour to fade.
transparencyNumberrequiredHow much to fade it, from 0 (keep it as it is) to 100 (invisible).

Returns

Color The same colour, more transparent.

Details

It multiplies the opacity the colour already has, so fading an already faded colour fades it further. Values outside 0 to 100 are held at the nearest end. To set an exact opacity instead, use color.alpha.

Missing values

A missing transparency counts as 0, so the colour is kept. Fading color.none gives color.none.

Example

background(close > open ? color.fade(color.green, 85) : color.fade(color.red, 85))

See also

color.alphacolor.nonebackground

color.alpha

functionNexuScript 1.0

Sets the opacity of a colour to an exact amount.

Syntax

color.alpha(c::Color, opacity::Number) -> Color

Parameters

NameTypeDefaultDescription
cColorrequiredThe colour to change.
opacityNumberrequiredThe new opacity, from 0 (invisible) to 1 (solid).

Returns

Color The same colour with the new opacity. Any opacity it had before is replaced.

Details

Values outside 0 to 1 are held at the nearest end. The built-in shaded areas use it, for example color.alpha(c, 0.12).

Missing values

A missing opacity keeps the colour as it is. color.none stays color.none.

Example

background(color.alpha(color.blue, 0.15))

See also

color.fadecolor.rgbband

color.green

valueNexuScript 1.0

The named colour green, #22c55e.

Syntax

color.green::Color

Details

Fully opaque. Use color.fade(color.green, 80) or color.alpha(color.green, 0.2) for a see-through version.

Missing values

A colour is never missing; color.none is "no colour".

Example

plot("Close", close, color = color.green)

See also

color.redcolor.tealcolor.hex

color.red

valueNexuScript 1.0

The named colour red, #ef4444.

Syntax

color.red::Color

Details

Fully opaque. Use color.fade(color.red, 80) or color.alpha(color.red, 0.2) for a see-through version.

Missing values

A colour is never missing; color.none is "no colour".

Example

plot("Close", close, color = close < open ? color.red : color.green)

See also

color.greencolor.orangecolor.hex

color.blue

valueNexuScript 1.0

The named colour blue, #3b82f6.

Syntax

color.blue::Color

Details

Fully opaque. Use color.fade(color.blue, 80) or color.alpha(color.blue, 0.2) for a see-through version.

Missing values

A colour is never missing; color.none is "no colour".

Example

plot("Average", ta.sma(close, 20), color = color.blue)

See also

color.tealcolor.purplecolor.hex

color.orange

valueNexuScript 1.0

The named colour orange, #ff9800.

Syntax

color.orange::Color

Details

Fully opaque. Use color.fade(color.orange, 80) or color.alpha(color.orange, 0.2) for a see-through version.

Missing values

A colour is never missing; color.none is "no colour".

Example

plot("Fast average", ta.ema(close, 9), color = color.orange)

See also

color.yellowcolor.redcolor.hex

color.yellow

valueNexuScript 1.0

The named colour yellow, #eab308.

Syntax

color.yellow::Color

Details

Fully opaque. Use color.fade(color.yellow, 80) or color.alpha(color.yellow, 0.2) for a see-through version.

Missing values

A colour is never missing; color.none is "no colour".

Example

if ta.crossover(close, ta.sma(close, 20))
    marker("Cross", color = color.yellow)
end

See also

color.orangecolor.greencolor.hex

color.purple

valueNexuScript 1.0

The named colour purple, #7e57c2.

Syntax

color.purple::Color

Details

Fully opaque. Use color.fade(color.purple, 80) or color.alpha(color.purple, 0.2) for a see-through version.

Missing values

A colour is never missing; color.none is "no colour".

Example

plot("Slow average", ta.sma(close, 50), color = color.purple)

See also

color.bluecolor.tealcolor.hex

color.teal

valueNexuScript 1.0

The named colour teal, #26a69a.

Syntax

color.teal::Color

Details

Fully opaque. Use color.fade(color.teal, 80) or color.alpha(color.teal, 0.2) for a see-through version.

Missing values

A colour is never missing; color.none is "no colour".

Example

plot("Mid", hl2, color = color.teal)

See also

color.greencolor.bluecolor.hex

color.gray

valueNexuScript 1.0

The named colour gray, #787b86.

Syntax

color.gray::Color

Details

Fully opaque. Use color.fade(color.gray, 80) or color.alpha(color.gray, 0.2) for a see-through version.

Missing values

A colour is never missing; color.none is "no colour".

Example

plot("Open", open, color = color.gray)

See also

color.whitecolor.blackcolor.hex

color.white

valueNexuScript 1.0

The named colour white, #ffffff.

Syntax

color.white::Color

Details

Fully opaque. Use color.fade(color.white, 80) or color.alpha(color.white, 0.2) for a see-through version.

Missing values

A colour is never missing; color.none is "no colour".

Example

if bar.last
    marker("Last", color = color.white)
end

See also

color.blackcolor.graycolor.hex

color.black

valueNexuScript 1.0

The named colour black, #000000.

Syntax

color.black::Color

Details

Fully opaque. Use color.fade(color.black, 80) or color.alpha(color.black, 0.2) for a see-through version.

Missing values

A colour is never missing; color.none is "no colour".

Example

background(color.fade(color.black, 90))

See also

color.whitecolor.graycolor.hex

color.none

valueNexuScript 1.0

No colour at all, so nothing is drawn.

Syntax

color.none::Color

Details

It has no hex value; string(color.none) writes none. Use it to draw only on some bars, for example a background that shows only on up bars. When a plot is given color.none on one bar, that bar falls back to the plot's own colour. Fading it or changing its opacity keeps it color.none.

Missing values

A colour is never missing; color.none is "no colour". A colour variable that has not been set yet, or a colour from before the first bar, is color.none.

Example

background(close > open ? color.fade(color.green, 90) : color.none)

See also

backgroundcolor.fadeColor

color.mix

functionNexuScript 1.3

Blends two colours together.

Syntax

color.mix(a::Color, b::Color, amount::Number) -> Color

Parameters

NameTypeDefaultDescription
aColorrequiredThe first colour, given when amount is 0.
bColorrequiredThe second colour, given when amount is 1.
amountNumberrequiredHow far to go from a towards b, from 0 to 1. 0.5 is halfway. Values outside are kept between 0 and 1.

Returns

Color The blended colour. Red, green, blue and opacity are each blended and rounded to whole steps.

Details

color.none blends as its partner made invisible, so color.mix(color.none, color.red, 0.5) is red at half opacity. Two color.none give color.none.

Missing values

A missing amount gives a unchanged.

Example

plot("Close", close, color = color.mix(color.red, color.green, close > open ? 0.8 : 0.2))

See also

color.gradientcolor.fadecolor.none

color.gradient

functionNexuScript 1.3

Picks a colour for a value on a scale between two colours.

Syntax

color.gradient(value::Number, low::Number, high::Number, low_color::Color, high_color::Color) -> Color

Parameters

NameTypeDefaultDescription
valueNumberrequiredThe number to colour, such as an RSI reading.
lowNumberrequiredThe bottom of the scale; a value here or below gets low_color.
highNumberrequiredThe top of the scale; a value here or above gets high_color.
low_colorColorrequiredThe colour at the bottom of the scale.
high_colorColorrequiredThe colour at the top of the scale.

Returns

Color The colour for value, blended between the two colours by where it sits on the scale (it works like color.mix). Outside the range it takes the end colour.

Missing values

A missing value, low or high gives color.none, so nothing is drawn on that bar.

Example

let rsi = ta.rsi(close, 14)
plot("RSI", rsi, color = color.gradient(rsi, 30, 70, color.red, color.green), width = 2)

See also

color.mixshadecolor.none