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:

Examples:

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:

Examples:

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:

Examples:

Returns: 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:

Examples:

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:

Examples:

Returns:

  • For numerical values: difference between current and previous value

  • For boolean values: true if values are different, false if same

  • undefined if 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:

Examples:

Returns: 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?