// Festlegen der Code-Parameter
DEFPARAM CumulateOrders = False // Kumulieren von Positionen deaktiviert
defparam preloadbars = 10000
defparam flatafter = 190000
// Verhindert das Trading an bestimmten Wochentagen
daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
timeframe(4 hour, updateonclose)
// Bedingungen zum Einstieg in Long-Positionen
indicator11 = MACDline[12,26,9](close)
indicator22 = ExponentialAverage[9](MACDline[12,26,9](close))
c3 = (indicator11 > indicator22)
// Bedingungen zum Einstieg in Short-Positionen
indicator33 = MACDline[12,26,9](close)
indicator44 = ExponentialAverage[9](MACDline[12,26,9](close))
c4 = (indicator33 < indicator44)
timeframe(5 minute, updateonclose)
c1 = (close > entrypricel)
c2 = (close < entryprices)
//long
IF time = 085500 and c3 THEN
EntryPricel = close - 30 * pipsize
ENDIF
IF not onmarket and time >= 090000 AND time <= 100000 and c1 and not daysforbiddenentry THEN
BUY 1 CONTRACT AT EntryPricel limit
SET TARGET %PROFIT 1.15
SET STOP %LOSS 0.85
ENDIF
//short
IF time = 085500 and c4 THEN
EntryPrices = close + 40 * pipsize
ENDIF
IF not onmarket and time >= 090000 AND time <= 100000 and c2 and not daysforbiddenentry THEN
sellshort 1 CONTRACT AT EntryPrices limit
SET TARGET %PROFIT 1.45
SET STOP %LOSS 0.75
ENDIF
//************************************************************************
//trailing stop function
trailingstart = 36 //50 trailing will start @trailinstart points profit
trailingstep = 2 //9 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