Operators
This section documents the operator functions.
*
Multiplies two numerical values or expressions.
Syntax:
expr1 * expr2Examples:
// 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:
expr1 / expr2Examples:
// Price ratio
$BTC.close / $BTC.open
// Indicator normalization
ta.rsi($BTC, 14) / 100
// Average calculation
($BTC.high + $BTC.low + $BTC.close) / 3
// Volume analysis
$BTC.volume / ta.sma($BTC.volume, 20)Returns: Numerical value or series of values
%
Returns the remainder after division (integer remainder).
Syntax:
expr1 % expr2Examples:
// Check if volume is even/odd
$BTC.volume % 2
// Cycle detection
ta.rsi($BTC, 14) % 10
// Time-based patterns
$BTC.close % 100Returns: 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:
expr1 + expr2Examples:
// Price addition
$BTC.high + $BTC.low
// Indicator combination
ta.rsi($BTC, 14) + ta.rsi($ETH, 14)
// String concatenation (in payloads)
"Price: " + $BTC.close
// Offset calculations
$BTC.close + ($BTC.close * 0.02)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:
expr1 - expr2 // Binary subtraction
-expr // Unary negationExamples:
// Price difference
$BTC.close - $BTC.open
// Indicator delta
ta.rsi($BTC, 14) - 50
// Unary negation
-ta.roc($BTC, 10)
// Historical comparison
$BTC.close - $BTC.close[1]Returns: Numerical value or series of values
<
Tests if the left operand is less than the right operand.
Syntax:
expr1 < expr2Examples:
// Price comparison
$BTC.close < $BTC.open
// Indicator thresholds
ta.rsi($BTC, 14) < 30
// Cross-asset comparison
$BTC.close < $ETH.close * 20
// Historical comparison
ta.sma($BTC, 10) < ta.sma($BTC, 50)Returns: Boolean value (true or false)
<=
Tests if the left operand is less than or equal to the right operand.
Syntax:
expr1 <= expr2Examples:
// Boundary conditions
ta.rsi($BTC, 14) <= 30
// Price levels
$BTC.close <= ta.sma($BTC, 20)
// Volume analysis
$BTC.volume <= ta.sma($BTC.volume, 10)Returns: Boolean value (true or false)
==
Tests if two expressions are equal.
Syntax:
expr1 == expr2Examples:
// Exact matches
ta.rsi($BTC, 14) == 50
// String comparison (in payloads)
symbol == "$BTC"
// Boolean comparison
ta.crossover(ta.sma($BTC, 10), ta.sma($BTC, 20)) == true
// Rounded comparisons
math.round($BTC.close) == 50000Returns: Boolean value (true or false)
>
Tests if the left operand is greater than the right operand.
Syntax:
expr1 > expr2Examples:
// Bullish conditions
$BTC.close > $BTC.open
// Overbought detection
ta.rsi($BTC, 14) > 70
// Breakout detection
$BTC.close > ta.bb($BTC, 20, 2).upper
// Volume surge
$BTC.volume > ta.sma($BTC.volume, 20) * 2Returns: Boolean value (true or false)
>=
Tests if the left operand is greater than or equal to the right operand.
Syntax:
expr1 >= expr2Examples:
// Support levels
$BTC.close >= ta.sma($BTC, 200)
// Momentum conditions
ta.macd($BTC, 12, 26, 9).histogram >= 0
// Threshold conditions
ta.atr($BTC, 14) >= 1000Returns: Boolean value (true or false)
and
Logical AND operation. Returns true only if both operands are true.
Syntax:
expr1 and expr2Examples:
// Multiple conditions
ta.rsi($BTC, 14) > 70 and $BTC.volume > ta.sma($BTC.volume, 20)
// Complex combinations
ta.crossover(ta.sma($BTC, 10), ta.sma($BTC, 50)) and ta.rsi($BTC, 14) < 70
// Nested conditions
$BTC.close > $BTC.open and ta.macd($BTC).histogram > 0 and $BTC.volume > ta.sma($BTC.volume, 10)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:
expr1 or expr2Examples:
// Alternative conditions
ta.rsi($BTC, 14) < 30 or ta.rsi($BTC, 14) > 70
// Breakout signals
$BTC.close > ta.bb($BTC).upper or $BTC.close < ta.bb($BTC).lower
// Multi-asset signals
ta.crossover(ta.sma($BTC, 10), ta.sma($BTC, 50)) or ta.crossover(ta.sma($ETH, 10), ta.sma($ETH, 50))Note: Also supports JavaScript syntax || for compatibility.
Returns: Boolean value (true or false)
not
Logical NOT operation. Inverts the boolean value.
Syntax:
not exprExamples:
// Negation
not ta.crossunder(ta.sma($BTC, 10), ta.sma($BTC, 50))
// Condition negation
not (ta.rsi($BTC, 14) > 70)
// Complex negation
not ($BTC.close < $BTC.open and $BTC.volume < ta.sma($BTC.volume, 10))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:
condition ? valueIfTrue : valueIfFalseExamples:
// Simple conditional
ta.rsi($BTC, 14) > 70 ? "Overbought" : "Normal"
// Signal direction
$BTC.close > $BTC.open ? "Buy" : "Sell"
// Dynamic thresholds
ta.rsi($BTC, 14) > ($BTC.volume > 1000000 ? 75 : 70) ? "Strong Sell" : "Hold"
// Payload expressions
"Action: " + (ta.crossover(ta.sma($BTC, 10), ta.sma($BTC, 50)) ? "Enter Long" : "Wait")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:
series[index]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:
// Price comparison
$BTC.close > $BTC.close[1] // Current price higher than previous
// Volume spike detection
$BTC.volume > $BTC.volume[1] * 1.5 // Volume 50% higher than previous
// RSI momentum
ta.rsi($BTC, 14) > ta.rsi($BTC, 14)[1] // RSI increasing
// Multi-period analysis
ta.rsi($BTC, 14)[5] < 30 and ta.rsi($BTC, 14) > 50 // RSI recovery from oversold
// MACD historical comparison
ta.macd($BTC, 12, 26, 9).histogram > ta.macd($BTC, 12, 26, 9).histogram[1]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.closeequals$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?