Crossover & ComparisonPine Script v6

ta.cross()Cross

Returns true on bars where two series cross each other (either direction), compared bar-to-bar.

Syntax

Syntax
ta.cross(source1, source2) → series bool

Arguments

ParameterTypeDescription
source1series int/floatFirst series.
source2series int/floatSecond series.

Returns

true if two series have crossed each other, otherwise false.

Code Examples

Pine Script v6 Example
//@version=6
indicator("ta.cross")
fast = ta.sma(close, 9)
slow = ta.sma(close, 21)
plot(fast)
plot(slow)
plotshape(ta.cross(fast, slow), title="Cross", style=shape.triangleup, location=location.belowbar, size=size.tiny)

Trading Applications

Detect any crossing between two series

Build custom crossover-based strategies

Identify indicator intersections

Use as a trigger for alerts

Related Functions

Frequently Asked Questions

ta.cross() is true when source1 and source2 intersect on the current bar (either source1 crossing above or below source2), based on their values this bar vs the prior bar.

ta.crossover() is true only when source1 crosses above source2. ta.crossunder() is true only when source1 crosses below source2. ta.cross() fires on either type of cross between the two series.

Use ta.crossover() or ta.crossunder() when you need directional logic (bullish vs bearish). Use ta.cross() when you only care that an intersection happened, not which way it went.

Generate ta.cross() Code with AI

Skip the manual coding. Use Pineify's AI Coding Agent to generate Pine Script code using ta.cross() and other built-in functions instantly.