Utilities
This section documents the utility (ta.*) functions.
ta.crossover
Detects when one series crosses above another or above a fixed level.
Syntax:
ta.crossover(seriesA, seriesB)
ta.crossover(series, level)Examples:
// Moving average crossover
ta.crossover(ta.sma($BTC, 10), ta.sma($BTC, 50))
// Price crossover
ta.crossover($BTC.close, ta.sma($BTC, 20))
// Level crossover
ta.crossover(ta.rsi($BTC, 14), 70)
// MACD crossover
ta.crossover(ta.macd($BTC, 12, 26, 9).macd, ta.macd($BTC, 12, 26, 9).signal)
// Custom indicator crossover
ta.crossover(ta.ema($BTC, 12), ta.ema($BTC, 26))Returns: Boolean (true when crossover occurs, false otherwise)
Use Cases:
Entry signals when fast MA crosses above slow MA
Breakout detection when price crosses above resistance
Momentum shifts when oscillators cross key levels
ta.crossunder
Detects when one series crosses below another or below a fixed level.
Syntax:
ta.crossunder(seriesA, seriesB)
ta.crossunder(series, level)Examples:
// Moving average crossunder
ta.crossunder(ta.sma($BTC, 10), ta.sma($BTC, 50))
// Price breakdown
ta.crossunder($BTC.close, ta.sma($BTC, 20))
// RSI exit signal
ta.crossunder(ta.rsi($BTC, 14), 30)
// Support breakdown
ta.crossunder($BTC.close, ta.bb($BTC, 20, 2).lower)
// MACD bearish signal
ta.crossunder(ta.macd($BTC, 12, 26, 9).macd, ta.macd($BTC, 12, 26, 9).signal)Returns: Boolean (true when crossunder occurs, false otherwise)
Use Cases:
Exit signals when fast MA crosses below slow MA
Breakdown detection when price crosses below support
Weakness signals when oscillators cross below key levels
ta.cross
Detects when two series cross each other in any direction (up or down).
Syntax:
ta.cross(source1, source2)Examples:
// Any moving average cross
ta.cross(ta.sma($BTC, 10), ta.sma($BTC, 50))
// Price crossing moving average (any direction)
ta.cross($BTC.close, ta.sma($BTC, 20))
// RSI crossing midline
ta.cross(ta.rsi($BTC, 14), 50)
// MACD line crossing signal line
ta.cross(ta.macd($BTC, 12, 26, 9).macd, ta.macd($BTC, 12, 26, 9).signal)
// Price crossing VWAP
ta.cross($BTC.close, ta.vwap($BTC))Returns: Boolean (true when any crossing occurs, false otherwise)
Use Cases:
General crossing detection without direction bias
Trend change identification
Mean reversion signals
Oscillator equilibrium breaks
ta.highest
Returns the highest value in a series over a specified lookback period.
Syntax:
ta.highest(series, length)Examples:
// Highest high over 20 periods
ta.highest($BTC.high, 20)
// Resistance level identification
$BTC.close > ta.highest($BTC.high, 50) // New 50-period high
// RSI extreme levels
ta.highest(ta.rsi($BTC, 14), 10) > 80
// Volume spike detection
$BTC.volume > ta.highest($BTC.volume, 20) * 0.8
// Breakout confirmation
$BTC.close > ta.highest($BTC.high, 20) and $BTC.volume > ta.sma($BTC.volume, 20) * 1.5Returns: Highest value in the lookback period
Use Cases:
Resistance level identification
Breakout detection and confirmation
Extreme reading analysis for oscillators
Volatility and volume spike detection
ta.lowest
Returns the lowest value in a series over a specified lookback period.
Syntax:
ta.lowest(series, length)Examples:
// Lowest low over 20 periods
ta.lowest($BTC.low, 20)
// Support level identification
$BTC.close < ta.lowest($BTC.low, 50) // New 50-period low
// RSI oversold extremes
ta.lowest(ta.rsi($BTC, 14), 10) < 20
// Volatility compression
ta.highest($BTC.high, 20) - ta.lowest($BTC.low, 20) < ta.atr($BTC, 14) * 5
// Support test
$BTC.low > ta.lowest($BTC.low, 20) and $BTC.close < ta.sma($BTC, 20)Returns: Lowest value in the lookback period
Use Cases:
Support level identification
Breakdown detection and confirmation
Oversold condition analysis
Range and volatility compression detection
ta.change
Compares current value to its value N bars ago and returns the difference.
Syntax:
ta.change(source, length) // length defaults to 1Examples:
// Price change from previous bar
ta.change($BTC.close) // Same as ta.change($BTC.close, 1)
// Price change over 5 bars
ta.change($BTC.close, 5)
// Volume change detection
ta.change($BTC.volume) > 0 // Volume increased
// RSI momentum change
ta.change(ta.rsi($BTC, 14)) > 5 // RSI increased by more than 5
// Direction change detection (for boolean series)
ta.change($BTC.close > $BTC.open) // Candle color changedReturns:
For numerical values: difference between current and previous value
For boolean values:
trueif values are different,falseif sameundefinedif insufficient data
Use Cases:
Momentum analysis and rate of change
Detecting direction changes in trends
Volume surge detection
Oscillator momentum shifts
ta.range
Calculates the range (highest - lowest) over a specified lookback period.
Syntax:
ta.range(series, length)Examples:
// True range over 14 periods
ta.range($BTC.high, 14) - ta.range($BTC.low, 14)
// Price range analysis
ta.range($BTC.close, 20) > ta.atr($BTC, 14) * 2 // Wide range day
// Volatility compression detection
ta.range($BTC.high, 10) < ta.sma(ta.range($BTC.high, 10), 20) * 0.5
// RSI range over lookback period
ta.range(ta.rsi($BTC, 14), 5) < 10 // RSI in tight range
// Bollinger Band width equivalent
ta.range(ta.bb($BTC, 20, 2).upper, 1) - ta.range(ta.bb($BTC, 20, 2).lower, 1)
// Volume range analysis
ta.range($BTC.volume, 10) / ta.sma($BTC.volume, 10) // Volume range ratioReturns: Range value (highest - lowest) over the lookback period, or 0 for constants
Use Cases:
Volatility measurement and analysis
Range compression/expansion detection
Breakout preparation identification
Market consolidation analysis
Last updated
Was this helpful?