DocsActionTrailing Stop

Trailing Stop

Risk ControlAction

Trailing Stop dynamically raises (for longs) or lowers (for shorts) the stop loss as price moves in your favour. The stop follows the highest observed price at a configurable distance — either as a percentage of that price or as a fixed number of price units. The stop never moves backward.

Algorithm

// Percentage mode (usePercentage = true)
highestPrice = max(highestPrice, currentPrice)
trailingStopPrice = highestPrice × (1 − trailingDistance / 100)
// Fixed mode (usePercentage = false)
highestPrice = max(highestPrice, currentPrice)
trailingStopPrice = highestPrice − fixedDistance

The high-water mark is stored per-node and persists across ticks. It resets automatically when the graph restarts or the position closes.

Parameters

ParameterDefaultDescription
trailingDistance2.0Distance from the high-water mark to the stop level. Interpreted as % when usePercentage is true, otherwise as price units.
usePercentagetrueWhen true, trailingDistance is a percent of the highest price. When false, it is a fixed absolute distance.
fixedDistance0Absolute distance used when usePercentage is false. Set to the desired price gap in your asset's native units.

Inputs & Outputs

PortTypeDescription
Input
inputprice seriesPrice series used to compute the high-water mark. Typically a close price or high price series.
Outputs
trailingStopPricenumber | nullCurrent trailing stop level in price units. Null if no price data yet.
trailingDistancenumberThe configured trailing distance value (mirrors the parameter).
usePercentagebooleanWhether percentage or fixed-distance mode is active.
highestPricenumber | nullThe highest price observed since the node started running.
lowestPricenumber | nullThe lowest price observed (tracked for short-side awareness).

Use Cases

Trend ride with tight exit

Set trailingDistance = 2% on a trending stock. The stop follows every new high, locking in gains while allowing normal pullbacks without premature exit.

Volatile crypto position

Use a fixed distance of 200 USDT on a BTC position to accommodate larger intraday swings without getting stopped out, while still protecting a large open profit.

Combined with Break Even

Use Break Even first (move SL to entry) then let Trailing Stop take over — the two work in series to eliminate risk then maximise the captured move.

Tips

Position-gated. The node checks for an active position before processing. It returns null and skips computation entirely when no position is open, preventing phantom SL levels from appearing on the chart.
High watermark reset. The high-water mark resets when the graph restarts. In backtesting, it resets at the start of each run. Per-trade reset requires a Close/Reopen cycle.
Input choice. Feeding the close price produces an end-of-bar trailing level. Feeding the high price ratchets on intrabar highs and produces a tighter, more responsive stop.

Related Nodes