The $TRAILING instruction in ProBuilder language is used to set a trailing stop loss for a trading position. A trailing stop loss is a type of stop order that moves with the market price and is set at a specified distance away from the current market price. Its primary purpose is to protect gains by enabling a trade to remain open and continue to profit as long as the price is moving in a favorable direction, but automatically closes the trade if the market price changes direction by a certain amount.
SET STOP $TRAILING x
Where x represents the loss in the currency of the traded instrument.
// Define moving averages for trading signals
indis i1 = average(close)[100]
indis i2 = average(close)[5]
// Define trade initiation condition
tradeinitiate = Close > i1 AND Close < i2 AND Low[3] > Low[2] AND Low[2] > Low[1] AND Low[1] > Low
// Execute buy order if conditions are met and no long position is currently held
IF NOT LongOnMarket AND tradeinitiate THEN
BUY 1 CONTRACTS AT MARKET
// Set a trailing stop loss at $100 from the current price
SET STOP $TRAILING 100
ENDIF
This example demonstrates how to initiate a buy order based on specific conditions involving moving averages and price lows. If these conditions are met and there is no existing long position, a buy order is placed, and a trailing stop loss is set at $100 from the current market price to protect any accrued profits.