Crossover & ComparisonPine Script v6

ta.cross()Cross

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

TradingView language reference

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.

Remarks

Evaluate the condition on each bar. Values can change while a realtime bar is open; use a close-confirmation policy if required. The indicator example plots markers and does not place orders or create a running alert.

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() combines crossover and crossunder: source1 is strictly above now and was at or below previously, or strictly below now and was at or above previously. Equality on the current bar alone is not a cross.

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

Draft Pine Script using ta.cross() with Pineify's AI Coding Agent, then review the arguments and test the result on your chart. Usage depends on your plan and available credits.