ProBacktest/probacktest · proorder

PRICE

PRICE places a stop loss or take profit at an absolute price level in ProBacktest and ProOrder through the SET STOP PRICE and SET TARGET PRICE commands.

Syntax

probuilder
SET STOP PRICE x
probuilder
SET TARGET PRICE x

Parameters

NameTypeDefaultDescription
xnumeric expressionrequiredThe absolute price level at which the stop loss or take profit is placed.

How it works

Most members of the stop and target families express the exit as a distance from the average position price, in points (PLOSS, PPROFIT), percent (%LOSS, %PROFIT), or cash ($LOSS, $PROFIT). The PRICE variant works differently: the argument is the exact price at which the exit order sits, independent of where the position was entered. This suits strategies built around chart levels, such as swing lows, prior session extremes, or round numbers identified in advance.

The level can be a literal or any numeric expression, so it can be recalculated bar by bar from indicator values. Once set, the level stays where it is until the next SET STOP or SET TARGET call replaces it; an absolute level never follows the market on its own.

Direction matters. For a long position the stop belongs below the current price and the target above it; for a short the sides are reversed. Both instructions share their slot with the other variants of the same family, so the most recent SET STOP call defines the stop and the most recent SET TARGET call defines the target.

Examples

Example 1, Fixed exit levels around a position (ProBacktest)

probuilder
// Exit at a loss if the market falls to 100
SET STOP PRICE 100

// Take profit if the market rises to 150
SET TARGET PRICE 150

The two levels bracket a long position between the absolute prices 100 and 150, regardless of the entry fill. These are the reference statements from the source documentation with rewritten comments.

Example 2, Stop below a swing low (ProOrder)

probuilder
// Place the stop just below the lowest low of the last 20 bars
swingLow = lowest[20](low)

IF NOT onmarket AND close CROSSES OVER average[50](close) THEN
  BUY 1 CONTRACTS AT MARKET
  SET STOP PRICE swingLow
ENDIF

Instead of a fixed distance, the stop is anchored to a chart structure, the 20-bar swing low that existed at entry time, a level with technical meaning rather than an arbitrary point count.

Example 3, Target at the previous session high (ProOrder)

probuilder
// Aim an intraday long at yesterday's high
IF NOT onmarket AND close CROSSES OVER average[20](close) AND close < dhigh(1) THEN
  BUY 1 CONTRACTS AT MARKET
ENDIF

IF longonmarket THEN
  SET TARGET PRICE dhigh(1)
ENDIF

The entry is only taken while price remains under yesterday's high, and the take profit sits exactly at that level, a common intraday objective.

Common errors and gotchas

  • Level on the wrong side of the market. A stop price above the market on a long, or a target below it, is inconsistent with the position and can close the trade immediately or be rejected. Validate computed levels against the current price before setting them.
  • Direction reversal on shorts. For short positions the stop belongs above the market and the target below. Reusing long-side level logic without flipping the comparison places both exits on the wrong side.
  • Static levels never move. Unlike trailing variants, an absolute level stays fixed until the code issues another SET call. Anchoring to an indicator requires re-executing the instruction whenever the level should update.
  • Slot overwrites. SET STOP PRICE replaces any earlier PLOSS, %LOSS, $LOSS, trailing, or breakeven stop, and SET TARGET PRICE replaces earlier targets. Mixing distance-based and price-based calls leaves only the most recent one active.
  • STOP, overview of the stop instruction family.
  • TARGET, overview of the target instruction family.
  • PLOSS, stop loss as a point distance from the entry.
  • PPROFIT, take profit as a point distance from the entry.
  • %LOSS, stop loss as a percentage distance.
  • %PROFIT, take profit as a percentage distance.
  • BREAKEVEN, moves the stop or target to the entry price.
  • TRADEPRICE, entry price of an individual order.
  • POSITIONPRICE, average entry price of the open position.
  • Lowest, lowest value over a lookback, useful for swing-low stops.