Conditional Value Node

The Conditional Value node picks a number by condition: if this, one value; else if that, another; otherwise a default. How the cases are checked, where its value can go, and the stop modes built on it.

NodeBy AlgoLiftUpdated 4 min read
On this page 6How it worksExample: an RSI threshold that follows the trendSettingsUse something else whenWhen it doesn't behaveGoing further

Some numbers in a strategy should depend on the market. A shallower RSI threshold when the trend is strong. A wider stop when things are wild. The Conditional Value node is an if, else-if, else for numbers: each case pairs a condition with a value, and the node gives the value of the first case that's true, or the Else value when none is.

Takes
Pairs of a condition and a number, plus a number for Else
Gives
One number: the first true case's, or Else
Reach for it
A threshold, a size or a stop should change with conditions

How it works

Each case has two inputs. If takes a condition and Then takes the number it stands for. Add more cases with Add Condition, and name each one ("Strong trend", "High volatility") so the node reads like a sentence. Below the cases sits Else, the number used when no case is true.

The cases are checked from the top, and the first true one wins. That only matters when they overlap, but then it matters a lot. With "ADX above 40" and "ADX above 25" as two cases, put the 40 first. The other way round, the 25 catches every bar the 40 was meant for.

A few rules worth knowing:

  • A case only counts once both its If and its Then are wired. A half-wired case is skipped.
  • A condition that can't be judged yet counts as false, so it falls through to the next case.
  • An unwired Else is 0. That's rarely what you want for a threshold or a stop, so wire it.

The output is a number for anything that takes one: a Comparison, a Math node, an Entry's quantity, a Bracket Order's stop or target override. It's worked out as the strategy runs, so nodes that need a full history behind a value can't read it. A Crossover, Since, Capture, a modifier and a State Machine all refuse it.

Example: an RSI threshold that follows the trend

You buy RSI dips on ES 5m with a threshold of 30. In a strong trend, though, pullbacks are shallow and RSI rarely gets that low, so you'd like 40 then. Your test for a strong trend is ADX(14) above 25.

Add a Conditional Value and name its first case "Strong trend". Wire a Comparison of ADX against a Constant of 25 (Greater Than) into its If, and a Constant of 40 into its Then. Wire a Constant of 30 into Else. Then compare RSI against the Conditional Value with Less Than, and wire that into the Entry.

The threshold is now 40 on strong-trend bars and 30 on the rest, and both numbers are ordinary Constants you can sweep.

Settings

Conditions
Default One case
The cases, each with a name, an If and a Then. Add them with Add Condition; every case but the first has a remove button.

Use something else when

You need true or false, not a number
Conditions combine into one condition through Logic or a Tally.
A stop that trails, or moves to breakeven
Pick the mode on the bracket. It builds its own Conditional Value for you (see below).
A stop that grows with volatility
Rather than switching between fixed distances, measure the stop in ATRs: set the row's unit to a multiple and wire an ATR in. No cases needed.

When it doesn't behave

It always gives the Else value

No case is true. Check each If on the chart, and check that each case has its Then wired, because a case without one is skipped. A condition with a missing value (an indicator still warming up) reads false too.

It always gives the first case

The first case is true whenever a later one is. Put the narrowest case at the top.

The builder won't let me wire it into a Crossover or a Since

Both need a full history of the value behind them, and a Conditional Value only exists while the strategy runs. Compare it with a Comparison instead. The Inspector's meters can't count a condition that reads one either, for the same reason, and mark it Can't measure rather than guess.

Going further

The Bracket Order's Armed trailing and Breakeven stop modes are built on this node. Set one and the builder lays out a Conditional Value with a single case named Armed: once price clears the trigger, it gives the trailing (or breakeven) level; until then, Else holds the current stop.

You can build the same kind of thing yourself. To choose a stop distance by volatility, pick the distance with a Conditional Value, subtract it from the Entry Price Trade Variable (add it, for a short), and wire the result into the bracket's stop override. Two things to know. The override takes a price, not a distance. And it's read again on every trade while the position is open, so if the condition flips mid-trade the stop moves with it. The bracket's own stop distance, unless you set it to 0, still places the stop at the fill; the override takes over from there.

Or ask the copilot