Crossover & ComparisonPine Script v6

ta.crossunder()Crossunder

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

TradingView language reference

Syntax

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

Arguments

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

Returns

true if source1 crossed under source2 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.crossunder")
fast = ta.sma(close, 50)
slow = ta.sma(close, 200)
plot(fast, color=color.teal)
plot(slow, color=color.orange)
plotshape(ta.crossunder(fast, slow), title="Crossunder", style=shape.labeldown, text="X", location=location.abovebar, size=size.small, color=color.red)

Trading Applications

Detect death cross (50 MA under 200 MA) signals

Build sell/short strategies based on crossunders

Trigger exit signals when fast indicator crosses below slow

Create alert conditions for bearish crossovers

Related Functions

Frequently Asked Questions

ta.crossunder(source1, source2) is true only on the bar where source1 moves from at or above source2 to strictly below source2. The mathematical direction is downward; whether it is bearish depends on what the series represent.

Crossover detects source1 rising through source2; crossunder detects source1 falling through source2. They are directional opposites for the same two-series relationship.

Pair long logic with ta.crossunder(fast, slow) or price vs support indicator to close or reduce longs when momentum or structure turns down. Add confirmation and risk rules.

Generate ta.crossunder() Code with AI

Draft Pine Script using ta.crossunder() 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.