RSI overbought and oversold strategy
Loading the chart…
About this strategy
Buys when RSI climbs back above 30 and sells when it falls back below 70: a simple mean-reversion test of RSI levels.
This strategy tests the most common way RSI is read: below 30 the market is oversold, above 70 it is overbought. It does not trade the moment RSI touches a level. It waits for RSI to cross back: a long entry when RSI rises back above 30, and a short entry when it falls back below 70.
Waiting for the cross back is the point. In a strong trend RSI can stay overbought or oversold for a long time, and buying the first dip below 30 in a falling market is how this idea usually loses money. The backtest shows how often that happened on your symbol.
RSI uses 14 bars by default. Shorter lengths make it swing to the extremes more often, so the strategy trades more. Range-bound stocks and indices suit it better than strongly trending ones, so compare a few symbols and timeframes before drawing conclusions.
How to use it
- Click Use on chart to backtest it on your symbol and timeframe.
- Change the RSI length in its settings and see how the number of trades changes.
- Compare a range-bound stock with a strongly trending one.
Settings and what it draws
Settings
| Input | Type | Default |
|---|---|---|
| Input 1 | Whole number | 14 |
Draws in its own pane
- OversoldLevel
- OverboughtLevel
- RSILine
Source code
strategy("RSI levels", overlay=false, initial_capital=100000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, pyramiding=1)
// Inputs
rsiLength = input.int(14, "RSI length", minval=1, maxval=100)
// Calculations
rsi = ta.rsi(close, rsiLength)
crossUp = ta.crossover(rsi, 30)
crossDown = ta.crossunder(rsi, 70)
// Plots and signals
hline(30, "Oversold", color=#787B86, linestyle=hline.style_dashed)
hline(70, "Overbought", color=#787B86, linestyle=hline.style_dashed)
plot(rsi, "RSI", color=#7E57C2, linewidth=2)
// Orders
if crossUp
strategy.entry("Long", strategy.long)
if crossDown
strategy.entry("Short", strategy.short)
// @builder-graph v1 e2f98258
// Visual builder data. Edit the code freely; it will then open as plain code.
// eyJuIjoiUlNJIG92ZXJib3VnaHQgLyBvdmVyc29sZCBzdHJhdGVneSIsIm5vZGVzIjpbeyJpZCI6Im4xIiwidCI6ImRlY2xhcmUu
// c3RyYXRlZ3kiLCJ4Ijo0MCwieSI6NDAsInAiOnsidGl0bGUiOiJSU0kgbGV2ZWx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GxpbmUiLCJ4IjozMDQsInkiOjM1MiwicCI6eyJ0aXRsZSI6Ik92ZXJib3VnaHQiLCJjb2xvciI6IiM3ODdCODYi
// LCJzdHlsZSI6ImRhc2hlZCIsIndpZHRoIjoxLCJwcmljZSI6NzB9fSx7ImlkIjoibjExIiwidCI6InN0cmF0LmxvbmciLCJ4Ijo4
// MzIsInkiOjQwLCJwIjp7ImlkIjoiTG9uZyIsInF0eSI6MH19LHsiaWQiOiJuMTIiLCJ0Ijoic3RyYXQuc2hvcnQiLCJ4Ijo4MzIs
// InkiOjE4NCwicCI6eyJpZCI6IlNob3J0IiwicXR5IjowfX1dLCJlZGdlcyI6W1siZTEiLCJuMiIsIm91dCIsIm4zIiwibGVuZ3Ro
// Il0sWyJlMiIsIm4zIiwib3V0IiwibjYiLCJhIl0sWyJlMyIsIm40Iiwib3V0IiwibjYiLCJiIl0sWyJlNCIsIm4zIiwib3V0Iiwi
// bjciLCJhIl0sWyJlNSIsIm41Iiwib3V0IiwibjciLCJiIl0sWyJlNiIsIm4zIiwib3V0IiwibjgiLCJ2YWx1ZSJdLFsiZTciLCJu
// NCIsIm91dCIsIm45IiwicHJpY2UiXSxbImU4IiwibjUiLCJvdXQiLCJuMTAiLCJwcmljZSJdLFsiZTkiLCJuNiIsIm91dCIsIm4x
// MSIsIndoZW4iXSxbImUxMCIsIm43Iiwib3V0IiwibjEyIiwid2hlbiJdXX0=
Comments (0)
No comments yet. Be the first to say how it worked for you.
More built-in tools
See all-
Majority Rule
Majority Rule shows the percentage of the last bars that closed higher than the bar before. Majority Rule is a simple measure of how often price has gone up over a recent window, as a percentage of…
Other 101 -
Historical Volatility
Shows the annualised standard deviation of log price returns over the last N bars, as a percentage. Historical Volatility measures how much price has actually moved. It takes the logarithm of the…
Volatility 100 -
Double EMA
The double exponential moving average: an EMA built to remove part of the lag of a normal EMA. The Double Exponential Moving Average (DEMA) was introduced by Patrick Mulloy. It takes an EMA and an…
Trend 010