ProBacktest/probacktest · proorder

Set Stop Profit

Set Stop Profit places a stop at a set profit distance from entry in ProBacktest and ProOrder, in points, percent, currency, or price units, locking in gains.

Syntax

probuilder
SET STOP PPROFIT x
SET STOP %PROFIT x
SET STOP $PROFIT x
SET STOP PROFIT x

Parameters

NameTypeDefaultDescription
xnumbernoneProfit distance between the entry price and the stop, in the unit implied by the variant, points, percent, account currency, or price units.

How it works

A normal SET STOP LOSS places the stop on the losing side of the entry. Set Stop Profit inverts that: the stop is placed at a profit distance from the entry, above the entry for a long position and below it for a short. Once active, the position can no longer close at a loss, if price retraces to the stop level the trade exits with x units of profit secured.

The command is a generalization of SET STOP BREAKEVEN, which is the special case of locking exactly zero. Set Stop Profit locks a chosen positive amount instead. The four variants only differ in how the distance is measured: PPROFIT counts points, %PROFIT a percentage of the entry price, $PROFIT an amount of account currency, and PROFIT price units of the instrument.

Timing is the critical detail. A stop placed on the profit side of the entry is only meaningful once price has already moved beyond that level. Called too early, the stop level sits on the wrong side of the current price and the position closes immediately. The instruction therefore always sits behind a guard that checks both an open position and a sufficient open gain.

Examples

Example 1, Locking 10 points once the trade has run (ProOrder)

probuilder
// After 20 points of gain, guarantee at least 10 points of profit
IF longonmarket AND close - tradeprice >= 20 * pointsize THEN
  SET STOP PPROFIT 10
ENDIF

Once the long is 20 points in profit, the stop moves to 10 points above entry. The trade can now end no worse than 10 points ahead. The SET STOP PPROFIT 10 call follows the example from the official reference, wrapped in the required guards.

Example 2, Percent-based profit lock (ProOrder)

probuilder
DEFPARAM CumulateOrders = false

IF NOT onmarket AND close CROSSES OVER Average[50](close) THEN
  BUY 1 CONTRACT AT MARKET
  SET STOP %LOSS 1
ENDIF

// Once up 2 percent, lock in 1 percent of profit
IF longonmarket AND close >= tradeprice * 1.02 THEN
  SET STOP %PROFIT 1
ENDIF

The trade starts with a regular 1 percent stop loss. After a 2 percent gain, the stop flips to the profit side and secures 1 percent, replacing the initial stop.

Example 3, Staged profit locking in price units (ProBacktest)

probuilder
// Raise the locked profit in steps as the trade extends
IF longonmarket THEN
  gain = close - tradeprice
  IF gain >= 100 THEN
    SET STOP PROFIT 50
  ELSIF gain >= 50 THEN
    SET STOP PROFIT 20
  ENDIF
ENDIF

The locked amount ratchets up with the open gain, 20 units secured after a 50-unit move, 50 units after a 100-unit move. Ordering the conditions from largest to smallest keeps the highest lock active.

Common errors and gotchas

  • Called before the gain exists. If the open profit is smaller than x, the stop level lies beyond the current price and the position exits at once. Always pair the command with a condition on the open gain, such as close - tradeprice >= threshold.
  • One stop slot. Set Stop Profit writes to the same internal stop as SET STOP LOSS, the trailing variants, and SET STOP BREAKEVEN. The most recent call wins, so mixing profit locks with a trailing stop on alternating bars produces erratic exits.
  • Unit mix-ups across variants. PPROFIT is points, %PROFIT percent, $PROFIT account currency, PROFIT price units. On instruments where point size and price unit differ, the wrong variant places the lock far from the intended level.
  • Locked profit is not guaranteed live. Backtests fill the stop exactly at its level. Live stops can slip in fast markets, so the realized profit can be slightly below the locked amount.
  • Set Target Loss, the mirrored command, a target placed at a loss distance.
  • SET, prefix of all order management declarations.
  • STOP, the protective-stop side of the SET instruction.
  • PPROFIT, profit distance measured in points.
  • %PROFIT, profit distance measured in percent.
  • $PROFIT, profit distance measured in account currency.
  • PROFIT, profit distance measured in price units.
  • BREAKEVEN, locks exactly zero, the special case of this command.
  • TRADEPRICE, the entry price of the current position.