Dear community, Attached is my code for the DAX on a 3-minute basis, long only. It is kept very simple. The conditions are that the EMA 2 crosses above the EMA 4 while the EMA 20 is above the EMA 75. A very tight stop-loss of 0.15 is to be set once the profit reaches 0.25%. At 0.5% the position is closed. The backtest results show clear profits.
//-------------------------------------------------------------------------
// EMA_DAX (LONG ONLY)
// ATR-Filter + fixer TP + später aktivierter Schutz-SL + Hard Stop
//-------------------------------------------------------------------------
DEFPARAM CumulateOrders = false
DEFPARAM PreLoadBars = 1000
once ordersize = 0.5
// ----------------------------------------------------
// Handelszeit
// ----------------------------------------------------
tt = time >= 130000 AND time <= 220000
// ----------------------------------------------------
// Volatilitätsfilter
// ----------------------------------------------------
atrPeriod = 14
atr = AverageTrueRange[atrPeriod]
MinATRLong = 8
VolOKLong = atr > MinATRLong
// ----------------------------------------------------
// EMAs
// ----------------------------------------------------
ema2 = ExponentialAverage[2](close)
ema4 = ExponentialAverage[4](close)
ema20 = ExponentialAverage[20](close)
ema75 = ExponentialAverage[75](close)
// ----------------------------------------------------
// Long-Setup
// ----------------------------------------------------
cLongEntry = ema2 CROSSES OVER ema4
TrendLong = ema20 > ema75 AND close > ema75
// ----------------------------------------------------
// Entry
// ----------------------------------------------------
IF tt THEN
IF cLongEntry AND TrendLong AND VolOKLong AND NOT longonmarket THEN
BUY ordersize CONTRACTS AT MARKET
ENDIF
ENDIF
// ----------------------------------------------------
// Positionsmanagement
// ----------------------------------------------------
IF longonmarket THEN
entry = tradeprice(1)
// Reset bei neuer Position
IF longonmarket AND NOT longonmarket[1] THEN
maxProfit = 0
slActivated = 0 // <-- wichtig!
ENDIF
// Gewinn in %
currentProfit = (close - entry) / entry * 100
maxProfit = MAX(maxProfit, currentProfit)
// ------------------------------------------------
// TAKE PROFIT bei +0,50 %
// ------------------------------------------------
IF maxProfit >= 0.5 THEN
SELL AT MARKET
ENDIF
// ------------------------------------------------
// Aktivierung des Schutz-SL ab +0,25 %
// ------------------------------------------------
IF slActivated = 0 AND maxProfit >= 0.25 THEN
slActivated = 1
slPrice = entry * 1.0015
ENDIF
// Schutz-SL aktiv?
IF slActivated = 1 THEN
SELL AT slPrice STOP
ENDIF
// ------------------------------------------------
// Hard Stop - fester Eurobetrag
// ------------------------------------------------
euroRisk = 175
valuePerPoint = 0.5
stopPoints = euroRisk / valuePerPoint
hardStop = entry - stopPoints
IF low <= hardStop THEN
SELL AT MARKET
ENDIF
ENDIF
// ----------------------------------------------------
// Tagesende Exit
// ----------------------------------------------------
IF time >= 215500 AND longonmarket THEN
SELL AT MARKET
ENDIF