ProBacktest/probacktest · proorder

LOSS

LOSS sets a stop loss with SET STOP LOSS x in ProBacktest and ProOrder, closing a losing trade once price moves x price units against the average entry price.

Syntax

probuilder
SET STOP LOSS x

Parameters

NameTypeDefaultDescription
xnumericnoneDistance from the average position price, expressed in the price units of the traded instrument.

How it works

SET STOP LOSS registers a protective stop with the execution engine. The distance x is measured from the average position price, so for a long position the stop sits at entry minus x, and for a short position at entry plus x. The same positive value works for both directions, the engine flips the side automatically.

The distance is expressed in raw price units. On an instrument quoted with five decimals, SET STOP LOSS 0.0050 places the stop 50 pips away. On an index quoted in whole points, the same statement would place it half a cent away, which is almost certainly wrong. For distances in points or pips regardless of quotation, SET STOP PLOSS is the safer variant, and SET STOP %LOSS expresses the distance as a percentage of the entry price.

The instruction is declarative. Once executed, the stop remains attached to the current position and to subsequent positions until another SET STOP statement replaces it or SET STOP LOSS 0 cancels it. It is common to place the statement directly after the entry order so the two are always in sync.

In ProBacktest the stop is evaluated against intrabar highs and lows, in live ProOrder it rests at the broker and can fill with slippage in fast markets.

Examples

Example 1, MACD entry with a fixed-distance stop (ProOrder)

probuilder
myMACD = MACD[12,26,9](close)
long = myMACD crosses over 0

IF NOT LongOnMarket AND long THEN
  BUY 1 CONTRACTS AT MARKET
  // stop placed 0.0050 price units below the average entry price
  SET STOP LOSS 0.0050
ENDIF

A long opens when the MACD line crosses above zero, with a stop 0.0050 price units below the entry. The value suits an instrument quoted with five decimals, such as a major currency pair.

Example 2, Volatility-scaled stop distance (ProBacktest)

probuilder
// distance adapts to current volatility
atr = AverageTrueRange[14](close)

IF NOT OnMarket AND close crosses over Average[50](close) THEN
  BUY 1 CONTRACT AT MARKET
  SET STOP LOSS 2 * atr
ENDIF

The stop distance is two ATRs, so it widens in volatile markets and tightens in quiet ones. The expression is recomputed on each entry, keeping risk proportional to conditions.

Example 3, Stop on the short side (ProOrder)

probuilder
short = close crosses under Average[100](close)

IF NOT ShortOnMarket AND short THEN
  SELLSHORT 1 CONTRACT AT MARKET
  // same positive distance, the engine places it above the short entry
  SET STOP LOSS 0.0080
ENDIF

For a short position the engine places the stop above the average entry price. The distance stays a positive number, no sign change is needed.

Common errors and gotchas

  • Price units, not points. x is a raw price distance. SET STOP LOSS 10 on a five-decimal currency pair means 10.0000 in price, an enormous distance. For a 10-pip stop write SET STOP LOSS 10 * PipSize or use SET STOP PLOSS 10.
  • Measured from the entry, not from current price. The stop level is anchored to the average position price. Calling the statement again later does not trail the stop from the latest close, it re-anchors the same distance from the entry. Trailing requires $TRAILING, %TRAILING, or TRAILING variants.
  • The setting persists. A SET STOP LOSS executed once continues to apply to every later position until replaced. A strategy that sets a tight stop in one branch and forgets to reset it elsewhere carries that stop into unrelated trades.
  • Backtest fills are optimistic. ProBacktest assumes the stop fills exactly at its level. Live stops can slip past the level in fast markets, so realized losses can exceed the configured distance.
  • %LOSS, stop loss as a percentage of the entry price.
  • $LOSS, stop loss as a cash amount.
  • PLOSS, stop loss as a distance in points.
  • Set Target Loss, exit a losing position at a fixed adverse distance.
  • Set Stop Profit, stop that locks in a profit distance.
  • STOP, pending stop orders for entries and exits.
  • TARGET, take-profit counterpart of the stop family.
  • BREAKEVEN, moves the stop or target to the entry price.
  • TRADEPRICE, the entry price of the current position.
  • TRAILING, trailing stop that follows favorable price movement.