Skip to content
Algo Trade Analytics Docs

?: - Pine Script Operator

?:

Ternary conditional operator.

expr1 ? expr2 : expr3

expr2 if expr1 is evaluated to true, expr3 otherwise. Zero value (0 and also NaN, +Infinity, -Infinity) is considered to be false, any other value is true.

  • Use na for ‘else’ branch if you do not need it.
//@version=6indicator("?:")// Draw circles at the bars where open crosses closes2 = ta.cross(open, close) ? math.avg(open,close) : naplot(s2, style=plot.style_circles, linewidth=2, color=color.red)// Combination of ?: operators for 'switch'-like logicc = timeframe.isintraday ? color.red : timeframe.isdaily ? color.green : timeframe.isweekly ? color.blue : color.grayplot(hl2, color=c)