ProBacktest/probacktest · proorder

PLOSS

PLOSS sets a stop loss a fixed number of points from the average position price in ProBacktest and ProOrder, written as SET STOP PLOSS x in a strategy.

Syntax

probuilder
SET STOP PLOSS x

Parameters

NameTypeDefaultDescription
xinteger or numeric expressionrequiredDistance in points between the average position price and the stop level.

How it works

When the instruction executes, the strategy registers a protective stop at x points on the losing side of the average position price, below the entry for a long and above it for a short. If price reaches that level, the position closes at market.

The distance is anchored to POSITIONPRICE, the average entry price of the whole position, not to the price of the latest order. When the strategy adds contracts to an existing position, the average moves and the stop level moves with it on the next evaluation.

A SET STOP command stays active until it is replaced. It does not need to be repeated on every bar, although passing a variable as x and re-executing the line lets the distance adapt to changing conditions. All stop variants share one internal stop slot, so calling SET STOP PLOSS after SET STOP %LOSS, SET STOP $LOSS, or a trailing variant simply overwrites the previous setting.

Examples

Example 1, MACD entry with a 50-point 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
ENDIF

// Stop loss 50 points from the average position price
SET STOP PLOSS 50

A long opens when the MACD crosses above zero, and the position is protected by a stop 50 points below the average entry price. This is the reference example from the source documentation with rewritten comments.

Example 2, Point-based stop on a short position (ProBacktest)

probuilder
short = close CROSSES UNDER average[100](close)

IF NOT shortonmarket AND short THEN
  SELLSHORT 1 CONTRACTS AT MARKET
ENDIF

// Stop 30 points above the average short entry price
SET STOP PLOSS 30

For a short position the same instruction places the stop on the opposite side, 30 points above the average entry, closing the trade if price rallies that far.

Example 3, Volatility-scaled stop distance (ProOrder)

probuilder
// Convert an ATR distance in price units into whole points
atr = AverageTrueRange[14](close)
stopPoints = max(10, round((2 * atr) / pointsize))

IF NOT onmarket AND close > highest[20](high[1]) THEN
  BUY 1 CONTRACTS AT MARKET
ENDIF

SET STOP PLOSS stopPoints

The stop distance follows volatility, two ATRs converted into points with a 10-point floor, so quiet markets get tight stops and volatile markets get room to breathe.

Common errors and gotchas

  • Anchored to the average, not the last fill. After pyramiding or averaging down, the stop is measured from the new POSITIONPRICE. A stop that looked safe relative to the first entry can sit much closer to, or further from, the market than expected.
  • One stop slot. PLOSS, %LOSS, $LOSS, BREAKEVEN, and the trailing variants all write to the same internal stop. Only the most recent SET STOP call is active, so alternating variants per bar causes erratic exits.
  • Points are not cash or percent. x is a point count. Use SET STOP %LOSS for a percentage distance and SET STOP $LOSS for a cash amount. Passing a cash figure to PLOSS on an instrument with a small point size produces an absurdly wide stop.
  • Ideal fills in backtests. ProBacktest fills the stop exactly at the computed level. Live execution can slip past it on gaps or fast markets, so realized losses can exceed the tested x points.
  • %LOSS, stop loss as a percentage of the position price.
  • $LOSS, stop loss as a cash amount.
  • PPROFIT, take profit in points, the mirror instruction.
  • %PROFIT, take profit as a percentage.
  • BREAKEVEN, moves the stop or target to the entry price.
  • PTRAILING, trailing stop expressed in points.
  • POSITIONPRICE, the average entry price the distance is measured from.
  • POINTSIZE, the size of one point in price units.
  • STOP, overview of the stop instruction family.