# Picking a value: if and ? :

if c then a else b, or c ? a : b, picks a value per bar.

`if c then a else b` gives `a` on bars where `c` is true and `b` elsewhere. `c ? a : b` is the same thing, shorter. `else` is required; use `none` for "no value".

```vex
fast = ema(close, 9)
slow = ema(close, 21)
trend = fast > slow ? 1 : -1
plot(fast, color = fast > slow ? green : red)
plot(slow, color = if fast > slow then green else red)
plot(trend, "Trend", style = steps)
```

- `? :` binds loosest: `a + b > c ? x : y` picks on the whole comparison.
- They chain: `a ? 1 : b ? 2 : 3`, or `if a then 1 else if b then 2 else 3`.
- Both sides must be the same kind of value (two numbers, two colors, two yes/nos).
- With a setting as the condition, `if` can pick between texts and whole formulas: `average == "ema" ? ema(close, n) : sma(close, n)`.

See also: [if](/documentation/vex/reference/formulas#if), [Colors](/documentation/vex/colors), [none](/documentation/vex/reference/formulas#none)
