DEFPARAM CumulateOrders = FALSE
ONCE EntryShort = 0
ONCE EntryLong = 0
IF Time = 090000 THEN //currently LONDON is 1 hour behind CET
EntryLong = close + 40 * pipsize
EntryShort = close - 40 * pipsize
ENDIF
IF OnMarket OR (StrategyProfit <> StrategyProfit[1]) THEN
EntryLong = 0
EntryShort = 0
ENDIF
IF OnMarket AND Time = 190000 THEN //currently LONDON is 1 hour behind CET
SELL AT Market
EXITSHORT AT Market
ENDIF
IF EntryLong THEN
BUY 1 Contract AT EntryLong STOP
SET STOP pLOSS 80
SET TARGET pPROFIT 240
ENDIF
IF EntryShort THEN
SELLSHORT 1 Contract AT EntryShort STOP
SET STOP pLOSS 80
SET TARGET pPROFIT 240
ENDIF
//************************************************************************
//trailing stop function
//
// https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/
//
trailingstart = 60 //trailing will start @trailinstart points profit
trailingstep = 60 //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