Sidechair

ta.cross()

Browse the reference

Returns true on any bar where the two series cross, in either direction.

Try it in the editor

ta.cross is ta.crossover(source1, source2) or ta.crossunder(source1, source2). It does not say which way the cross went.

To find the direction, compare the two series on the same bar, or call ta.crossover and ta.crossunder separately.

Syntax

Pine Script
ta.cross(source1: series int/float, source2: series int/float) -> series bool

Arguments

NameTypeDefaultDescription
source1series int/floatrequiredThe first series. The call is true on the bar where it meets or passes source2.
source2series int/floatrequiredThe second series or a level.

Returns

series bool: true on a bar where the series crossed in either direction.

Remarks

  • The first bar is always false, since there is no earlier value to compare.

Example

Pine ScriptAny cross of close and an averageOpen in editor
//@version=6
indicator("Close crosses SMA", overlay = true)
avg = ta.sma(close, 20)
plot(avg, "SMA 20", color = color.orange)
plotchar(ta.cross(close, avg), "Cross", "x", location.top, color.blue, size = size.tiny)

See also

Runs on Sidechair