$TRAILING
The $TRAILING instruction sets a trailing stop as a fixed money distance in the instrument currency with SET STOP $TRAILING in ProBacktest and ProOrder.
Syntax
SET STOP $TRAILING xParameters
| Name | Type | Default | Description |
|---|---|---|---|
x | numeric | none | Maximum give-back allowed from the best price since entry, expressed in the currency of the traded instrument. |
How it works
$TRAILING combines with SET STOP only. It behaves like SET STOP $LOSS with one difference: the reference price ratchets. For a long position the stop trails below the highest price reached since entry, at a distance equivalent to x currency units given the position size, and it never moves down. For a short position it trails above the lowest price reached. When price retraces by the full distance, the position closes.
The money amount is translated into a price gap through the position size and the point value of the instrument, so the same x yields a tighter price trail on a bigger position. The setting persists for the current and all future positions until another SET STOP call overrides it, and a value of 0 disables it.
The practical effect is a cap on how much open profit the trade can give back, measured in account-relevant terms rather than in points or percent.
Examples
Example 1, Pullback entry with a 100 currency-unit trail (ProBacktest)
// Moving averages framing the pullback
i1 = Average[100](close)
i2 = Average[5](close)
// Uptrend pullback with three rising lows
tradeinitiate = Close > i1 AND Close < i2 AND Low[3] > Low[2] AND Low[2] > Low[1] AND Low[1] > Low
IF NOT LongOnMarket AND tradeinitiate THEN
BUY 1 CONTRACTS AT MARKET
// Give the trade at most 100 of retracement from its best price
SET STOP $TRAILING 100
ENDIFThe strategy buys pullbacks in an uptrend. From entry onward the stop shadows the highest price reached and exits after a retracement worth 100 currency units.
Example 2, Money trail on a short breakout (ProOrder)
support = Lowest[20](low)
IF NOT ShortOnMarket AND close crosses under support[1] THEN
SELLSHORT 1 CONTRACT AT MARKET
ENDIF
// The stop trails above the lows, exit after a 75 currency-unit bounce
SET STOP $TRAILING 75On the short side the trail follows price down; only a bounce worth 75 currency units against the position triggers the exit.
Example 3, Static money stop first, trail after activation (ProOrder)
DEFPARAM CumulateOrders = false
IF NOT OnMarket AND close crosses over Highest[20](high)[1] THEN
BUY 1 CONTRACT AT MARKET
// Fixed risk while the breakout proves itself
SET STOP $LOSS 120
ENDIF
// Once the trade is 100 ahead in money terms, switch to a trail
IF LongOnMarket AND (close - TRADEPRICE) * POINTVALUE / POINTSIZE >= 100 THEN
SET STOP $TRAILING 60
ENDIFA two-phase exit expressed entirely in money: a static 120 risk cap at entry, replaced by a 60 trailing give-back once the open profit reaches 100. The conversion uses POINTVALUE and POINTSIZE to turn the price move into currency for a one-contract position.
Common errors and gotchas
- Wrong SET pairing.
$TRAILINGis a stop instruction and combines withSET STOPonly. There is noSET TARGET $TRAILING; profit targets use$PROFIT. - Money, not points.
SET STOP $TRAILING 100allows a give-back worth 100 currency units, not 100 points. The points variant isPTRAILING, and confusing the two changes the stop distance by the instrument's point value. - Position size rescales the trail. Because the money distance is divided across the position, doubling the quantity halves the price gap. Sizing changes can turn a comfortable trail into one inside normal bar noise.
- One stop slot.
$TRAILING,%TRAILING,$LOSS,PLOSSandBREAKEVENoverwrite the same internal stop; only the most recentSET STOPcall is active. Alternating between them per bar produces erratic exits. - Backtest granularity. ProBacktest updates the trailed level from bar data. Live execution trails tick by tick, so live exits can differ slightly from backtested ones on fast bars.
Related instructions
%TRAILING, trailing stop as a percentage of the position price.PTRAILING, trailing stop as a distance in points.TRAILING, the trailing stop family overview.$LOSS, static stop loss as a fixed money amount.$PROFIT, take profit as a fixed money amount.BREAKEVEN, moves the stop or target to the entry price.STOP, pending stop orders and the SET STOP family.POINTVALUE, currency value of one point, used in money-to-price conversion.LONGONMARKET, true while a long position is open.
