Skip to content
Nexus Prop LLC

NexuScript 1.5

Types and literals

Every value has one of these types. There are no hidden conversions.

Number

typeNexuScript 1.0

A 64-bit floating-point number; whole numbers are numbers too.

Syntax

Number
14   1_000   2.5   1e-3

Details

Underscores may separate digits. A number written with a . or an exponent is a decimal literal, which makes an input a number-with-decimals setting.

Missing values

missing is the number that is not there.

Example

let x::Number = 1_000
plot("x", x)

See also

missingIntFloat

Bool

typeNexuScript 1.0

Either true or false.

Syntax

Bool

Details

Conditions must be Bool; there are no truthy numbers.

Missing values

A Bool is never missing; a history read before the first bar gives false.

Example

let up::Bool = close > open
if up
    candle_color(color.green)
end

See also

truefalseif

String

typeNexuScript 1.0

Text, written in double quotes.

Syntax

String
"text"

Details

Escapes: \\, \", \n, \t, \r, \$, \u{hex}. Text cannot span lines. Join with *, put values inside with $( ).

Missing values

Text is never missing; it may be empty ("").

Example

let name::String = "Close: " * string(close)
marker(name)

See also

string*$( )

Color

typeNexuScript 1.0

A colour with its transparency, or no colour.

Syntax

Color

Details

Written with the named colours (color.blue), color.hex("#22c55e") or color.rgb(34, 197, 94).

Missing values

color.none means no colour; a colour is never missing.

Example

let c::Color = close > open ? color.green : color.red
plot("Close", close, color = c)

See also

color.hexcolor.rgbcolor.none

Array

typeNexuScript 1.0

An ordered list of values of one type, counted from 1.

Syntax

Array{T}
[1.0, 2.0, 3.0]
state recent::Array{Number} = []

Details

Arrays are values: assigning one copies it. At most 100,000 items. An index outside the array is an error.

Missing values

Items may be missing; use coalesce when adding them up.

Errors

  • NS402an index outside the array
  • NS403taking from an empty array

Example

state recent::Array{Number} = []
on bar
    push!(recent, close)
    if length(recent) > 10
        popfirst!(recent)
    end
    plot("Average of last 10", sum(recent) / length(recent))
end

See also

push!length[ ]for

tuple

typeNexuScript 1.0

A fixed group of values, plain (a, b) or named (fast = f, slow = s).

Syntax

(a, b)
(name = a, other = b)

Details

Read a part by name with t.name, or all parts in order with let (a, b) = t. Tuples cannot be changed. Functions such as ta.macd and ta.bands give named tuples.

Missing values

Each part may be missing like any value of its type.

Example

let pair = (fast = ta.ema(close, 9), slow = ta.ema(close, 21))
plot("Gap", pair.fast - pair.slow)

See also

let.ta.macd

missing

valueNexuScript 1.0

The number that is not there: a gap, or a value not worked out yet.

Syntax

missing

Details

Arithmetic with missing gives missing; <, <=, >, >=, == with it are false and != is true. Plotting it leaves a gap. Test with ismissing, fill with coalesce.

Missing values

This is the value itself.

Errors

  • NS212x == missing; use ismissing(x)

Example

state saved = missing
on bar
    if bar.index == 10
        saved = close
    end
    plot("Saved close", saved)
end

See also

ismissingcoalesceNumber

true

valueNexuScript 1.0

The Bool value for yes.

Syntax

true

Missing values

Never missing.

Example

input show = true, title = "Show average"
on bar
    let avg = ta.sma(close, 20)
    plot("Average", show ? avg : missing)
end

See also

falseBool

false

valueNexuScript 1.0

The Bool value for no.

Syntax

false

Missing values

Never missing.

Example

input fill_on = false, title = "Shade"
on bar
    if fill_on
        background(color.fade(color.blue, 90))
    end
end

See also

trueBool

Int

typeNexuScript 1.0

Makes an input a whole-number setting, whatever the default is written like.

Syntax

input name = Int(x), ...

Details

A saved value is kept inside min and max and rounded half to even.

Missing values

An input always has a value.

Example

input length = Int(20), title = "Length", min = 1
on bar
    plot("Average", ta.sma(close, length))
end

See also

Floatinput

Float

typeNexuScript 1.0

Makes an input a number-with-decimals setting.

Syntax

input name = Float(x), ...

Details

Same as writing the default with a decimal point (2.0).

Missing values

An input always has a value.

Example

input mult = Float(2), title = "Multiplier", step = 0.1
on bar
    let (basis, upper, lower) = ta.bands(close, 20, mult)
    plot("Upper", upper)
end

See also

Intinput

Symbol

typeNexuScript 1.0

Makes an input a symbol setting; empty text means the chart's own symbol.

Syntax

input name = Symbol("ES"), ...

Details

The value is text in capitals. Use it with higher(...; symbol = name). The chart loads another symbol only when your chart could show it.

Missing values

An input always has a value; "" means the chart's symbol.

Example

input other = Symbol(""), title = "Compare with"
on bar
    let c = higher("D", symbol = other) do
        close
    end
    plot("Daily close", c)
end

See also

Timeframehigherinput

Timeframe

typeNexuScript 1.0

Makes an input a timeframe dropdown.

Syntax

input name = Timeframe("D"), ...

Details

The value is text such as "60" or "D".

Missing values

An input always has a value.

Example

input htf = Timeframe("D"), title = "Higher timeframe"
on bar
    let c = higher(htf) do
        close
    end
    plot("Higher close", c)
end

See also

Symbolhighertimeframe.name

struct

declarationNexuScript 1.5

Declares a record type: a named group of typed fields, built with the type's name like a function.

Syntax

struct Name
    field::Type
    field::Type = default
end

let r = Name(value, field = value)

Details

A struct is a named tuple with a type name: Name(...) builds one (values by position in field order, then by name; a field with a default may be left out), r.field reads a field, and the name is a type for let, state, parameters, return types and arrays (state swings::Array{Swing} = []). A struct is a value: assigning it copies it, and a field cannot be assigned (build a new one instead). A state may hold a struct whose fields are numbers, text, Bools, colours or enum values, and arrays of those. The name starts with a capital letter.

Errors

  • NS201two fields or two types with the same name
  • NS211a field is missing, given twice, or not in the struct
  • NS210a value has another type than its field
  • NS220a field of a struct is assigned
  • NS232the header names a version before 1.5

Example

nexscript 1.5

indicator "Last swing high", overlay = true

struct Swing
    price::Number
    bar::Number = -1
end

state last = Swing(price = missing)

on bar
    let ph = ta.pivot_high(high, 2, 2)
    if !ismissing(ph)
        last = Swing(ph, bar.index - 2)
    end
    plot("Last swing high", last.price, style = "step")
end

See also

tupleenumstateArray