Crossover & ComparisonPine Script v6

ta.crossover()

Crossover

The source1-series is defined as having crossed over source2-series if, on the current bar, the value of source1 is greater than source2, and on the previous bar, source1 was less than or equal to source2.

Syntax

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

Arguments

ParameterTypeDescription
source1series int/floatSeries that must end above source2 on the current bar.
source2series int/floatReference series.

Returns

true if source1 crossed over source2 otherwise false.

Code Examples

Pine Script v6 Example
//@version=6
indicator("ta.crossover")
fast = ta.sma(close, 50)
slow = ta.sma(close, 200)
plot(fast, color=color.teal)
plot(slow, color=color.orange)
plotshape(ta.crossover(fast, slow), title="Crossover", style=shape.labelup, text="X", location=location.belowbar, size=size.small, color=color.green)

Trading Applications

Detect golden cross (50 MA over 200 MA) signals

Build moving average crossover strategies

Trigger buy signals when fast indicator crosses above slow

Create alert conditions for bullish crossovers

Related Functions

Frequently Asked Questions

Generate ta.crossover() Code with AI

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