Distance Node

The Distance node measures how far one value is from another in points, ticks, percent, ATRs or standard deviations. Which unit to pick, why normalizing makes a rule portable across markets, and what can and can't read it.

NodeBy AlgoLiftUpdated 4 min read
On this page 6How it worksExample: buy a stretch below VWAPSettingsUse something else whenWhen it doesn't behaveGoing further

"Ten points above the 20 EMA" is a big stretch in a quiet month and noise in a fast one, and it means something else again on NQ. The Distance node measures how far one value sits from another in a unit you choose: points, ticks, percent, ATRs or standard deviations. Choose a unit that scales with the market and the same rule keeps meaning the same thing, on ES in 2018 or NQ today.

Takes
A value, and a reference to measure it from
Gives
The signed distance, positive when the value is above
Reach for it
A threshold like “more than 2 ATRs below VWAP” or “within 8 ticks of the level”

How it works

Wire the thing that moves into Value and the level into Reference. The output is the value minus the reference, converted to your unit, so it's positive above the reference and negative below. Compare it with a Constant in the same unit.

UnitThe distance isGood for
PointsValue − referenceOne market where volatility stays put
TicksPoints ÷ the tick size (0.25 on ES and NQ, 0.01 on stocks)Rules about order placement
%100 × (value − reference) ÷ referenceStocks at very different prices
ATRPoints ÷ the ATR over the period you setThresholds that should scale with volatility
Std devHow unusual the gap is next to its own recent historyStretches judged against what's normal lately

Points are the trap. A threshold in points quietly assumes the market's typical move never changes, and it does: across years, across regimes, and between instruments. NQ covers far more points in a day than ES, so a 10-point rule written on ES barely registers there. Measured in ATRs, the threshold breathes with the market, which is usually what you meant in the first place.

Points, ticks, percent and ATR are plain arithmetic, so they work on live price and update on every trade. That's also why a Crossover or a modifier can't read them: those want a value that settles once per bar. When you want the moment, cross the underlying values instead.

Example: buy a stretch below VWAP

Say you trade ES 5m and want to buy sharp selloffs away from the day's VWAP, but only real ones. Ten points below VWAP is a different event on a calm day than on a wild one, so measure in ATRs.

Add a Distance node with the unit set to ATR and the period at 14. Wire Current Price into Value and the VWAP into Reference. Then a Comparison: the distance Less Than a Constant of −2. That's true while price is more than two ATRs below VWAP. AND it with your reversal trigger into a long Entry.

Point the same strategy at NQ and the rule still says two ATRs below VWAP, no translation needed. Whether the edge survives the move is for the backtest to tell you, but at least the question is the same one.

Settings

Unit
Default Points
Points, Ticks, % (of the reference), ATR or Std dev.
Period
Default 14
For ATR, the ATR's period in bars of the value's series. For Std dev, the window of completed bars. From 2 to 500; the other units ignore it.

Use something else when

Where price sits inside a range, from 0 to 1
Its Position output places a value between a high and a low, which no single distance can.
Lines a set distance above and below a level
Bands draws center ± k × width as lines you can plot, cross and place orders at.
A stop or target N ATRs from the fill
Set the row's unit to a multiple and wire the ATR into it. The ATR is frozen at the fill, so the stop doesn't move.

When it doesn't behave

Price below the level reads positive

Value and Reference are swapped. The distance is value minus reference, so the moving thing goes into Value and the level into Reference.

The builder refuses my Std dev distance

One of the inputs is live price, or something that isn't a bar value, like a Math node. Standard deviations need two values from completed bars. Use points, ticks, percent or ATR for live price.

A Crossover won't read my Distance

In points, ticks, percent or ATR the distance is worked out on every trade, and a Crossover needs a value that settles at the bar. Wire the values themselves into the Crossover, or compare the distance with a Comparison, which reads it on every trade.

Going further

The period is sweepable, and so is the Constant you compare against. The unit isn't, because switching from points to ATRs changes the question rather than tuning it.

A Distance in ATRs makes a good guard against chasing. Give a trend entry one more condition, price no more than half an ATR above its 20 EMA, and it buys near the average instead of after the move has already run.

Or ask the copilot