Moving average crossovers, RSI leaving oversold, MACD turning — almost every trading strategy depends on detecting a cross between two series. In Pine Script v5/v6 (2026), that is solved with two built-in functions: ta.crossover and ta.crossunder. This guide shows the exact syntax, ready-to-paste examples for TradingView and the most common mistakes that make a signal “repaint” or fire at the wrong time.
Want to turn these crossover signals into automated trades? Check out our open-source Python bot.
See the bot (Quotex API in Python) →What each function does
Both functions return a boolean value (true/false) evaluated on every bar:
ta.crossover(a, b)→ returns true on the bar where seriesacrosses aboveb(it was below or equal before, now it is above).ta.crossunder(a, b)→ returns true on the bar whereacrosses belowb.
Note that the cross is a one-off event: it is true only on the exact bar of the cross, not while a stays above b. For that distinction there is the generic function ta.cross(a, b), which detects a cross in either direction.
Basic syntax
ta.crossover(ta.rsi(close,14), 30) fires when the RSI rises and crosses the 30 level — useful for detecting an exit from oversold.
Example with RSI
Firing alerts on the cross
To automate (including via webhook), combine the cross with alertcondition or alert():
alert.freq_once_per_bar_close and base decisions on the bar close. Crosses evaluated while the bar is still forming can appear and disappear (repaint) before the close, generating false signals.
Common mistakes
- Confusing it with a simple comparison:
fast > slowis true on every bar where the fast average is above;ta.crossoveris true only on the bar of the cross. - Argument order:
ta.crossover(a, b)≠ta.crossover(b, a). Direction matters. - Forgetting the close: intrabar signals repaint. Confirm at the close for realistic backtests.
- Using it on series with
na: on the first candles the average can benaand the cross does not fire — that is expected.
FAQ
What is the difference between ta.cross and ta.crossover?ta.cross detects a cross in either direction; ta.crossover only upward and ta.crossunder only downward.
Does it work in Pine Script v5 and v6?
Yes. In v5/v6 use the ta. prefix. In old scripts (v3/v4) it was just crossover() without the namespace.
Can I compare a series with a fixed number?
Yes, as in ta.crossover(ta.rsi(close,14), 50).
Do these signals work for binary options?
They work as a strategy trigger, but a cross on its own generates many false signals. Combine it with a trend filter and always test on a demo account.
Disclaimer: binary options are extremely high-risk products and can result in the total loss of your capital. This content is educational and technical; it does not constitute an investment recommendation or financial advice. Indicators and crosses do not guarantee results. Always test on a demo account before trading with real money.
