ProBacktest/probacktest · proorder

PROFIT

SET TARGET PROFIT in ProBacktest and ProOrder places a take profit a fixed number of price units from entry. PROFIT syntax, examples, and common errors.

Syntax

probuilder
SET TARGET PROFIT x

Parameters

NameTypeDefaultDescription
xnumbernoneDistance between the entry price and the take profit, expressed in price units of the instrument. Accepts literals, variables, and expressions.

How it works

SET TARGET PROFIT declares a pending take-profit order relative to the entry price of the position. For a long position the exit level sits x price units above the entry; for a short position it sits x units below. When price reaches the level, the position closes automatically.

The declaration is persistent. Once executed, it stays active for the current position and for positions opened later, until another SET TARGET call replaces it. Placing the instruction on its own line at the end of the code, outside any IF block, is the common pattern for a fixed target that applies to every trade. Wrapping it in conditions allows the target to change mid-trade, in which case the most recent call defines the active level.

The distance is measured in price units, one unit being the POINTSIZE of the instrument. For percent-based or cash-based targets, use the %PROFIT and $PROFIT variants instead of converting manually.

Examples

Example 1, MACD entry with a 50-unit target (ProBacktest)

probuilder
myMACD = MACD[12,26,9](close)
long = myMACD crosses over 0
IF NOT LongOnMarket AND long THEN
    BUY 1 CONTRACTS AT MARKET
ENDIF
// Close the position once it gains 50 price units
SET TARGET PROFIT 50

A long opens when the MACD line crosses above zero, and the take profit closes it 50 price units above the entry. This is the example from the official reference.

Example 2, Fixed bracket of target and stop (ProOrder)

probuilder
DEFPARAM CumulateOrders = false

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

// Fixed exit bracket around the entry price
SET TARGET PROFIT 120
SET STOP LOSS 60

Every position carries the same bracket, a take profit 120 units above entry and a stop 60 units below. Both declarations sit outside the entry block so they apply to all trades.

Example 3, Volatility-scaled target (ProOrder)

probuilder
atr = AverageTrueRange[14](close)

IF NOT onmarket AND RSI[14](close) < 30 THEN
  BUY 1 CONTRACT AT MARKET
  // Target distance adapts to recent volatility
  SET TARGET PROFIT ROUND(2 * atr)
ENDIF

The target distance is recomputed at entry as twice the current ATR, so quiet markets get tighter targets than volatile ones.

Common errors and gotchas

  • Price units, not points or percent. SET TARGET PROFIT measures its distance in price units of the instrument. For points use SET TARGET PPROFIT, for percent SET TARGET %PROFIT, for account currency SET TARGET $PROFIT. Mixing up the unit produces targets that are wildly too tight or too wide.
  • PROFIT does not read profit. The keyword only appears inside the SET instruction. To read the running result of a strategy or position, use STRATEGYPROFIT or POSITIONPERF; writing IF profit > 0 does not compile.
  • Distance, not level. The value is an offset from the entry price, not an absolute price. SET TARGET PROFIT 12000 on an index trading at 12050 creates a target 12000 units away, not a target at 12000.
  • The last call wins. Consecutive SET TARGET calls overwrite one another, only the most recent declaration is active. Conditional blocks that fire on the same bar can silently replace an intended target.
  • PPROFIT, take-profit distance in points.
  • %PROFIT, take-profit distance in percent.
  • $PROFIT, take-profit distance in account currency.
  • SET, prefix of all order management declarations.
  • TARGET, the take-profit side of the SET instruction.
  • LOSS, stop-loss distance in price units.
  • Set Target Loss, target order placed at a loss distance from entry.
  • STRATEGYPROFIT, realized profit of the strategy in account currency.
  • POSITIONPERF, performance of the open position.
  • TRADEPRICE, the entry price of the current position.