SET
SET in ProBacktest and ProOrder introduces order management commands such as SET TARGET PROFIT and SET STOP LOSS. Variants, syntax, and errors explained.
Syntax
SET TARGET PROFIT value
SET STOP LOSS valueParameters
| Name | Type | Default | Description |
|---|---|---|---|
value | number | none | Distance from the entry price at which the exit triggers, in the unit implied by the keyword that follows STOP or TARGET. Accepts literals, variables, and expressions. |
How it works
SET introduces the two families of exit declarations. SET STOP defines where the position closes at a loss, and SET TARGET defines where it closes at a profit. Each family accepts several unit keywords: LOSS and PROFIT measure the distance in price units, PLOSS and PPROFIT in points, %LOSS and %PROFIT in percent, $LOSS and $PROFIT in account currency. Beyond fixed distances, SET STOP also accepts the trailing variants TRAILING, PTRAILING, %TRAILING, and $TRAILING, and both sides accept BREAKEVEN.
A SET declaration is persistent. It applies to the currently open position and to every position opened afterwards, until another SET call on the same side replaces it. There are exactly two slots, one stop-side and one target-side; within a slot the most recent call wins. Written unconditionally at the end of the code, a declaration acts as a standing bracket on all trades. Written inside IF blocks, it adjusts the exit as the trade develops, which is how breakeven and profit-locking logic is expressed.
The values are distances from the entry price, not absolute price levels. For a long position the stop distance extends below the entry and the target distance above it; a short position mirrors both.
Examples
Example 1, Standing bracket on every trade (ProBacktest)
// Standing exit bracket, applies to each position the strategy opens
SET TARGET PROFIT 120
SET STOP LOSS 100Each trade carries a take profit 120 price units from entry and a stop 100 units from entry. This is the example from the official reference.
Example 2, Percent-based bracket (ProOrder)
DEFPARAM CumulateOrders = false
IF NOT onmarket AND close CROSSES OVER Average[50](close) THEN
BUY 1 CONTRACT AT MARKET
ENDIF
// Exit at plus 2 percent or minus 1 percent from entry
SET TARGET %PROFIT 2
SET STOP %LOSS 1The percent variants keep the bracket proportional to the instrument's price, which makes the same code reusable across differently priced markets.
Example 3, Tightening the stop as the trade works (ProOrder)
DEFPARAM CumulateOrders = false
IF NOT onmarket AND close CROSSES OVER highest[20](high)[1] THEN
BUY 1 CONTRACT AT MARKET
ENDIF
// Initial stop, replaced by a tighter trailing stop once in profit
IF onmarket AND close - tradeprice < 20 * pointsize THEN
SET STOP PLOSS 20
ELSIF onmarket THEN
SET STOP PTRAILING 10
ENDIFThe stop slot is rewritten each bar, a fixed 20-point stop early in the trade, then a 10-point trailing stop once the position is 20 points in profit. The latest SET call on the stop side is always the active one.
Common errors and gotchas
- SET is not assignment. Variables are assigned with
=, as ina = 10. SET only precedes order management keywords;SET a 10does not compile, andSTOP LOSS 100without SET does not compile either. - Distances, not price levels.
SET STOP LOSS 100places the stop 100 price units from entry, not at price 100. Absolute levels must be converted to a distance from TRADEPRICE first. - One slot per side, last call wins. Two
SET STOPlines that both execute on the same bar leave only the second one active. Overlapping IF blocks are the usual source of a stop that is silently different from what was intended. - Declarations outlive the trade. A SET call keeps applying to future positions until replaced. A conditional tightening that fires late in one trade carries over to the next trade's entry bar unless the code resets the bracket when flat.
Related instructions
STOP, the stop-loss side of the SET instruction.TARGET, the take-profit side of the SET instruction.BREAKEVEN, moves the stop or target to the entry price.TRAILING, trailing stop distance in price units.PTRAILING, trailing stop distance in points.Set Stop Profit, stop order placed at a profit distance from entry.Set Target Loss, target order placed at a loss distance from entry.PROFIT, take-profit distance in price units.LOSS, stop-loss distance in price units.PPROFIT, take-profit distance in points.PLOSS, stop-loss distance in points.
