The 20-period EMA crossing the 50-period EMA opens a trade in the direction of the cross. A long closes when the 20 EMA drops back under the 50 EMA, a short when it climbs back above, and a 1% stop sits behind every trade.
Best run of 16. Gold, 1 hour, spread 0.6, from run pf:2026-09-15-GOLD-1h.tsv:3.
| Period | Up to 2026-09-15 |
| Instrument | Gold, 1 hour |
| Spread | 0.6 points |
| Contracts | 1 |
| Starting capital | 1,000,000 |
| Costs | Spread only. Commissions and overnight financing are not included. |
| Bars | Up to 200,000 bars, fewer where the instrument has less history |
| Last tested | 2026-09-15 |
| positionSize Contracts per trade | 1 |
| fastPeriod Fast EMA length | 20 |
| slowPeriod Slow EMA length | 50 |
| stopLossPct Protective stop, percent of entry price | 1 |
Every run
| Market | Timeframe | PF | Trades | Win % | Net | Max DD |
|---|---|---|---|---|---|---|
| GoldBest run | 1 hour | 1.22 | 1,288 | 29.74 | 2,194 EUR | -1,197 |
| Gold | 5 min | 1.11 | 1,966 | 26.70 | 1,165 EUR | -1,388 |
| Nasdaq 100 | 1 hour | n/a | 1,401 | 26.98 | 6,023 EUR | -6,902 |
| DAX 40 | 15 min | n/a | 1,940 | 28.66 | 4,448 EUR | -4,448 |
| Nasdaq 100 | 5 min | n/a | 1,885 | 27.11 | 3,611 EUR | -7,028 |
| S&P 500 | 1 hour | n/a | 1,341 | 28.78 | 835 EUR | -1,426 |
| Gold | 30 min | n/a | 1,984 | 27.57 | 805 EUR | -1,364 |
| S&P 500 | 30 min | n/a | 1,965 | 27.94 | 496 EUR | -1,149 |
| DAX 40 | 30 min | n/a | 2,022 | 29.53 | 81.60 EUR | -5,966 |
| DAX 40 | 1 hour | n/a | 1,311 | 27.08 | -291 EUR | -6,515 |
| S&P 500 | 15 min | n/a | 1,951 | 29.06 | -679 EUR | -1,754 |
| Gold | 15 min | n/a | 1,963 | 24.76 | -1,259 EUR | -2,012 |
| S&P 500 | 5 min | n/a | 1,929 | 23.74 | -1,424 EUR | -1,833 |
| Nasdaq 100 | 30 min | n/a | 2,046 | 27.52 | -5,055 EUR | -6,302 |
| Nasdaq 100 | 15 min | n/a | 2,014 | 28.55 | -5,075 EUR | -10,960 |
| DAX 40 | 5 min | n/a | 2,001 | 26.29 | -6,743 EUR | -6,898 |
Charts
Top 10 of 16 runs. The full list is in the table above.
Above 1.0 made money, below 1.0 lost money.
The code
// ============================================================ // EMA 20/50 Cross // ProRealAlgos Strategy Library | prorealalgos.com // Type: Trend // Direction: Long & short // Timeframe tested: 1 hour // ============================================================ // --- Settings --- DEFPARAM CumulateOrders = false // --- Parameters --- positionSize = 1 // contracts per trade fastPeriod = 20 // fast EMA length slowPeriod = 50 // slow EMA length stopLossPct = 1 // protective stop, percent of entry price // --- Indicators --- fastMA = ExponentialAverage[fastPeriod](close) slowMA = ExponentialAverage[slowPeriod](close)
25 more lines: the entry and exit rules.
Setup
Questions
Yes. The cross, the reverse cross exit and the 1% stop are all automated. The stats come from the pre-rewrite version, so demo test the new code first.
Gold 1 hour made 2,194.30 EUR over 1288 trades. Nasdaq 100 1 hour made 6,023.10 EUR but with a 6,901.70 EUR drawdown, while S&P 500 on 5 and 15 minutes lost.
With 1 contract and a 0.6 point spread, the Gold 1 hour run had a max drawdown of 1,196.80 EUR. Nasdaq 100 on 15 minutes reached 10,959.70 EUR.
The 20/50 pair reacts within a session on 5 minute to 1 hour bars. The 1 hour chart gave the best profit factor on Gold.
Related
The ProRealAlgos community gets the full rules, the complete code and the automated portfolio.