NexuScript 1.5
Colors
Named colours, custom colours, transparency and gradients.
"#22c55e".color.rgbA colour from its red, green and blue amounts, with an optional opacity.color.fadeMakes a colour more see-through by a percentage.color.alphaSets the opacity of a colour to an exact amount.color.greenThe named colour green, #22c55e.color.redThe named colour red, #ef4444.color.blueThe named colour blue, #3b82f6.color.orangeThe named colour orange, #ff9800.color.yellowThe named colour yellow, #eab308.color.purpleThe named colour purple, #7e57c2.color.tealThe named colour teal, #26a69a.color.grayThe named colour gray, #787b86.color.whiteThe named colour white, #ffffff.color.blackThe named colour black, #000000.color.noneNo colour at all, so nothing is drawn.color.mixBlends two colours together.color.gradientPicks a colour for a value on a scale between two colours.A colour from its hex code, such as "#22c55e".
Syntax
color.hex(text::String) -> ColorParameters
| Name | Type | Default | Description |
|---|---|---|---|
text | String | required | The 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
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) -> ColorParameters
| Name | Type | Default | Description |
|---|---|---|---|
r | Number | required | How much red, from 0 to 255. |
g | Number | required | How much green, from 0 to 255. |
b | Number | required | How much blue, from 0 to 255. |
a | Number | 1 | The 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
Makes a colour more see-through by a percentage.
Syntax
color.fade(c::Color, transparency::Number) -> ColorParameters
| Name | Type | Default | Description |
|---|---|---|---|
c | Color | required | The colour to fade. |
transparency | Number | required | How 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
Sets the opacity of a colour to an exact amount.
Syntax
color.alpha(c::Color, opacity::Number) -> ColorParameters
| Name | Type | Default | Description |
|---|---|---|---|
c | Color | required | The colour to change. |
opacity | Number | required | The 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
The named colour green, #22c55e.
Syntax
color.green::ColorDetails
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
The named colour red, #ef4444.
Syntax
color.red::ColorDetails
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
The named colour blue, #3b82f6.
Syntax
color.blue::ColorDetails
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
The named colour orange, #ff9800.
Syntax
color.orange::ColorDetails
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
The named colour yellow, #eab308.
Syntax
color.yellow::ColorDetails
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)
endSee also
The named colour purple, #7e57c2.
Syntax
color.purple::ColorDetails
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
The named colour teal, #26a69a.
Syntax
color.teal::ColorDetails
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
The named colour gray, #787b86.
Syntax
color.gray::ColorDetails
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
The named colour white, #ffffff.
Syntax
color.white::ColorDetails
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)
endSee also
The named colour black, #000000.
Syntax
color.black::ColorDetails
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
No colour at all, so nothing is drawn.
Syntax
color.none::ColorDetails
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
Blends two colours together.
Syntax
color.mix(a::Color, b::Color, amount::Number) -> ColorParameters
| Name | Type | Default | Description |
|---|---|---|---|
a | Color | required | The first colour, given when amount is 0. |
b | Color | required | The second colour, given when amount is 1. |
amount | Number | required | How 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
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) -> ColorParameters
| Name | Type | Default | Description |
|---|---|---|---|
value | Number | required | The number to colour, such as an RSI reading. |
low | Number | required | The bottom of the scale; a value here or below gets low_color. |
high | Number | required | The top of the scale; a value here or above gets high_color. |
low_color | Color | required | The colour at the bottom of the scale. |
high_color | Color | required | The 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)