Strategy vault / Mean reversion
RSI Reversal Strategy
The RSI reversal strategy calculates the RSI indicator and smoothed moving average to determine if a stock is overbought or oversold, thereby generating buy and sell signals. This strategy leverages the reversal…

Overview
The RSI reversal strategy calculates the RSI indicator and smoothed moving average to determine if a stock is overbought or oversold, thereby generating buy and sell signals. This strategy leverages the reversal characteristic of the RSI indicator to profit when stock prices reverse.
Strategy Logic
The strategy first calculates the 14-period RSI and normalizes it to 0-100. Then it calculates the 5-period weighted moving average of RSI, and maps it to -1 to 1 using the tangent function. When the mapped RSI crosses above -0.8, a buy signal is generated. When it crosses below 1, a sell signal is generated. The mapping and threshold judgement methods are used here to detect the reversal signals of the RSI indicator.
The strategy also sets the running month and date range so that it only runs during specified months and dates.
Advantages
- Utilizes the reversal characteristic of RSI indicator to generate trading signals at price reversal points and capture reversal opportunities.
- Mapping and threshold judgement on RSI make the signals clearer.
- Configurable running months and dates, flexible to utilize.
Risks
- RSI reversal signals may have false signals, resulting in incorrect trading signals. This can be reduced by adjusting RSI parameters or adding other filters.
- Relying solely on a single RSI indicator makes it vulnerable to fake signals. Adding other indicators or factors can improve strategy stability.
- Fixed months and date range may miss trading opportunities during other time periods. More flexible running time can be configured.
Optimization Directions
- Test more parameter combinations to find optimal matches between RSI and moving average periods.
- Add indicators like volume or volatility to confirm reversal signals and reduce false signals.
- Optimize and adjust the running months and date range to cover more trading opportunities.
- Add stop loss mechanisms to control risks.
Summary
The RSI reversal strategy effectively captures price reversal opportunities by constructing simple reversal trading rules based on the RSI indicator. The strategy is easy to implement, but can be enhanced via parameter optimization, risk control mechanisms etc, making it a stable profitable quantitative trading strategy.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 14 | RSI Main Period |
| v_input_2 | 5 | RSI Smooth Period |
| v_input_3 | 6 | monthfrom |
| v_input_4 | 12 | monthuntil |
| v_input_5 | true | dayfrom |
| v_input_6 | 31 | dayuntil |
Source Pine Script
/*backtest
start: 2023-01-12 00:00:00
end: 2024-01-18 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=3
strategy(title="RSI Reverse", shorttitle="RSI Reverse")
RSI_main = input(14, title="RSI Main Period")
RSI_smooth = input(5, title="RSI Smooth Period")
//Functions
RVS(input) => (exp(2*input)-1) / (exp(2*input)+1)
//RSI Calculation
raw_RSI=0.1*(rsi(close,RSI_main)-50)
wma_RSI=wma(raw_RSI,RSI_smooth)
RVS_RSI = RVS(wma_RSI)
threshold1 = RVS_RSI < 0.8? 1 : 0
threshold2 = -0.8
plot(RVS_RSI,color=red)
plot(threshold1,color=blue)
plot(threshold2,color=blue)
buycon = crossover(RVS_RSI,threshold2)
sellcon = crossunder(RVS_RSI , threshold1)
monthfrom =input(6)
monthuntil =input(12)
dayfrom=input(1)
dayuntil=input(31)
if ( buycon )
strategy.entry("BUY", strategy.long, stop=close, oca_name="TREND", comment="BUY")
else
strategy.cancel(id="BUY")
if ( sellcon)
strategy.close("BUY")
Published by ChaoZhang on the FMZ strategy square · last modified 2024-01-19. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.
Build this with AgenKit
A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/RSI-Reversal-Strategy.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- Get tests, backtest, risk controls and a paper-trading switch
Understand it first
Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.
Related specs
- ATR and EMA based Dynamic Take Profit and Stop Loss Adaptive StrategyPine Script · Mean reversion · 1h
- Adaptive Mean Reversion Trading Strategy Based on Chande Momentum OscillatorPine Script · Mean reversion · 1d
- Adaptive RSI Oscillator Dynamic Trading Strategy with Threshold OptimizationPine Script · Mean reversion · 1d
- Advanced 15 Minute Chart Trading Signal StrategyPine Script · Mean reversion · 3h
- Advanced Fibonacci Retracement Trend Following and Reversal Trading StrategyPine Script · Mean reversion · 3h
- Advanced Momentum EMA Trend Following with RSI Overbought Oversold Trading StrategyPine Script · Mean reversion · 1d