Ternary Operator "if else"

QuantScript's ternary

if else
operator implements conditional expressions.

Syntax is as follows:

1 positiveOutcomeExpr if conditionExpr else negativeOutcomeExpr

The result of the whole expression is:

  • positiveOutcomeExpr
    if
    conditionExpr
    is
    true
  • negativeOutcomeExpr
    if
    conditionExpr
    is
    false
  • unknown
    if
    conditionExpr
    is not a Boolean

Examples:

1 10 if 9 > 8 else 7 # -> 10
2
3 10 if 9 < 8 else 7 # -> 7
4
5 10 if 9 else 8 # -> unknown
6
7 high if open else low # -> unknown

Table of Operands

Anything not listed here results in an Unknown.
This operator is right associative -

a if b else c if d else e
is the same as
a if b else (c if d else e)
.

Positive OperandConditional OperandNegative OperandResult
AnyBooleanAnyAny
AnySeries<Boolean>AnySeries<Any>
AnyMultiDataset<Boolean>AnyMultiDataset<Any>