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.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
//------------------------------------------------------------------------- // 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 |
Share this
No information on this site is investment advice or a solicitation to buy or sell any financial instrument. Past performance is not indicative of future results. Trading may expose you to risk of loss greater than your deposits and is only suitable for experienced investors who have sufficient financial means to bear such risk.
ProRealTime ITF files and other attachments :PRC is also on YouTube, subscribe to our channel for exclusive content and tutorials

Thanks a lot for sharing this code. The way you combine an EMA trend filter with an ATR filter and then manage the trade with a small fixed TP, a late protective stop and a hard stop defined in euros is very instructive. It’s a simple but well-structured concept, and that’s rare enough.
The performance is excellent on the time window you posted, but outside that range the edge basically disappears. With slightly different EMA settings (EMA7, EMA13, EMA22, EMA77) the performance is positive from 2020 onwards, but it remains more of a research framework than a plug-and-play system for me. So I really wanted to say thank you for sharing it here.
Thanks for sharing, I think that currentProfit must be “currentProfit = (close – entry) / (entry / 100) ” for the right calculation