Tested by BacktestingMax
RSI + 50 EMA strategy backtest
Does the RSI + 50 EMA strategy make money?
Mostly no. The strategy buys a dip in an uptrend. The uptrend: price is above the 50 EMA, a moving average of the last 50 closing prices. The dip: RSI, an indicator that scores how hard price has moved from 0 to 100, falls below 40 and then comes back above it. Sells use the opposite rules: price below the 50 EMA, and RSI back below 60. We ran 24 backtests: 8 markets, each on 15-minute, 1-hour and 4-hour charts, from 2019 to 2025, after trading costs. 8 of the 24 made money, but 4 of those 8 were 4-hour tests with fewer than 100 trades, too few to judge. With 100 trades or more, only 2 tests made money in both 2019–2022 and 2023–2025: the Nasdaq 100 (+40.2%) and gold (+10.4%), both on 1-hour charts. 7 of the 8 tests on 15-minute charts lost money. Does the 50 EMA filter make the RSI dip better? Not on 1-hour charts. It removed about 7 in every 8 trades, and more of the trades it kept were winners, but the average trade was a little worse. On daily charts, the setup almost never happened: 33 trades in 7 years, on all 8 markets together.
24 backtests 2019–2025 Trading costs included Tested 23 November 2026
Where it worked 24 backtests- Made money
- 4 of 24 tests, using the standard rules
- Made money in both periods
- 2 2019–2022 and again 2023–2025
- Best backtest
- +40% Nasdaq 100, 1-hour chart: account growth 2019–2025
- No RSI exit: take profit at 2R only
- 2 tests made money in both periods, compared with 2 using the standard rules
Made money in both periods
- Gold, 1-hour
- Nasdaq 100, 1-hour
The results
Results on every market
Each box shows one backtest of the RSI + 50 EMA using the standard rules, from 2019 to 2025, after trading costs: the % result, and a small chart of the account balance. The solid line is the account balance and the dashed line is the starting balance. Green results made money; red results lost money. Under each result: whether it made money in both 2019–2022 and 2023–2025, or passed all four of our checks (see "How a test passes" further down).
| Market | 15-minute | 1-hour | 4-hour |
|---|---|---|---|
| EUR/USD | −43% Lost money | −44% Lost money | −10% Too few trades |
| GBP/USD | −41% Lost money | −35% Lost money | +10% Too few trades |
| USD/JPY | −32% Lost money | +10% Made money overall, lost in one period | −2% Too few trades |
| AUD/USD | −77% Lost money | −6% Lost money | +10% Too few trades |
| Gold | −55% Lost money | +10% Made money in both periods | +11% Too few trades |
| Silver | −80% Lost money | −5% Lost money | −11% Too few trades |
| Nasdaq 100 | +8% Made money overall, lost in one period | +40% Passed all four checks | −0.4% Too few trades |
| S&P 500 | −36% Lost money | −22% Lost money | +8% Too few trades |
All the numbers, test by test
| Market | Chart | Trades | Win rate | Profit factor | Result | Max drawdown | 2019–2022 | 2023–2025 | Monte Carlo drawdown | Trading costs |
|---|---|---|---|---|---|---|---|---|---|---|
| EUR/USD | 15-minute | 821 | 39.1% | 0.89 | −43.3% | −56.0% | −38.4% | −7.9% | −60.4% | $4,675 |
| EUR/USD | 1-hour | 206 | 32.5% | 0.60 | −43.6% | −44.0% | −32.3% | −16.7% | −48.9% | $506 |
| EUR/USD | 4-hour | 42 | 28.6% | 0.64 | −9.9% | −10.7% | −7.7% | −2.4% | −16.3% | $59 |
| GBP/USD | 15-minute | 785 | 39.4% | 0.88 | −40.9% | −56.8% | −29.9% | −15.6% | −59.3% | $4,450 |
| GBP/USD | 1-hour | 212 | 34.4% | 0.70 | −35.1% | −39.5% | −23.4% | −15.3% | −42.9% | $580 |
| GBP/USD | 4-hour | 55 | 45.5% | 1.34 | +10.3% | −4.8% | +1.3% | +8.9% | −10.2% | $90 |
| USD/JPY | 15-minute | 713 | 40.5% | 0.92 | −32.4% | −39.3% | −9.9% | −25.0% | −53.6% | $4,064 |
| USD/JPY | 1-hour | 193 | 45.1% | 1.07 | +9.5% | −18.0% | +23.3% | −11.2% | −21.5% | $635 |
| USD/JPY | 4-hour | 48 | 39.6% | 0.93 | −2.0% | −11.1% | −4.2% | +2.3% | −13.1% | $53 |
| AUD/USD | 15-minute | 705 | 36% | 0.74 | −76.9% | −78.2% | −50.0% | −53.7% | −80.2% | $4,304 |
| AUD/USD | 1-hour | 191 | 40.8% | 0.95 | −5.5% | −13.9% | +4.1% | −9.3% | −26.9% | $887 |
| AUD/USD | 4-hour | 35 | 48.6% | 1.52 | +9.8% | −4.0% | +6.5% | +3.2% | −7.8% | $66 |
| Gold | 15-minute | 672 | 37.1% | 0.83 | −54.5% | −57.6% | −27.7% | −37.1% | −64.8% | $4,040 |
| Gold | 1-hour | 167 | 44.9% | 1.11 | +10.4% | −9.3% | +5.9% | +4.2% | −18.6% | $495 |
| Gold | 4-hour | 46 | 52.2% | 1.53 | +11.0% | −3.5% | +2.5% | +8.3% | −7.3% | $64 |
| Silver | 15-minute | 707 | 37.6% | 0.72 | −79.9% | −79.9% | −43.6% | −64.3% | −82.8% | $9,034 |
| Silver | 1-hour | 151 | 43% | 0.94 | −5.0% | −10.7% | −4.1% | −1.0% | −22.3% | $1,209 |
| Silver | 4-hour | 50 | 32% | 0.61 | −11.3% | −16.6% | −5.0% | −6.7% | −17.0% | $214 |
| Nasdaq 100 | 15-minute | 821 | 42.8% | 1.01 | +8.1% | −36.6% | +33.3% | −18.9% | −43.1% | $4,757 |
| Nasdaq 100 | 1-hour | 218 | 48.6% | 1.32 | +40.2% | −10.6% | +21.7% | +15.2% | −16.3% | $446 |
| Nasdaq 100 | 4-hour | 59 | 39% | 0.99 | −0.4% | −8.3% | +0.9% | −1.3% | −12.4% | $47 |
| S&P 500 | 15-minute | 772 | 38.3% | 0.92 | −36.3% | −54.5% | −18.4% | −22.0% | −56.0% | $3,886 |
| S&P 500 | 1-hour | 219 | 39.3% | 0.83 | −21.6% | −28.3% | −8.8% | −14.0% | −34.9% | $487 |
| S&P 500 | 4-hour | 69 | 47.8% | 1.23 | +8.2% | −4.1% | +7.4% | +0.7% | −11.0% | $67 |
Profit factor is the money won divided by the money lost. Above 1 means the test made money. Max drawdown is the biggest fall from the highest balance. 2019–2022 and 2023–2025 show the result in each period on its own. Monte Carlo drawdown: we shuffled the trades into a random order 1,000 times; in 95% of those runs, the worst drawdown was this number or less. Result is the change in the account, with the risk of each trade set to 1% of the account at that time.
The account balance
The best test and the middle test
What we found
What the 24 backtests show
With the standard rules, 2 of the 24 tests made money in both 2019–2022 and 2023–2025, with 100 trades or more. Both were on 1-hour charts. On the Nasdaq 100, the account grew 40.2% from 2019 to 2025: 21.7% in 2019–2022 and 15.2% in 2023–2025. It also passed all four of our checks (see 'How a test passes'). On gold, the account grew 10.4%: 5.9% and then 4.2%. On the currency pairs, the 1-hour tests did much worse. EUR/USD lost 43.6% and GBP/USD lost 35.1%. USD/JPY made 9.5%, but only because of 2019–2022: it lost 11.2% in 2023–2025. On the S&P 500, the 1-hour test lost 21.6%, so the strategy did not work on every stock index.
R is the amount one trade risks: 1% of the account when the trade opens. Does the 50 EMA make the RSI pullback better? We ran the same RSI rules without it: buy on every RSI cross back above 40, and sell on every cross back below 60. On 1-hour charts, the 50 EMA cut the trades from 12,318 to 1,557, and the share of winning trades rose from 35.6% to 40.9%. But the average trade did not improve: it lost 0.046R with the 50 EMA, and 0.032R without it. One reason is the RSI exit. With the trend, RSI reaches 70 (or 30) more easily. So with the 50 EMA, the RSI exit closed 23.0% of the trades, with an average win of 0.86R. Without it, the RSI exit closed only 8.4%, with an average win of 1.17R (see the comparison below).
On 4-hour charts, the 50 EMA did help the average trade: +0.039R with it, and +0.010R without it, over all 8 markets. But it left only 35 to 69 trades per market in 7 years, so no 4-hour test reached the 100 trades we need to judge a test. 4 of them made money in both 2019–2022 and 2023–2025: GBP/USD, AUD/USD, gold and the S&P 500. On daily charts, the setup almost never happened. For a daily RSI to fall below 40, price usually has to fall far enough to go below the 50 EMA too. From 2019 to 2025, the 8 markets together made only 33 daily trades with the 50 EMA, and 601 without it. USD/JPY made 1 trade in 7 years.
Should you wait for the 2R take-profit, or take profit when RSI reaches 70 (or 30 for a sell)? We tested both, from 2019 to 2025. With the RSI exit, 17.9% to 24.0% of the trades closed there before they reached the 2R take-profit, depending on the chart (see the table below). Without the RSI exit, fewer trades won: 33.4% instead of 40.9% on 1-hour charts. But the winning trades were bigger, and the average trade was a little better on all three charts. On 1-hour charts, it lost 0.035R instead of 0.046R. On 4-hour charts, it made 0.051R instead of 0.039R. With either exit, 8 of the 24 tests made money from 2019 to 2025.
Some traders also want the 50 EMA itself to rise before they buy, and to fall before they sell. We tested this as one more rule: the 50 EMA must be higher than it was 10 candles before for a buy, and lower for a sell. It cut the trades by about 40%, from 7,957 to 4,699 on all 24 tests. The average trade got worse on 15-minute charts (from −0.087R to −0.121R) and on 1-hour charts (from −0.046R to −0.086R). On 1-hour charts, the sells did worst: with this rule, they lost 0.225R each, compared with 0.094R with the standard rules.
Does the 50 EMA help?
More winners with the 50 EMA, but not a better average trade
These numbers add up the 8 markets on 1-hour charts, from 2019 to 2025. Both versions use the same RSI signals, stop-loss and exits. Without the 50 EMA, the strategy buys on every RSI cross back above 40, and sells short on every cross back below 60.
- Trades, with the 50 EMA (the standard rules)
- 1,557 40.9% of them were winners.
- Trades, without the 50 EMA
- 12,318 35.6% of them were winners.
- Average trade, with the 50 EMA
- −0.046R Without the 50 EMA: −0.032R.
R is the amount one trade risks: 1% of the account when the trade opens. Each average is the result of one trade after trading costs, in R, over every trade of the 8 tests. The RSI exit closed 23.0% of the trades with the 50 EMA, and 8.4% without it.
How the trades ended
About 6 trades in 10 ended at the stop-loss
With the standard rules, every trade ended at its stop-loss, at its 2R take-profit, or at the RSI exit (RSI at 70 for a buy, or 30 for a sell). These numbers add up the 8 markets on each chart, from 2019 to 2025. Each cell shows the share of trades that ended this way, and their average result in R.
| Chart | Stop-loss | 2R take-profit | RSI exit |
|---|---|---|---|
| 15-minute (5,996 trades) | 60.4%, −1.08R | 21.7%, +1.87R | 17.9%, +0.86R |
| 1-hour (1,557 trades) | 58.7%, −1.01R | 18.3%, +1.93R | 23.0%, +0.86R |
| 4-hour (404 trades) | 57.7%, −0.95R | 18.3%, +1.88R | 24.0%, +1.00R |
R is the amount one trade risks: 1% of the account when the trade opens. The results are after trading costs, so a trade at the stop-loss usually loses a little more than 1R, and a take-profit makes a little less than 2R. On 15-minute charts, some trades closed at a worse price than the stop-loss when price jumped past it. A stop-loss can also lose less than 1R, because the trade opens at the next candle's open, not at the signal candle's close.
The strategy
What the RSI + 50 EMA is
RSI + 50 EMA is a pullback strategy: it waits for price to move a little against the trend, then trades when the move with the trend starts again. It uses two indicators. The 50 EMA is a moving average of the last 50 closing prices that gives more weight to recent candles. Many traders read price above the 50 EMA as an uptrend, and price below it as a downtrend. RSI (Relative Strength Index) is an indicator that scores how hard price has moved, from 0 to 100, over the last 14 candles. In an uptrend, a dip of RSI below 40 shows a pullback. When RSI comes back above 40, the strategy buys. In a downtrend, it sells short when RSI comes back below 60. A short trade makes money if price falls.
- RSI
- 14 candles, on closing prices, with Wilder's smoothing (the standard RSI). Entry levels 40 (buys) and 60 (sells). Exit levels 70 (buys) and 30 (sells). We calculated RSI and the 50 EMA ourselves, on the same candles as the rules (see 'Price data').
- 50 EMA
- The 50-candle EMA of the closing price. A buy needs the signal candle to close above it. A sell needs it to close below it. The first value of the EMA is the first closing price, and no trade opens before the 100th candle.
- Stop-loss
- The recent swing: the lowest low of the last 10 candles for a buy, and the highest high for a sell, the signal candle included. Traders say 'the recent swing' without a number, so 10 candles is our choice. The stop-loss does not move.
- Take-profit
- 2 times the stop-loss distance, measured from the close of the signal candle. It does not move. The RSI exit can close the trade earlier.
- Risk per trade
- 1% of the account at that time. In the results, we call this amount R. The account started at $10,000. The trade size is rounded down to a size the market allows. The value of a trade can be at most 30 times the account (this limit is called leverage). When the stop-loss is very close, a 1% risk needs a bigger trade than that, so the trade is cut to the limit and risks less than 1%. With the standard rules, this happened to 200 trades on 15-minute charts, and to none on 1-hour and 4-hour charts. A loss can also be bigger than 1% when price jumps past the stop-loss. 55 trades lost more than 1.5R on 15-minute charts (49 of them on silver), and 5 on 1-hour charts.
- Signals while a trade is open
- With the standard rules, 8,696 signals passed both entry rules (the RSI cross and the 50 EMA). 708 of them came while a trade was open, so they were ignored. 61 of these 708 came on a candle where the open trade also hit its stop-loss or take-profit. Our backtest engine checks for a signal before it closes the trade, so these 61 signals were ignored as well.
- Smallest trade size
- Each market has a smallest trade: 1,000 units of a currency pair, 1 ounce of gold, 50 ounces of silver or 0.1 of an index contract. When the trade that risks 1% would be smaller than that, the backtest skips the signal. With the standard rules, this happened 30 times: 28 times on 15-minute charts (24 of them on silver), and twice on silver's 1-hour chart. On the Nasdaq 100's 15-minute chart, 1 more order did not open, because the account did not have enough money set aside for it (the margin a broker asks for).
- Trading costs
- The spread: the gap between the buy price and the sell price. Currency pairs: 0.8 pips on EUR/USD, 1.2 on GBP/USD, 0.9 on USD/JPY and 1.0 on AUD/USD (a pip is 0.0001, or 0.01 on USD/JPY). Metals: $0.30 an ounce on gold and $0.020 on silver. Stock indices: 0.4 points on the S&P 500 and 1.5 on the Nasdaq 100. For silver and the Nasdaq 100, these are wider than our backtest engine's default spreads, to match a typical retail broker. Our spreads stay the same at all times, but real spreads widen around news and at the daily rollover. No commission. The entry and the RSI exit are market orders, so each pays half the spread. A trade that closes at its stop-loss also pays half the spread. The take-profit is a limit order: it pays no spread, but it fills only when price trades through the limit. Our charts show the sell price (the bid), and the buy price (the ask) is one spread higher. So the take-profit of a sell, which is a buy order, fills only when the chart price goes one spread below it.
- Overnight fees
- Not included. Brokers charge a fee (a swap), or sometimes pay one, for each night a trade stays open past 17:00 New York time. With the standard rules, half of the trades lasted longer than about 2 hours on 15-minute charts, 13 hours on 1-hour charts and 2.8 days on 4-hour charts. So these fees would change the 4-hour results most, and they could make a result better or worse.
- Price data
- CFD prices: the prices a broker quotes for a CFD (contract for difference), the product most brokers outside the US offer for trading these markets. We start in 2019 because our index prices before mid-2018 often did not move outside stock exchange hours. The strategy skips two kinds of candle, and these candles don't count for RSI, the 50 EMA or the recent swing. First, on some Fridays, the data has a few minutes of prices after the weekly close at 17:00 New York time, which make a tiny extra candle. Second, some candles show no price change at all (the high equals the low), for example on market holidays.
- Silver data
- On 1 June 2023, our silver data has 7 minutes with no trading, from 21:41 to 21:47 UTC, at prices 1.4% to 1.5% above the last price with trading. With the standard rules, one 15-minute sell closed at its stop-loss at 21:42, for a loss of 0.07R. With the change 'Only when the 50 EMA is rising (or falling)', one 15-minute buy opened at 21:45 and later lost 0.93R. These trades change silver's results by less than 1 percentage point.
The rules we tested
- Use RSI over the last 14 candles and a 50 EMA, both on closing prices. We check the rules when each candle closes, and a trade opens at the next candle's open.
- Buy when the candle closes above the 50 EMA and RSI crosses back above 40. That means RSI was below 40 at the close of the candle before, and is 40 or higher at this close.
- Sell short when the candle closes below the 50 EMA and RSI crosses back below 60. That means RSI was above 60 at the close of the candle before, and is 60 or lower at this close.
- Put the stop-loss at the recent swing: the lowest low of the last 10 candles for a buy, and the highest high of the last 10 candles for a sell. The 10 candles include the signal candle, the candle where the entry rules are met.
- Put the take-profit 2 times as far from the signal candle's close as the stop-loss. This is called a 2R take-profit: it wins 2 times the amount the trade risks.
- Also close the trade at the next candle's open when a candle closes with RSI at 70 or higher (for a buy), or at 30 or lower (for a sell). The trade closes at the first of three exits: the stop-loss, the take-profit or this RSI exit.
- Risk 1% of the account on each trade. Hold one trade at a time: signals that come while a trade is open are ignored. The stop-loss and the take-profit don't move.
The method
How we tested it
The test
- Markets
- EUR/USD, GBP/USD, USD/JPY, AUD/USD, Gold, Silver, Nasdaq 100 and S&P 500
- Charts
- 15-minute, 1-hour and 4-hour candles
- Dates
- January 2019 to December 2025
- Account
- $10,000, risking 1% of the account on each trade
- Trading costs
- Included. Every trade pays that market's normal trading cost: the spread, which is the gap between the buy price and the sell price.
How a test passes
We call a test passed only if it meets all four checks. A strategy can make money in one backtest and still fail one of these checks.
- At least 100 trades. With fewer trades, a good result could be luck.
- It made money from 2019 to 2022 and again from 2023 to 2025. This shows whether the strategy kept working in the newer years, not only in the older ones.
- A profit factor (the money won divided by the money lost) of at least 1.2 from 2023 to 2025, after trading costs.
- In 95% of 1,000 random shuffles of the trades, the account must not fall more than 30% from its highest point.
Improvements
Can the RSI + 50 EMA be improved?
We tried three changes traders often make to the RSI + 50 EMA strategy, one at a time, on the same 24 tests. One removes the 50 EMA, to see what it adds. One changes the exit. One adds a rule about the direction of the 50 EMA. If you pick the best change and judge it on the same years, it will almost always look good. So we picked the best one in 2019–2022 only, by the number of tests that made money, and then checked it in 2023–2025.
| Version | Made money 2019–2022years used to pick the best version | Made money 2023–2025years not used to pick it | Made money in both periods | Passed all four checks |
|---|---|---|---|---|
| Standard rules The rules under 'The rules we tested', with nothing changed. | 10 of 24middle test −4.6% | 7 of 24middle test −8.6% | 2 | 1 |
| Without the 50 EMA Buy on every RSI cross back above 40, and sell short on every RSI cross back below 60, whether price is above or below the 50 EMA. The stop-loss and the exits stay the same. | 8 of 24middle test −30.8% | 6 of 24middle test −19.0% | 3 | 0 |
| No RSI exit: take profit at 2R onlyBest on 2019–2022 A trade ends only at its stop-loss or its 2R take-profit. It does not close when RSI reaches 70 (or 30). The entries stay the same. | 11 of 24middle test −1.8% | 6 of 24middle test −7.9% | 2 | 2 |
| Only when the 50 EMA is rising (or falling) Buy only when the 50 EMA is higher than it was 10 candles before, and sell short only when it is lower. The other rules stay the same. | 7 of 24middle test −6.2% | 8 of 24middle test −3.4% | 1 | 1 |
Not clearly. In 2019–2022, the years we used to pick, taking profit at 2R only did best: 11 of 24 tests made money with it, compared with 10 with the standard rules. In 2023–2025, the years we kept for the check, it made money in 6 of 24, compared with 7. The middle test in 2023–2025 (half of the 24 did better, half did worse) was −7.9% with it, and −8.6% with the standard rules. With the 2R take-profit only, the same 2 tests as with the standard rules made money in both periods: gold and the Nasdaq 100 on 1-hour charts. Both passed all four of our checks. Without the 50 EMA, 3 tests made money in both periods: EUR/USD and USD/JPY on 4-hour charts, and the Nasdaq 100 on the 1-hour chart. But the middle test lost 30.8% in 2019–2022, and 7 of the 8 accounts on 15-minute charts lost more than 90%. The rule that the 50 EMA must be rising (or falling) made money in 8 of 24 tests in 2023–2025, the most of the four versions. But it made money in only 7 in 2019–2022. With it, only gold on the 1-hour chart made money in both periods.
Passed all four checks with no RSI exit: take profit at 2R only
- Gold, 1-hour
- Nasdaq 100, 1-hour
Questions
Questions traders ask
Does the RSI + 50 EMA strategy work?
Not in most of our backtests. From 2019 to 2025, after trading costs, it made money in 8 of 24 tests: 8 markets, each on 15-minute, 1-hour and 4-hour charts. Only 2 made money in both 2019–2022 and 2023–2025 with 100 trades or more: the Nasdaq 100 (+40.2%) and gold (+10.4%), both on 1-hour charts. The entry rules: buy when price is above the 50 EMA and RSI(14) crosses back above 40, and sell short when price is below it and RSI crosses back below 60.
Does the 50 EMA filter make the RSI strategy better?
Not on 1-hour charts. It made more of the trades winners, but the average trade was a little worse. On 1-hour charts, 40.9% of the trades won with the 50 EMA, and 35.6% without it. But the average trade lost 0.046R with it, and 0.032R without it (R is the amount one trade risks, 1% of the account). On 4-hour charts, the 50 EMA did help: +0.039R per trade, compared with +0.010R. On both charts, it cut the number of trades by about 7 in 8.
What is the best timeframe for the RSI + 50 EMA strategy?
In our tests, 1-hour charts did best. They gave the only tests with 100 trades or more that made money in both 2019–2022 and 2023–2025: the Nasdaq 100 and gold. 7 of 8 tests lost money on 15-minute charts. On 4-hour charts, 4 of 8 tests made money in both periods, but each made only 35 to 69 trades in 7 years. That is fewer than the 100 trades we need to judge a test. On daily charts, the setup came only 33 times in 7 years, on all 8 markets together.
Should you take profit at RSI 70 or at 2R?
From 2019 to 2025, waiting for the 2R take-profit gave a slightly better average trade on 15-minute, 1-hour and 4-hour charts. Without the RSI exit, fewer trades won (33.4% instead of 40.9% on 1-hour charts), but the winning trades were bigger. The trades closed by the RSI exit made 0.86R to 1.00R on average, about half of a 2R take-profit (R is the amount one trade risks, 1% of the account). But it is not clearly better. With either exit, 8 of the 24 tests made money from 2019 to 2025. In 2023–2025, the 2R-only version made money in 6 tests, against 7 with the RSI exit.
Keep exploring
Related strategies we tested
RSI Best RSI settings: 24 RSI settings backtested on 6 markets Made money in 4 of 18 tests, 3 of them in both periods. Best: S&P 500, 1-hour, +62% RSI RSI + Bollinger Bands strategy backtest Made money in 5 of 30 tests, 4 of them in both periods. Best: EUR/GBP, 4-hour, +35% RSI RSI overbought/oversold strategy backtest Made money in 4 of 24 tests, 2 of them in both periods. Best: DAX, 1-hour, +92% RSI RSI divergence strategy backtest Made money in 5 of 24 tests, 2 of them in both periods. Best: DAX, 1-hour, +49% MACD MACD + 200 EMA strategy backtest Made money in 8 of 40 tests, 5 of them in both periods. Best: Gold, 1-hour, +30% Moving averages Best EMA crossover: 7 EMA pairs backtested on 10 markets Made money in 11 of 40 tests, 5 of them in both periods. Best: USD/JPY, 1-hour, +167%The strategy code we ran
This is the exact code from the BacktestingMax strategy engine. Paste it into the strategy editor in the app to run it on any market.
class Rsi50Ema(Strategy):
"""RSI + 50 EMA pullback: buy when RSI comes back up from a dip, but only in an uptrend
(price above the 50 EMA), and the mirror for sells. Plus three common changes.
RSI (14, Wilder's way): the first average gain and average loss are the simple mean of the
first 14 changes in the close; after that avg = (avg * 13 + newest) / 14. RSI = 100 - 100 /
(1 + average gain / average loss), and 100 when the average loss is 0. The 50 EMA is the EMA
of the closes over 50 candles: the newest close counts 2 / (50 + 1), the rest is the EMA of
the candle before; it starts at the first close, as the built-in EMA does.
Standard (all switches off), checked when each candle closes:
Buy at the next candle's open when
- the candle closes above the 50 EMA,
- and RSI crosses back above 40 on this candle (RSI was below 40 on the candle before
and is 40 or higher now).
Sell short at the next candle's open when the candle closes below the 50 EMA and RSI
crosses back below 60 (it was above 60 on the candle before and is 60 or lower now).
Stop-loss at the recent swing: the lowest low of the last 10 candles for a buy (the
highest high for a sell), the signal candle included. It does not move.
Take-profit at 2R: 2 times the stop-loss distance, measured from the signal candle's
close. It does not move.
RSI exit: a buy is closed at the next candle's open after a candle closes with RSI at 70
or higher; a sell after a candle closes with RSI at 30 or lower.
Whichever of the stop-loss, the take-profit and the RSI exit comes first ends the trade.
One trade at a time: a signal while a trade is open is skipped.
Size: the trade loses 1% of the account if the stop-loss is hit.
No trade until 100 candles have been used, the same start for every version.
Skipped candles: a flat candle (high = low: no price moved, e.g. a market holiday) and a
candle that opens on a Friday at 17:00 New York time or later, before the Sunday open (some
index data has a few minutes of prices after the weekly close). The strategy ignores them
completely: they do not go into the EMA, the RSI or the swing, and they are never signal
candles. That is why the EMA and the RSI are worked out here instead of with the built-in
indicators. On a market that trades at the weekend (crypto), remove the weekend part of the
skip.
The changes, one at a time:
no_ema = 1 no 50 EMA filter: buy on every RSI cross back above 40 and sell on every
cross back below 60, wherever price is versus the EMA
tp_only = 1 no RSI exit: a trade ends only at its stop-loss or its 2R take-profit
slope = 1 also require the 50 EMA to be rising for a buy (higher than 10 candles ago)
and falling for a sell (lower than 10 candles ago)
"""
params = {"rsi_period": Param(type=int, default=14, min=2, max=100),
"ema_period": Param(type=int, default=50, min=2, max=300),
"buy_level": Param(type=float, default=40.0, min=1.0, max=60.0),
"sell_level": Param(type=float, default=60.0, min=40.0, max=99.0),
"exit_long": Param(type=float, default=70.0, min=50.0, max=99.0),
"exit_short": Param(type=float, default=30.0, min=1.0, max=50.0),
"swing_bars": Param(type=int, default=10, min=2, max=50),
"target_r": Param(type=float, default=2.0, min=0.5, max=10.0),
"no_ema": Param(type=int, default=0, min=0, max=1),
"tp_only": Param(type=int, default=0, min=0, max=1),
"slope": Param(type=int, default=0, min=0, max=1)}
lookback = 2
min_candles = 100
def init(self, ctx):
self.ny = ctx.clock("America/New_York")
self.count = 0 # candles used so far
self.trend = None # the 50 EMA
self.emas = [] # the last 11 values of the 50 EMA (for the slope)
self.prev_close = None # close of the candle used before
self.changes = 0 # closes changes seen so far
self.gain_sum = 0.0 # sums of the first 14 changes (seed of Wilder's average)
self.loss_sum = 0.0
self.avg_gain = None
self.avg_loss = None
self.prev_rsi = None # RSI on the candle used before
self.lows = [] # lows and highs of the last 10 candles used
self.highs = []
@staticmethod
def step(ema, value, length):
"""One EMA step: the newest value counts 2 / (length + 1)."""
return value if ema is None else ema + 2.0 / (length + 1) * (value - ema)
def update_rsi(self, close, n):
"""Wilder's RSI on the candles used; None until n changes have been seen."""
if self.prev_close is None:
self.prev_close = close
return None
change = close - self.prev_close
self.prev_close = close
gain, loss = max(change, 0.0), max(-change, 0.0)
self.changes += 1
if self.avg_gain is None:
self.gain_sum += gain
self.loss_sum += loss
if self.changes < n:
return None
self.avg_gain, self.avg_loss = self.gain_sum / n, self.loss_sum / n
else:
self.avg_gain = (self.avg_gain * (n - 1) + gain) / n
self.avg_loss = (self.avg_loss * (n - 1) + loss) / n
if self.avg_loss == 0:
return 100.0
return 100.0 - 100.0 / (1.0 + self.avg_gain / self.avg_loss)
def on_bar(self, ctx):
p = ctx.params
# A flat candle, or a candle after the weekly close: ignore it completely.
wd, hour = self.ny.weekday, self.ny.hour
after_close = (wd == 4 and hour >= 17) or wd == 5 or (wd == 6 and hour < 17)
if ctx.high[0] == ctx.low[0] or after_close:
return
c = ctx.close[0]
self.count += 1
self.trend = self.step(self.trend, c, p.ema_period)
self.emas = (self.emas + [self.trend])[-11:]
rsi = self.update_rsi(c, p.rsi_period)
r1, self.prev_rsi = self.prev_rsi, rsi
self.lows = (self.lows + [ctx.low[0]])[-p.swing_bars:]
self.highs = (self.highs + [ctx.high[0]])[-p.swing_bars:]
if self.count < self.min_candles or rsi is None:
return
# RSI exit: the close fills at the next candle's open. The stop-loss and the
# take-profit are the engine's own and fire on their own.
pos = ctx.position
if pos is not None and p.tp_only == 0:
if (pos.is_long and rsi >= p.exit_long) or (pos.is_short and rsi <= p.exit_short):
ctx.close_position()
# the signal check below still runs, so skipped signals are counted
if r1 is None:
return
buy_signal = r1 < p.buy_level <= rsi
sell_signal = r1 > p.sell_level >= rsi
if not ctx.gate("rsi_crosses_back", buy_signal or sell_signal):
return
if buy_signal and sell_signal:
return
side = 1 if buy_signal else -1
with_trend = c > self.trend if side == 1 else c < self.trend
if not ctx.gate("with_the_50_ema", p.no_ema == 1 or with_trend):
return
if p.slope == 1:
old = self.emas[0] if len(self.emas) == 11 else None
rising = old is not None and ((self.trend > old) if side == 1 else (self.trend < old))
if not ctx.gate("50_ema_slope", rising):
return
if not ctx.gate("signal_while_open", pos is None):
return
stop = min(self.lows) if side == 1 else max(self.highs)
if not ctx.gate("stop_on_the_right_side", (stop < c) if side == 1 else (stop > c)):
return
size = ctx.size_by_risk_pct(0.01, stop=stop, entry=c)
if not ctx.gate("size_at_least_the_minimum", size > 0):
return
tp = c + side * p.target_r * abs(c - stop)
if side == 1:
ctx.buy(size=size, sl=stop, tp=tp, tag="rsi50ema_long")
else:
ctx.sell(size=size, sl=stop, tp=tp, tag="rsi50ema_short")
Your turn
Test the RSI + 50 EMA yourself
Change the settings, the market or the stop-loss and see the result in seconds. Ask the BacktestingMax AI: Backtest the RSI + 50 EMA pullback strategy (RSI 14 crossing back above 40 above the 50 EMA, stop-loss at the 10-candle swing, take-profit at 2R) on the Nasdaq 100, 1-hour chart
.
Free account. No credit card needed.
See every strategy we tested Browse strategies shared by tradersBacktest on historical data with trading costs, run by BacktestingMax. Past results do not guarantee future results, and nothing here is financial advice. Updated 23 November 2026.