// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// VARIABLES
timeframe(default)
stepfactor1 = 0.5
stepfactor2 = 0.25
myPRCDynamicRSI, myPRCDynamicRSI2, myPRCDynamicRSI3, myPRCDynamicRSI4 = CALL "PRC_DynamicRSI"[0.1, 0.1, 14, 60]
DM = DEMA[14](close)
PST = Supertrend[2,10]
SL = PST - 0.25
PT = SL * 1.5
// Conditions to enter long positions
IF DM < PST AND myPRCDynamicRSI < myPRCDynamicRSI2 THEN
SELLSHORT 10 CONTRACTS AT MARKET
ENDIF
SET STOP pTRAILING SL
SET TARGET pPROFIT PT
QUIT
//====== Trailing Stop mechanism - start =====
trailingstart = (stepfactor1 * SL )
trailingstep = (stepfactor2 * SL )
//resetting variables when no trades are on market
if not onmarket then
priceexit = 0
endif
//case LONG order
if longonmarket then
//first move (breakeven)
IF priceexit=0 AND close-tradeprice(1) >= trailingstart*pointsize THEN
priceexit = tradeprice(1) + trailingstep*pointsize
ENDIF
//next moves
IF priceexit>0 THEN
P2 = close-priceexit >= trailingstart*pointsize
IF P2 THEN
priceexit = priceexit + trailingstep*pointsize
ENDIF
ENDIF
ENDIF
//case SHORT order
if shortonmarket then
//first move (breakeven)
IF priceexit=0 AND tradeprice(1)-close >= trailingstart*pointsize THEN
priceexit = tradeprice(1) - trailingstep*pointsize
ENDIF
//next moves
IF priceexit>0 THEN
P2 = priceexit-close >= trailingstart*pointsize
IF P2 THEN
priceexit = priceexit - trailingstep*pointsize
ENDIF
ENDIF
ENDIF
//exit on trailing stop price levels
if onmarket and priceexit>0 then
EXITSHORT AT priceexit STOP
SELL AT priceexit STOP
ENDIF
//====== Trailing Stop mechanism - end =====