Exit logic often needs to know about the trade it's managing. Where did it fill? Where's the stop now? The Trade Variable reads one of those values off an open leg and hands it on as a number, so "move the stop to the entry plus 2" is something you wire rather than something you guess.
- Takes
- Nothing. It reads the leg it came from
- Gives
- One number about the open trade
- Reach for it
- Exit logic that depends on the trade itself
How it works
You make one by dragging a value off the rail along the top of a Trade node, or the Entry Price pill on a Bracket Order. It's tied to that leg, and it only has something to read while that leg is open, so it belongs in the leg's exit logic: a bracket's stop or target input, or a setter.
There are six values, and nothing else:
| Value | Reads |
|---|---|
| Entry Price | The leg's average fill price |
| Entry ATR | The ATR when the leg filled, on the series and period you set (14 by default). It doesn't change during the trade |
| Quantity | The contracts or shares open on this leg |
| Current Target | Where the leg's target is right now |
| Current Stop | Where the leg's stop is right now |
| Direction | 1 for a long, -1 for a short |
The rail offers the first five. Direction isn't on it, so ask the copilot if a formula needs the trade's side. Entry Time used to be on the list; it's retired, and a Time Since set to this trade's entry does the job.
The ratchet
Current Stop is the value that makes trailing stops work. A stop computed fresh on every tick, like price minus 10, moves down whenever price does, which is the opposite of a trailing stop. Read the current stop back and keep the better of the two:
| Trade | Stop input gets | So the stop can only |
|---|---|---|
| Long | Max of Current Stop and the new level | Rise |
| Short | Min of Current Stop and the new level | Fall |
The stops a Bracket Order's Stop Mode builds are this exact shape, and the builder refuses the backwards version: a Min feeding a long's stop, or a Max feeding a short's.
Example: trail by 1.5 ATR, measured at entry
Say you trade ES 5m longs with a bracket: a 30-point target and an 8-point stop. The bracket's ATR trailing mode reads the ATR live, so its trail widens and narrows with volatility mid-trade. You want the trail fixed for the whole trade at 1.5 times the ATR when it filled.
Drag Entry ATR off the Trade node and multiply it by a Constant of 1.5 in a Math node. Subtract that from Current Price in a second Math node. Drag out Current Stop, take the Max of it and the subtraction in a third, and wire the Max into the bracket's stop input on the left edge of its STOP LOSS row.
The row now reads Initial: the 8-point stop protects the trade at the start, and the trail takes over once price minus 1.5 ATR passes it. From then on the stop only climbs, always the same distance behind price.
Settings
Use something else when
When it doesn't behave
My trailing stop moves down on pullbacks
The new level goes straight into the stop. Put a Max (long) or Min (short) between them, with Current Stop on its other input.
My stop moved after entry when I wanted it fixed
Something in the formula is re-read every tick, usually a live ATR or a moving average. Use Entry ATR, which is taken once when the trade fills, or measure the bracket's stop from a Level, which is read once too.
Going further
The ratchet takes a gate well. A breakeven stop with a cushion, "move the stop to the entry plus 1 once the trade is 2 ATRs in profit", is Entry Price plus 2 × Entry ATR as the trigger, a Comparison of Current Price against it, and a Conditional Value that picks Entry Price plus 1 when the comparison is true and Current Stop when it isn't. Run that through the same Max into the stop input and the stop jumps once, then stays.