DefParam CumulateOrders = False
Once EMAPeriod = 26
Once ADXPeriod = 6
Once TStart = 20 //Trailing Start
Once TStep = 2 //Trailing Step
a=exponentialaverage [EMAPeriod] (high) //Upper Grab
b=exponentialaverage [EMAPeriod] (low) //Lower Grab
c=ADX[ADXPeriod] //Average Directional Index
If Close > a and Close[1] < a and c > 25 then //Start UpTrend and ADX>25
Buy 1 contract at Market
EndIf
if Close < b and Close[1] > b and c > 25 then //Start DownTrend and ADX>25
SellShort 1 contract at Market
EndIf
//************************************************************************
//trailing stop function
trailingstart = TStart //trailing will start @trailinstart points profit
trailingstep = TStep //trailing step to move the "stoploss"
//reset the stoploss value
IF NOT ONMARKET THEN
newSL=0
ENDIF
//manage long positions
IF LONGONMARKET THEN
//first move (breakeven)
IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
newSL = tradeprice(1)+trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
newSL = newSL+trailingstep*pipsize
ENDIF
ENDIF
//manage short positions
IF SHORTONMARKET THEN
//first move (breakeven)
IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN
newSL = tradeprice(1)-trailingstep*pipsize
ENDIF
//next moves
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
//************************************************************************