ProBacktest/probacktest · proorder

PTRAILING

SET STOP PTRAILING in ProBacktest and ProOrder sets a trailing stop that follows price at a fixed distance in points. PTRAILING syntax, examples, and gotchas.

Syntax

probuilder
SET STOP PTRAILING x

Parameters

NameTypeDefaultDescription
xnumbernoneDistance in points between the market price and the trailing stop. Accepts literals, variables, and expressions.

How it works

SET STOP PTRAILING declares a dynamic stop order that trails the market by a fixed number of points. For a long position the stop sits x points below the highest price reached since entry; when price makes a new high, the stop rises with it, and when price falls the stop holds its level. The position closes once price retraces x points from its best level. Short positions mirror this behavior above the market.

Like all SET declarations, the instruction is persistent. Declared once, usually on its own line outside any IF block, it applies to the current position and to every later position until another SET STOP call replaces it.

The distance is measured in points. The sibling variants cover other units: SET STOP TRAILING for price units, SET STOP %TRAILING for percent, and SET STOP $TRAILING for account currency.

Examples

Example 1, Trailing stop on a pullback entry (ProBacktest)

probuilder
// Trend filter and short-term average
i1 = average(close)[100]
i2 = average(close)[5]

// Enter on a three-bar pullback inside an uptrend
tradeinitiate = Close > i1 AND Close < i2 AND Low[3] > Low[2] AND Low[2] > Low[1] AND Low[1] > Low
tradeclose = Close > Close[1]

IF NOT LongOnMarket AND tradeinitiate THEN
    BUY 1 CONTRACTS AT MARKET
ENDIF

IF LongOnMarket AND tradeclose THEN
    SELL AT MARKET
ENDIF

// Protective stop trails 10 points behind price
SET STOP PTRAILING 10

The strategy buys pullbacks above the 100-bar average and exits on strength, while the trailing stop caps any retracement at 10 points. This is the example from the official reference.

Example 2, Breakout entry protected by a point-based trail (ProOrder)

probuilder
DEFPARAM CumulateOrders = false

// Enter on a 20-bar breakout
IF NOT onmarket AND close > highest[20](high)[1] THEN
  BUY 1 CONTRACT AT MARKET
ENDIF

// Let the trade run, exit after a 25-point retracement
SET STOP PTRAILING 25

No fixed target is used. The trailing stop is the only exit, so the trade stays open as long as price keeps advancing without a 25-point pullback.

Example 3, Trailing a short position (ProOrder)

probuilder
DEFPARAM CumulateOrders = false

// Short when price loses the 50-bar average
IF NOT onmarket AND close CROSSES UNDER Average[50](close) THEN
  SELLSHORT 1 CONTRACT AT MARKET
ENDIF

// Stop trails 15 points above the falling price
SET STOP PTRAILING 15

For a short, the stop sits above the market and steps down as price makes new lows, closing the trade after a 15-point bounce.

Common errors and gotchas

  • Points, not price units or percent. PTRAILING trails in points, TRAILING in price units, %TRAILING in percent, and $TRAILING in account currency. Picking the wrong variant on an instrument with a small point size creates a stop that is effectively at the market or absurdly far away.
  • One stop slot per position. SET STOP PTRAILING, SET STOP LOSS, and SET STOP BREAKEVEN all write to the same internal stop, and the most recent call wins. Alternating between them bar by bar produces erratic exits; choose one stop policy per trade.
  • Backtests fill trailing stops optimistically. ProBacktest evaluates the trail on bar data and assumes clean fills at the stop level. Live execution in fast markets slips through the level, so live results are systematically worse than the simulation for tight trails.
  • Too tight a trail turns into an instant exit. A distance smaller than the normal bar-to-bar noise of the instrument closes most trades within a few bars. Size the distance from measured volatility, for example a multiple of ATR converted to points, rather than a fixed guess.
  • TRAILING, trailing stop distance in price units.
  • %TRAILING, trailing stop distance in percent.
  • $TRAILING, trailing stop distance in account currency.
  • SET, prefix of all order management declarations.
  • STOP, the protective-stop side of the SET instruction.
  • BREAKEVEN, moves the stop or target to the entry price.
  • PLOSS, fixed stop-loss distance in points.
  • TRADEPRICE, the entry price of the current position.
  • POINTSIZE, the value of one point of the instrument.
  • LONGONMARKET, true while a long position is open.