%LOSS
The %LOSS instruction sets a stop loss as a percentage below the average position price with SET STOP %LOSS in ProRealTime™ ProBacktest and ProOrder code.
Syntax
SET STOP %LOSS xParameters
| Name | Type | Default | Description |
|---|---|---|---|
x | numeric | none | Percentage distance from the average position price at which the stop loss triggers. Accepts decimals, so 1.5 means 1.5 percent. |
How it works
%LOSS combines with SET STOP only. The instruction defines a stop loss as a relative distance: for a long position the exit level sits x percent below the average position price, and for a short position it sits x percent above it. Because the level derives from the position price rather than a fixed price, the same line of code adapts to any instrument and any entry level.
The instruction is declarative. Once it executes, the stop applies to the current position and to every future position the strategy opens, until another SET STOP call replaces it. Placing it once near the end of the code is the usual pattern. Calling SET STOP %LOSS 0 removes the stop.
When several orders are cumulated into one position, the percentage is computed from the average price of the whole position. On IG and PRT-CFD accounts the platform attaches the stop to each individual order, so each order carries its own protective level.
The target-side counterpart is SET TARGET %PROFIT. The inverted combinations, a stop placed in the profit zone or a target placed in the loss zone, are documented separately under Set Stop Profit and Set Target Loss.
Examples
Example 1, MACD entry with a 2 percent stop (ProBacktest)
myMACD = MACD[12,26,9](close)
long = myMACD crosses over 0
IF NOT LongOnMarket AND long THEN
BUY 1 CONTRACTS AT MARKET
ENDIF
// Protective stop 2 percent below the average position price
SET STOP %LOSS 2The strategy buys when the MACD line crosses above zero. Whatever the entry price turns out to be, the stop always sits 2 percent below it.
Example 2, Percent stop on a short position (ProOrder)
fast = Average[10](close)
slow = Average[40](close)
IF NOT ShortOnMarket AND fast crosses under slow THEN
SELLSHORT 1 CONTRACT AT MARKET
ENDIF
// For shorts the stop sits 1.5 percent ABOVE the position price
SET STOP %LOSS 1.5The same instruction protects short positions. The platform mirrors the distance automatically, so no sign change is needed in the code.
Example 3, Full percent bracket around the entry (ProOrder)
DEFPARAM CumulateOrders = false
rsiVal = RSI[14](close)
IF NOT OnMarket AND rsiVal < 30 THEN
BUY 1 CONTRACT AT MARKET
ENDIF
// Risk 1 percent, aim for 2 percent, a fixed 1:2 bracket
SET STOP %LOSS 1
SET TARGET %PROFIT 2Combining SET STOP %LOSS with SET TARGET %PROFIT builds a symmetric percent-based bracket that scales with the instrument price.
Common errors and gotchas
- Percent of price, not of equity.
SET STOP %LOSS 2risks 2 percent of the position price, not 2 percent of the account. On a leveraged position the equity impact can be far larger. Convert carefully when translating a risk-per-trade rule into this instruction. - Wrong SET pairing. The documented form is
SET STOP %LOSS. The percent target is a different keyword,SET TARGET %PROFIT. Mixing the two up either fails to compile or produces an exit on the wrong side of the entry. - Last SET STOP wins.
%LOSS,$LOSS,PLOSS,%TRAILINGandBREAKEVENall write to the same internal stop slot. Only the most recentSET STOPcall is active, so alternating between forms bar by bar leads to erratic exits. - Placement inside conditional blocks. Wrapping the instruction in an
IFthat is true on one bar only still works, because the setting persists, but re-executing it with a different value each bar silently reprices the stop. Keep it unconditional unless the reprice is intended.
Related instructions
$LOSS, stop loss as a fixed money amount.PLOSS, stop loss as a distance in points.%PROFIT, take profit as a percentage of the position price.%TRAILING, trailing stop as a percentage of the position price.BREAKEVEN, moves the stop or target to the entry price.STOP, pending stop orders and the SET STOP family.Set Target Loss, target placed in the loss zone, the inverted form.TRADEPRICE, entry price of a given trade.POSITIONPRICE, average price of the open position.LONGONMARKET, true while a long position is open.
