Operators

This section documents the operator functions.


*

Multiplies two numerical values or expressions.

Syntax:

expr1 * expr2

Examples:

// Basic multiplication
$BTC.close * 1.05

// Multiply indicator values
ta.rsi($BTC, 14) * 2

// Complex expressions
($BTC.high + $BTC.low) * 0.5

// Using with historical data
$BTC.close[1] * ta.sma($BTC, 20)

Returns: Numerical value or series of values


/

Divides one numerical value by another.

Syntax:

Examples:

Returns: Numerical value or series of values


%

Returns the remainder after division (integer remainder).

Syntax:

Examples:

Returns: Numerical value or series of values

Note: The result has the same sign as the dividend (first operand).


+

Adds two numerical values or concatenates strings.

Syntax:

Examples:

Returns:

  • For numbers: Numerical value or series of values

  • For strings: Concatenated string


-

Subtracts one numerical value from another, or negates a value (unary).

Syntax:

Examples:

Returns: Numerical value or series of values


<

Tests if the left operand is less than the right operand.

Syntax:

Examples:

Returns: Boolean value (true or false)


<=

Tests if the left operand is less than or equal to the right operand.

Syntax:

Examples:

Returns: Boolean value (true or false)


==

Tests if two expressions are equal.

Syntax:

Examples:

Returns: Boolean value (true or false)


>

Tests if the left operand is greater than the right operand.

Syntax:

Examples:

Returns: Boolean value (true or false)


>=

Tests if the left operand is greater than or equal to the right operand.

Syntax:

Examples:

Returns: Boolean value (true or false)


and

Logical AND operation. Returns true only if both operands are true.

Syntax:

Examples:

Note: Also supports JavaScript syntax && for compatibility.

Returns: Boolean value (true or false)


or

Logical OR operation. Returns true if at least one operand is true.

Syntax:

Examples:

Note: Also supports JavaScript syntax || for compatibility.

Returns: Boolean value (true or false)


not

Logical NOT operation. Inverts the boolean value.

Syntax:

Examples:

Note: Also supports JavaScript syntax ! for compatibility.

Returns: Boolean value (true or false)


? :

Conditional (ternary) operator. Returns one of two values based on a condition.

Syntax:

Examples:

Returns: The value of either the second or third operand, depending on the condition


[]

Access historical values from price data and technical indicators using bracket notation.

Syntax:

Index Values:

  • [0] - Current value (latest)

  • [1] - Previous value (1 period ago)

  • [2] - 2 periods ago

  • [n] - n periods ago

  • [500] - 500 periods ago (max)

Examples:

Important Notes:

  • Historical access works with all price data (open, high, low, close, volume)

  • Historical access works with all technical indicators

  • Index [0] is optional - $BTC.close equals $BTC.close[0]

  • Maximum lookback limit is 500 - accessing beyond this throws an error

  • Use reasonable lookback periods (1-50) for most trading strategies

Last updated

Was this helpful?