ProBacktest/probacktest · proorder

TARGET

TARGET sets a take-profit level in ProBacktest and ProOrder via SET TARGET PROFIT x, closing the open position automatically once x points of gain are reached.

Syntax

probuilder
SET TARGET PROFIT x

Parameters

NameTypeDefaultDescription
xnumericnoneProfit distance from the entry price, expressed in points. Scale it to the instrument's point size.

How it works

SET TARGET PROFIT x registers a take-profit order at x points from the entry price of the position, above entry for longs and below entry for shorts. When price reaches that level, the engine closes the position without any further code. The distance is measured from TRADEPRICE, so the same statement works for both directions.

The instruction configures the position rather than placing a one-off order. Declaring it in the code path that opens the trade is the usual pattern, and the target stays attached to the position until it is hit, until the position closes for another reason, or until a later SET TARGET statement replaces it. The most recent call always wins.

The unit is points. For a distance in account currency use the $PROFIT variant, and for a percentage of the entry price use %PROFIT. The opposite tool, a target placed at a losing level to escape a bad trade at a controlled price, is documented under Set Target Loss, and BREAKEVEN can move the target to the entry price.

Examples

Example 1, MACD entry with a 20-point target (ProOrder)

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

IF NOT LongOnMarket AND long THEN
  BUY 1 CONTRACTS AT MARKET
  // Close the trade automatically after 20 points of profit
  SET TARGET PROFIT 20
ENDIF

A long opens when the MACD crosses above zero, and the engine closes it once price has gained 20 points from the entry. This is the reference example for the instruction.

Example 2, Volatility-scaled target (ProBacktest)

probuilder
atr = AverageTrueRange[14](close)
// Express the target in points as a multiple of ATR
targetPoints = ROUND(2 * atr / pointsize)

IF NOT onmarket AND close crosses over average[50](close) THEN
  BUY 1 CONTRACT AT MARKET
  SET TARGET PROFIT targetPoints
ENDIF

Instead of a fixed number, the target adapts to recent volatility, two ATRs converted into points. Wider markets get wider targets, quiet markets tighter ones.

Example 3, Full bracket with stop and target (ProOrder)

probuilder
IF NOT onmarket AND close > highest[20](high)[1] THEN
  BUY 1 CONTRACT AT MARKET
  SET STOP LOSS 15
  // Reward twice the risk
  SET TARGET PROFIT 30
ENDIF

A breakout entry protected on both sides. The stop risks 15 points and the target aims for 30, a fixed 2:1 reward-to-risk bracket.

Common errors and gotchas

  • Points, not currency. The distance is in points, so SET TARGET PROFIT 20 means 20 points, not 20 euros or dollars. On instruments with small point sizes the intended level can be far off. Use $PROFIT for cash distances.
  • Last call wins. Each SET TARGET statement overwrites the previous one for the position. A statement executed unconditionally on every bar silently replaces any adaptive target set at entry.
  • No position, delayed effect. Called while flat, the setting applies to the next position that opens. That is often intended, but it can attach a stale target computed bars earlier to a fresh trade.
  • Exact-fill assumption. ProBacktest fills the target exactly at the level. Live fills through ProOrder can differ around gaps and fast moves, so backtested target strategies tend to look slightly better than live results.
  • STOP, the stop-loss counterpart configured with SET STOP LOSS.
  • BREAKEVEN, moves the stop or target to the entry price.
  • Set Target Loss, target placed at a losing level to exit at a controlled loss.
  • Set Stop Profit, stop placed at a winning level to lock in gains.
  • %PROFIT, take profit expressed as a percentage of the entry price.
  • $PROFIT, take profit expressed in account currency.
  • TRAILING, trailing stop that follows price at a fixed point distance.
  • TRADEPRICE, entry price the target distance is measured from.