Skip to content
Nexus Prop LLC

NexuScript 1.5

Operators

Arithmetic, comparison, logic and text. Operators bind from the loosest (? :) to the tightest (^, then calls and [ ]).

+

operatorNexuScript 1.0

Adds two numbers.

Syntax

a + b

Details

Also unary: +x is x.

Missing values

If either side is missing, the result is missing.

Example

plot("High plus low", high + low)

See also

-*

-

operatorNexuScript 1.0

Subtracts, or flips the sign of a number.

Syntax

a - b
-a

Details

-2^2 is -4: the power binds tighter.

Missing values

If either side is missing, the result is missing.

Example

plot("Bar change", close - open)

See also

+abs

*

operatorNexuScript 1.0

Multiplies two numbers, or joins two texts.

Syntax

a * b
text * text

Details

Text joins only with text: "Close " * string(close).

Missing values

A missing number gives missing.

Example

plot("Double range", (high - low) * 2)

See also

/string

/

operatorNexuScript 1.0

Divides two numbers.

Syntax

a / b

Details

Dividing by zero follows the usual floating-point rules: 1 / 0 is infinity and 0 / 0 is missing; test with isfinite.

Missing values

A missing side gives missing.

Example

plot("Close to open", close / open)

See also

*modisfinite

%

operatorNexuScript 1.0

The remainder of a division, with the sign of the left side.

Syntax

a % b

Details

-7 % 3 is -1. Use mod for the remainder that follows the divisor's sign.

Missing values

A missing side gives missing.

Example

plot("Bar in group of 5", bar.index % 5)

See also

mod/

^

operatorNexuScript 1.0

Raises a number to a power.

Syntax

a ^ b

Details

Binds from the right: 2^3^2 is 2^9. Computed by NexuScript itself, so it gives the same last digit everywhere.

Missing values

A missing side gives missing.

Example

plot("Squared change", (close - close[1]) ^ 2)

See also

sqrtexp

==

operatorNexuScript 1.0

True when two values of the same type are equal.

Syntax

a == b

Details

Colours compare by their channels, enums by member. Comparisons chain: 0 < x <= 10 means 0 < x && x <= 10.

Missing values

Any comparison with missing is false. Writing x == missing is an error: use ismissing(x).

Example

if bar.index == 0
    marker("First")
end

See also

!=ismissing

!=

operatorNexuScript 1.0

True when two values of the same type differ.

Syntax

a != b

Details

The opposite of ==.

Missing values

With missing on either side the result is true.

Example

if close != open
    background(color.fade(color.blue, 95))
end

See also

==

<

operatorNexuScript 1.0

True when the left number is smaller.

Syntax

a < b

Details

Chains with other comparisons: low < x < high.

Missing values

False when either side is missing.

Example

if close < open
    candle_color(color.red)
end

See also

<=>>=

<=

operatorNexuScript 1.0

True when the left number is smaller or equal.

Syntax

a <= b

Details

Chains with other comparisons.

Missing values

False when either side is missing.

Example

if close <= low[1]
    marker("Low", position = "below")
end

See also

<>=

>

operatorNexuScript 1.0

True when the left number is larger.

Syntax

a > b

Details

Chains with other comparisons.

Missing values

False when either side is missing.

Example

if close > open
    candle_color(color.green)
end

See also

>=<

>=

operatorNexuScript 1.0

True when the left number is larger or equal.

Syntax

a >= b

Details

Chains with other comparisons.

Missing values

False when either side is missing.

Example

if close >= high[1]
    marker("High")
end

See also

><=

&&

operatorNexuScript 1.0

True when both sides are true.

Syntax

a && b

Details

The right side is only worked out when the left is true. A ta call on the right side is allowed only when the left side is fixed.

Missing values

Both sides are Bool, which is never missing.

Example

if close > open && volume > volume[1]
    marker("Strong")
end

See also

||!

||

operatorNexuScript 1.0

True when either side is true.

Syntax

a || b

Details

The right side is only worked out when the left is false.

Missing values

Both sides are Bool, which is never missing.

Example

if high > high[1] || low < low[1]
    marker("Wide")
end

See also

&&!

!

operatorNexuScript 1.0

Turns true into false and false into true.

Syntax

!a

Details

Works on Bool only.

Missing values

Bool is never missing.

Example

if !bar.confirmed
    background(color.fade(color.yellow, 90))
end

See also

&&||

? :

operatorNexuScript 1.0

Picks one of two values by a condition.

Syntax

condition ? a : b

Details

a and b must have the same type. Binds loosest of all and groups from the right, so a ? b : c ? d : e reads naturally.

Missing values

Only the chosen side is worked out; a missing value is passed through.

Example

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

See also

if

[ ]

operatorNexuScript 1.0

Reads a value from n bars ago, or an item of an array.

Syntax

series[n]
array[i]

Details

On bar values, source inputs, state variables and let/const values written directly in on bar (or a higher block), x[n] is the value n bars ago; x[0] is now. n is a whole number from 0 to 20,000 and may change per bar. On an array, a[i] is item i, counting from 1.

Missing values

Before the first bar a history read gives missing (false for Bool, color.none for colours).

Example

let change = close - close[1]
let fast = ta.ema(close, 9)
plot("Change", change)
plot("Fast was rising", fast[1] > fast[2] ? 1 : 0)

See also

letstateArray

$( )

operatorNexuScript 1.0

Puts values inside text.

Syntax

"text $name text $(expression)"

Details

$name and $(expression) are replaced by string(value). Numbers are written in their shortest exact form; write \$ for a dollar sign.

Missing values

A missing number is written missing.

Example

marker("Close $(round(close, digits = 2))")

See also

string*

.

operatorNexuScript 1.0

Reads a name from a namespace such as ta or color, or a named part of a tuple.

Syntax

namespace.name
tuple.part

Details

Namespaces: ta, color, symbol, timeframe, session, period, bar, and in strategies order, position, account.

Missing values

A part of a tuple may be missing like any number.

Example

let (basis, upper, lower) = ta.bands(close, 20)
let daily = higher("D") do
    (high = high, low = low)
end
plot("Yesterday high", daily.high)

See also

tuplehigher