// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// Conditions to enter long positions
indicator1 = RSI[14](close)
c1 = (indicator1 < 30)
indicator2 = RSI[14](close)
c2 = (indicator2 > 86)
IF c1 THEN
BUY 1 CONTRACT AT MARKET
ENDIF
IF c2 THEN
sellshort 1 CONTRACT AT MARKET
ENDIF
// trailing stop function
trailingstep = 6 //5 trailing step to move the "stoploss" after BreakEven
startBreakeven = 2 //5 pips in gain to activate the breakeven function
PointsToKeep = 2 //3 pips to keep in profit above/below entry price when the breakeven is activated
//
//reset the stoploss value
IF NOT ONMARKET THEN
newSL = 0
breakevenLevel = 0
ENDIF
//******************************************************************************************************
// ----- BREAKEVEN code
//
//reset the breakevenLevel when no trade are on market
// --- LONG side
IF LONGONMARKET AND (close - tradeprice(1)) >= (startBreakeven * pipsize) AND breakevenlevel = 0 THEN
breakevenLevel = tradeprice(1) + (PointsToKeep * pipsize) //calculate the breakevenLevel
ENDIF
// --- SHORT side
IF SHORTONMARKET AND (tradeprice(1) - close) >= (startBreakeven * pipsize) AND breakevenlevel = 0 THEN
breakevenLevel = tradeprice(1) + (PointsToKeep * pipsize) //calculate the breakevenLevel
ENDIF
//Set new Stop Loss
IF breakevenLevel > 0 THEN
newSL = BreakEvenLevel
ENDIF
//******************************************************************************************************
// ----- TRAILING STOP code
//
//manage long positions
IF LONGONMARKET AND BreakEvenLevel THEN
//next moves after BreakEven
IF newSL > 0 AND ((close - newSL) >= (trailingstep * pipsize)) THEN
newSL = newSL + (trailingstep * pipsize)
ENDIF
ENDIF
//manage short positions
IF SHORTONMARKET AND BreakEvenLevel THEN
//next moves after BreakEven
IF newSL > 0 AND ((newSL - close) >= (trailingstep * pipsize)) THEN
newSL = newSL - (trailingstep * pipsize)
ENDIF
ENDIF
//stop order to exit the positions
IF newSL > 0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF