Skip to main content

Overview

Crossover functions compare two sources at the current and previous bar to detect directional changes. They all return a boolean.
All crossover functions require a source function (a (offset?) => number | null callable), not a scalar. Pass ctx.close or input.source() - not ctx.close().

ta.crossover(a, b) - A crosses above B

Returns true when a was below b on the previous bar and is now above b.
The idiomatic form passes source functions directly:

ta.crossunder(a, b) - A crosses below B

Returns true when a was above b on the previous bar and is now below b.

ta.cross(a, b) - Either direction

Returns true for either crossover or crossunder.

ta.rising(source, length) - Rising over N bars

Returns true if source(0) > source(length) - current value is higher than length bars ago.

ta.falling(source, length) - Falling over N bars

Returns true if source(0) < source(length).

Source type requirement

The a and b arguments to crossover/crossunder/cross must be source functions ((offset?) => number | null). A plain number is accepted for b only. Passing a scalar to a causes a TypeError.

Moving averages

Common sources for crossover signals.

Oscillators

RSI crossovers (crossing 70/30) are a classic use case.

Series

Manual crossover detection with Series for full control.