Contents
- abs
- add
- all_time_high
- all_time_low
- and
- approx
- aroon_down
- aroon_osc
- aroon_up
- atr
- bb_lower
- bb_upper
- bb_width
- cci
- change
- cond
- count
- cross
- crossover
- crossunder
- cumsum
- days_since
- dev
- deviation
- div
- ema
- eq
- falling
- floordiv
- gain
- gt
- gte
- highest
- highest_bars_ago
- hma
- kc_lower
- kc_middle
- kc_upper
- kcw
- loss
- lowest
- lowest_bars_ago
- lt
- lte
- macd_histogram
- macd_line
- macd_signal
- max
- mean
- median
- mfi
- min
- mod
- mom
- months_since
- mul
- ne
- obv
- offset
- or
- pct_change
- percentrank
- pivothigh
- pivotlow
- pow
- range
- rising
- roc
- rsi
- sma
- sqrt
- stdev
- stoch_d
- stoch_k
- streak
- sub
- sum
- swma
- true_range
- universe_percentile
- variance
- vwma
- weeks_since
- wilderma
- williams_r
- wma
- years_since
No matches
cond
Conditional/ternary operator (if-then-else)
cond(condition, if_true, if_false)
Parameters
| Name | Type | Description |
|---|---|---|
condition |
bool | Boolean expression to evaluate |
if_true |
field | Value returned when condition is true |
if_false |
field | Value returned when condition is false |
Formula
result = if_true when condition, else if_false
Examples
// 1 for up days, 0 for down days
cond(close > open, 1, 0);
// distance above MA (zero when below)
cond(close > sma(close, 20), close - sma(close, 20), 0);
// -1 = overbought, 1 = oversold, 0 = neutral
cond(rsi(close, 14) > 70, -1,
cond(rsi(close, 14) < 30, 1, 0));
// body-to-range ratio, safe when range is zero
cond(bar_range != 0, bar_change / bar_range, 0);
Returns
field
Notes
Can be nested for multi-level classification (if-else-if chains). Arguments can be any expression: fields, functions, or constants. Both branches are evaluated, so use for calculations not side effects.