Trade Variable Node

The Trade Variable reads a live value of an open trade: its entry price, the ATR when it filled, its quantity, its direction, the current target or the current stop. Where it comes from, what each value means, and the ratchet behind every trailing stop.

NodeBy AlgoLiftUpdated 4 min read
On this page 7How it worksThe ratchetExample: trail by 1.5 ATR, measured at entrySettingsUse something else whenWhen it doesn't behaveGoing further

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:

ValueReads
Entry PriceThe leg's average fill price
Entry ATRThe ATR when the leg filled, on the series and period you set (14 by default). It doesn't change during the trade
QuantityThe contracts or shares open on this leg
Current TargetWhere the leg's target is right now
Current StopWhere the leg's stop is right now
Direction1 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:

TradeStop input getsSo the stop can only
LongMax of Current Stop and the new levelRise
ShortMin of Current Stop and the new levelFall

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

Value
Default Entry Price
Which value of the trade it reads. Picked by the pill you drag it from.
Series
Entry ATR only: whose bars the ATR is measured on. Set to your first series when the node is made.
Period
Default 14
Entry ATR only: the ATR's period, 1 to 500 bars.

Use something else when

A trailing or breakeven stop, ready-made
Trailing, Armed trailing, Breakeven and ATR trailing build the ratchet for you, out of these same parts.
How long the trade has been open
Set to this trade's entry, in minutes or bars.
A fact about the last trade, after it closed
A Trade Variable only reads an open leg. To keep something for later, write it into a variable of your own when the Entry fills.

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.

Or ask the copilot