The %TRAILING instruction in ProBuilder language is used to set a trailing stop loss based on a percentage from the average position price. This feature is crucial for managing risk by allowing a position to remain open as long as the price is moving favorably, but automatically closing it if the price declines by a specified percentage.
SET STOP %TRAILING x
Where x represents the percentage distance from the current average price at which the stop loss should be set.
// Define moving averages
i1 = average(close)[100]
i2 = average(close)[5]
// Define entry and exit conditions
tradeinitiate = Close > i1 AND Close < i2 AND Low[3] > Low[2] AND Low[2] > Low[1] AND Low[1] > Low
tradeclose = Close > Close[1]
// Execute trade
IF NOT LongOnMarket AND tradeinitiate THEN
BUY 1 CONTRACTS AT MARKET
ENDIF
IF LongOnMarket AND tradeclose THEN
SELL AT MARKET
ENDIF
// Set a trailing stop loss at 1.5% from the current average price
SET STOP %TRAILING 1.5
This example demonstrates how to set a trailing stop loss at 1.5% from the current average price. The trading strategy involves buying when the current close is between a 100-period and a 5-period moving average and the last three lows are ascending. The position is closed when the current close is higher than the previous close. The trailing stop loss ensures that if the price drops by 1.5% from its highest point since the entry, the position will be closed to protect gains.
This instruction is essential for implementing risk management strategies in automated trading systems, helping to secure profits while limiting downside risk.