If / Then / Else¶
Flow · Branch
Per-bar branching: when condition is true, emit if_true's value; otherwise emit if_false's. The visual equivalent of condition ? a : b. Bars where condition is missing emit NaN — engine treats as 'no value'.
If / Then / Else is conditional selection on the chart: when a condition is true it passes through one value, otherwise it passes through another. It's the visual equivalent of the ternary expression condition ? a : b that programmers use everywhere. With it you can build values that adapt to context — a wider stop in volatile regimes and a tighter one in calm, a different target in a trend versus a range, and so on.
How it works¶
The block takes three inputs: a boolean If (the condition), a Then value, and an Else value. On each bar, if the condition is true it emits the Then value; if false, the Else value. The Then/Else inputs can be series or bars (bars use the close). Bars where the condition is missing (NaN) emit NaN, which the engine treats as "no value." The result is a single per-bar series you can feed onward — into a risk leg, a comparison, or another block.
When to use it¶
Use If / Then / Else whenever a parameter should switch based on context. The classic case is regime-adaptive risk: feed a Volatility Regime or ADX / DMI condition into If, a wide ATR stop into Then, and a tight one into Else, so your stop distance changes with conditions. You can also use it to blend two indicators, swap a target by trend direction, or select between two signals. It's the block that lets a single strategy behave differently in different environments without splitting into two strategies.
Example¶
A regime-adaptive stop: feed an ADX / DMI > 25 condition into If, an ATR×3 series into Then (wide stop for trends), and an ATR×1.5 series into Else (tight stop for ranges); wire the Pick output into the Tester's SL socket. Now the stop widens in trends and tightens in chop. Backtest in the Tester.
Tips & gotchas¶
- It's
condition ? a : b— per-bar selection between two values. - Then/Else can be series or bars (bars use close) — mix freely.
- Missing condition → NaN output — the engine reads that as "no value," which is usually what you want.
- Great for regime-adaptive risk — switch stop/target by Volatility Regime or ADX / DMI.
Related blocks¶
Inputs¶
| Socket | Type | What to wire in |
|---|---|---|
| If | signal |
Boolean condition that picks the source. |
| Then | series / bars |
Value used when condition is true. BARS uses close. |
| Else | series / bars |
Value used when condition is false. BARS uses close. |
Outputs¶
| Output | Type | Plots as | Description |
|---|---|---|---|
| Pick | series |
Line · sub-pane | Per-bar selected value. |
Reference auto-generated from the block catalog · category Flow.