Sidechair

ta.crossover()

Browse the reference

Returns true on the bar where source1 moves from at or below source2 to above it.

Try it in the editor

ta.crossover is true when source1 > source2 on this bar and source1 <= source2 on the previous bar. Either argument can be a series or a plain number such as 70.

It is true for one bar per cross. On the first bar there is no previous value, and any na makes it false.

Syntax

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

Arguments

NameTypeDefaultDescription
source1series int/floatrequiredThe series expected to move up through the other.
source2series int/floatrequiredThe series or level being crossed.

Returns

series bool: true on the crossing bar, otherwise false.

Remarks

  • Touching without passing through counts: when source1 equals source2 on the previous bar, the next bar above is a crossover.
  • Call it on every bar. Inside an if block it compares values from bars where the block ran.

Example

Pine ScriptMark the cross of two averagesOpen in editor
//@version=6
indicator("Crossover marks", overlay = true)
fast = ta.sma(close, 10)
slow = ta.sma(close, 30)
plot(fast, "Fast", color = color.green)
plot(slow, "Slow", color = color.red)
plotshape(ta.crossover(fast, slow), "Cross up", shape.labelup, location.belowbar, color.green, text = "Up", textcolor = color.white)

See also

Runs on Sidechair