Strategy vault / Mean reversion
RSI Divergence Strategy 442346
The RSI Divergence strategy utilizes the Relative Strength Index (RSI) to identify potential price reversals by spotting divergences between price movements and RSI trends. It focuses on: Bullish Divergence: Occurs…

Overview
The RSI Divergence strategy utilizes the Relative Strength Index (RSI) to identify potential price reversals by spotting divergences between price movements and RSI trends. It focuses on:
Bullish Divergence: Occurs when price hits a new low while RSI does not, signaling weakening downward momentum and potential upward reversal.
Bearish Divergence: Happens when price makes a new high while RSI does not, indicating decreasing upward momentum and potential downward reversal.
This strategy combines overbought and oversold RSI levels to optimize entry and exit points, aiming to capture market reversals for improved trading accuracy and profitability. Suitable for various trading instruments, it's a valuable tool for traders aiming to buy lows and sell highs in fluctuating markets.
Strategy Logic
The RSI Divergence strategy is based on the following key judgments:
Calculate RSI Value: Compute RSI in the range of 0-100 based on average gain and average loss over a specific period.
Identify Overbought/Oversold: RSI above overbought level (e.g. 70) indicates overbought; RSI below oversold level (e.g. 30) indicates oversold.
Detect Divergence: Check if latest price movement is consistent with RSI movement. If price makes new high/low but RSI does not, it shows divergence.
Combine Entry/Exit: Bullish divergence with oversold RSI signals long entry. Bearish divergence with overbought RSI signals short entry.
Set Profit Target/Stop Loss: Close position for profit when RSI re-enters overbought/oversold zone.
By comparing price fluctuation and RSI change to gauge market strength, the strategy aims to profit from market inefficiency.
Advantages
The RSI Divergence Strategy has the following pros:
Capture Reversals: Excellent in detecting divergences between price and RSI to identify exhaustion reversals.
Optimize with Overbought/Oversold Levels: Combining intrinsic overbought/oversold in RSI helps fine tune entries and exits.
Simple and Easy to Implement: Relatively simple logic and parameter settings make this strategy intuitive to understand and implement.
Wide Versatility: Applicable to a variety of products like CFDs, crypto and stocks for broad adoption.
Boost Profitability: The systematic approach results in lower drawdowns for stable long term returns.
Risks
The RSI Divergence Strategy also bears the following risks:
False Signal Risks: Divergences do not certainly reverse or sustain - risk of acting on false signals.
Parameter Optimization Difficulties: Results are sensitive to RSI period, overbought/oversold levels etc requiring rigorous testing.
Exceptional Market Conditions: Strategy tends to fail when markets spike irregularly or the setup is overused.
Lagging Indicator: Technical indicators like RSI are generally lagging and unable to precisely determine reversal points.
Strict risk control, adaptive parameters and combined analysis with other factors can mitigate the risks to some extent.
Enhancement Opportunities
The RSI Divergence strategy can be further optimized via:
Testing RSI Input Values: Backtest different RSI lookback periods to find ideal parameters.
Combining Other Indicators: Adding confluence from MACD, KD etc improves signal accuracy.
More Stop Loss Techniques: Complement exiting profit target stop loss with methods like moving average envelope stop loss.
Wider Products Adaptability: Tweak parameters for better strategy alignment with more product types like commodities.
Applying Deep Learning: Use Deep Learning models like RNNs to judge RSI divergences and forecast prices.
Conclusion
The RSI Divergence captures mean-reverting opportunities by comparing price dynamics against RSI flows. The simple robust strategy works across asset classes for scalable short term reversals and excess returns. But its efficacy also carries inherent limitations requiring constant iterations for market adaptability.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 14 | RSI Length |
| v_input_2 | 70 | Overbought Level |
| v_input_3 | 30 | Oversold Level |
Source Pine Script
/*backtest
start: 2024-02-13 00:00:00
end: 2024-02-20 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("RSI Divergence Strategy", overlay=true)
// RSI Parameters
rsiLength = input(14, "RSI Length")
overboughtLevel = input(70, "Overbought Level")
oversoldLevel = input(30, "Oversold Level")
rsiValue = ta.rsi(close, rsiLength)
// Divergence detection
priceLow = ta.lowest(low, rsiLength)
priceHigh = ta.highest(high, rsiLength)
rsiLow = ta.lowest(rsiValue, rsiLength)
rsiHigh = ta.highest(rsiValue, rsiLength)
bullishDivergence = low < priceLow[1] and rsiValue > rsiLow[1]
bearishDivergence = high > priceHigh[1] and rsiValue < rsiHigh[1]
// Strategy Conditions
longEntry = bullishDivergence and rsiValue < oversoldLevel
longExit = rsiValue > overboughtLevel
shortEntry = bearishDivergence and rsiValue > overboughtLevel
shortExit = rsiValue < oversoldLevel
// ENTER_LONG Condition
if (longEntry)
strategy.entry("Long Entry", strategy.long)
// EXIT_LONG Condition
if (longExit)
strategy.close("Long Entry")
// ENTER_SHORT Condition
if (shortEntry)
strategy.entry("Short Entry", strategy.short)
// EXIT_SHORT Condition
if (shortExit)
strategy.close("Short Entry")
Published by ChaoZhang on the FMZ strategy square · last modified 2024-02-21. 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-Divergence-Strategy-442346.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