// Step trailing stop parameters
trailingstart = 30 // Trailing will start when in profit by 30 points
trailingstep = 30// Trailing step to move the stop loss
initialStopLoss = 125 // Initial stop loss in points
takeProfit = 250 // Take profit in points
// Variable to store the new stop loss level for long and short positions
newSLlong = 0
newSLshort = 0
// Trading strategy logic based on the indicator signals
IF LongSignal AND Not OnMarket AND not daysForbiddenEntry THEN
BUY PositionSize CONTRACT AT MARKET
SET STOP pLOSS initialStopLoss
SET TARGET pPROFIT takeProfit
newSLlong = 0 // Reset the trailing stop level for long positions
ENDIF
IF ShortSignal AND Not OnMarket AND not daysForbiddenEntry THEN
SELLSHORT PositionSize CONTRACT AT MARKET
SET STOP pLOSS initialStopLoss
SET TARGET pPROFIT takeProfit
newSLshort = 0 // Reset the trailing stop level for short positions
ENDIF
// Manage step trailing stop for long positions
IF LONGONMARKET THEN
IF newSLlong = 0 AND close - tradeprice(1) >= trailingstart * pipsize THEN
newSLlong = tradeprice(1) + trailingstep * pipsize
ELSIF newSLlong > 0 AND close - newSLlong >= trailingstep * pipsize THEN
newSLlong = newSLlong + trailingstep * pipsize
ENDIF
IF newSLlong > 0 THEN
SELL AT newSLlong STOP
ENDIF
ENDIF
// Manage step trailing stop for short positions
IF SHORTONMARKET THEN
IF newSLshort = 0 AND tradeprice(1) - close >= trailingstart * pipsize THEN
newSLshort = tradeprice(1) - trailingstep * pipsize
ELSIF newSLshort > 0 AND newSLshort - close >= trailingstep * pipsize THEN
newSLshort = newSLshort - trailingstep * pipsize
ENDIF
IF newSLshort > 0 THEN
EXITSHORT AT newSLshort STOP
ENDIF
ENDIF