Identifies oversold conditions in large-cap stocks and bets on a price correction back to the 20-period moving average.
US Equities
5-Minute
RSI + SMA
Intermediate
Imagine stretching a rubber band. When you let it go, it snaps back to its normal shape. Financial markets often behave in a similar way. When the price of an asset (like a stock or cryptocurrency) moves sharply up or down, it has a tendency to "revert" back towards its average, historical value. This phenomenon is what we call mean reversion.
Your bot will try to profit from these "snap-backs" by identifying when prices have moved too far from their average and betting on a return to equilibrium.
Your "Price Magnet"
It's simply the average price over a specific number of recent candles (e.g., the last 50 hours). On a chart, it looks like a smoothed line that follows the price.
Purpose: It serves as your point of reference—the "mean" that the price will likely want to return to.
Your "Market Speedometer"
This is an indicator that measures how quickly and sharply the price has changed. It operates on a scale from 0 to 100.
Purpose: It tells you when the market is "overbought" (the price has risen too fast, RSI > 70) or "oversold" (the price has fallen too fast, RSI < 30).
Example trade setup on AAPL 5-minute chart
| Parameter | Recommended Value | Description |
|---|---|---|
| RSI_PERIOD | 14 | Standard RSI lookback period for momentum calculation |
| RSI_THRESHOLD | 30 | Oversold level trigger for entry signals |
| SMA_PERIOD | 20 | Moving average for trend confirmation and exit target |
| STOP_LOSS | 1.5% | Maximum loss per trade before automatic exit |
| VOLUME_MULTIPLIER | 1.2x | Required volume above average for trade validation |
| MAX_HOLD_TIME | 4 hours | Maximum position duration to avoid overnight risk |
The mean reversion strategy works beautifully when the market is moving sideways, in a limited range (in "consolidation"). The problem arises when a strong, one-directional trend begins—for example, after important economic news.
Imagine trying to pick up pennies from a railroad track just as a train is approaching. That's how this strategy behaves in a strong trend.
When the price starts to rise sharply, the RSI can remain in "overbought" territory (above 70) for a very long time. A naive bot, sticking to the rules, will stubbornly keep opening SELL positions, hoping for a "reversion." Each of these positions will generate a loss, and the sum of these losses can easily wipe out the profits from many previous successful trades.
Fortunately, you can make your bot much smarter. Here are three "upgrades" we recommend to help you avoid the trend trap.
You need to teach the bot to recognize when the market is in a strong trend and, at that point... simply do nothing.
Tool: The ADX (Average Directional Index) indicator.
How it works: ADX is like a "trend-o-meter." It doesn't tell you which way the trend is going, but it measures its strength. A high ADX (e.g., > 25) = a strong trend. A low ADX (< 25) = a sideways market.
The new rule: Enable the RSI Mean Reversion logic ONLY when the ADX is low. If the ADX is high, the bot should "wait it out" and not open any positions.
The 70 and 30 levels on the RSI are arbitrary. Sometimes the market is more volatile, and "overbought" might not start until RSI hits 80. How can you automate this?
Tool: Bollinger Bands.
How it works: Instead of rigid 70/30 levels, apply Bollinger Bands... directly onto the RSI indicator itself! This will create a dynamic channel that automatically adjusts to the current volatility.
The new rule: Open a BUY position when the RSI crosses below its own lower Bollinger Band. Open a SELL position when the RSI crosses above its own upper Bollinger Band.
Sometimes you might see a buy signal on the 1-hour chart, but a powerful downtrend is in full force on the daily chart. Swimming against the current rarely ends well.
How to do it: Before the bot opens a position, it must check what's happening on a higher timeframe.
The new rule: We recommend allowing the bot to open a BUY position on the 1-hour chart only if the price on the daily chart is above its long-term moving average (e.g., the 200-day MA). This ensures you're not fighting the main trend.
67.3%
1.84
1.23
-8.7%
12-month backtest on S&P 500 stocks (2023)
The RSI Mean Reversion strategy is a fantastic starting point for learning algorithmic trading. It's logical and easy to understand, but in its basic form, it's dangerous. The real art is in adding filters and safeguards that protect your capital from catastrophic losses.
Remember: In algorithmic trading, managing risk and understanding the weaknesses of your strategy is more important than the entry signal itself. Good luck building your first bot!
Disclaimer: Past performance is not indicative of future results. Trading involves risk and you should carefully consider your investment objectives, level of experience, and risk appetite.