Strategy vault / Mean reversion
SPY RSI Stochastics Crossover Reversal Trend Strategy
The SPY RSI Stochastics Crossover Reversal Trend Strategy is a quantitative trading strategy that uses RSI indicator crossovers between fast and slow lines to determine price reversals. The strategy combines slow…

Overview
The SPY RSI Stochastics Crossover Reversal Trend Strategy is a quantitative trading strategy that uses RSI indicator crossovers between fast and slow lines to determine price reversals. The strategy combines slow, fast and MA lines and generates buy and sell signals when certain conditions are met, in order to capture significant price reversal opportunities.
Strategy Logic
The core logic of this strategy is based on RSI fast and slow line crossovers. RSI usually reverses at overbought and oversold zones, so by determining the golden cross and death cross situations between the fast and slow RSI lines, we can identify possible price reversal points in advance. Specifically, the strategy mainly relies on the following indicators and conditions:
- Slow RSI Line: 64-period RSI line
- Fast RSI Line: 9-period RSI line
- RSI MA Line: 3-period simple moving average of fast RSI line
- RSI Overbought Threshold: parameter set to 83
- RSI Oversold Threshold: parameter set to 25
- RSI Neutral Zone: between 39 and 61
- Trading Hours: Monday to Friday 9:00am to next day 9:00am
When fast RSI crosses over slow RSI (golden cross) and fast line crosses over MA line, a buy signal is generated. When fast RSI crosses below slow RSI (death cross) and fast line crosses below MA line, a sell signal is generated.
In addition, the following logic is configured to filter out some noise trades:
- No trading signals generated within neutral RSI zone
- Only trade between Monday to Friday 9:00am to next day 9:00am
There are two exit conditions after entering:
- Close position when fast RSI enters the opposite region (overbought or oversold)
- Close position when reverse RSI crossover signal occurs
Advantage Analysis
The biggest advantage of SPY RSI Stochastics Crossover Reversal Trend Strategy is that it can capture the trend early before significant price reversals occur. Through fast and slow RSI line crossovers, it can issue trading signals ahead of time and create opportunities to enter the market. In addition, the strategy has the following advantages:
- Clear signal generation rules, easy to understand and track
- Dual filters designed to reduce noise signals
- Flexible overbought/oversold zone settings suit different market environments
- Combines both trend following and reversal capturing capabilities
In summary, by combining trend following and value reversal analysis, the strategy can capture price reversal timing to some extent, and has strong practicality.
Risk Analysis
Although SPY RSI Stochastics Crossover Reversal Trend Strategy has certain advantages, it also has the following main risks:
- Unable to completely avoid risks from noise trades despite dual filter design
- RSI crossovers not perfect at predicting actual reversal points, some difficulty exists
- Needs reasonable parameter settings, otherwise over-frequent or sparse trades may occur
- Black swan events leading to false breakouts cannot be fully avoided
To address the above risks, the strategy can be optimized and improved in the following aspects:
- Use machine learning algorithms to train optimal parameters and reduce noise signals
- Incorporate other technical indicators to improve reliability of crossover signals
- Add stop loss mechanisms to control per trade risk exposure
- Optimize adaptive updating of parameters to improve adaptability
Optimization Directions
The SPY RSI Stochastics Crossover Reversal Trend Strategy can mainly be optimized in the following areas:
- Parameter Optimization: Find optimal parameter combinations systematically via methods like genetic algorithms, grid search etc.
- Feature Engineering: Incorporate more price influencing features like volume changes, volatility etc. to aid decisions
- Machine Learning: Train crossover criteria with machine learning algorithms to improve accuracy
- Stop Loss Optimization: Introduce trailing stops, time stops etc. to control risks
- Adaptive Updating: Enable key parameters to adjust adaptively based on real-time market conditions
Such optimizations can make the strategy parameters more intelligent, signals more reliable, and also adjust rules according to market changes, thereby greatly improving the strategy's profit stability.
Conclusion
The SPY RSI Stochastics Crossover Reversal Trend Strategy designed a relatively simple and clear quantitative trading strategy system based on judging RSI fast and slow line crossovers. Combining both trend following and reversal trading features, it can capture price reversal timing to some degree. But the strategy also has some inherent flaws, requiring parameter, feature and model optimization to control risks and improve signal quality. With continuous optimizations, it can become a stable profitable quantitative system.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 64 | SLOW RSI Length |
| v_input_2 | 9 | FAST RSI Length |
| v_input_3 | 3 | RSI SMA Length |
| v_input_4 | 83 | RSI Upper |
| v_input_5 | 25 | RSI Lower |
| v_input_6 | 61 | RSI Upper Deadzone |
| v_input_7 | 39 | RSI Lower Deadzone |
| v_input_8 | 0900-0900 | Session Start |
Source Pine Script
/*backtest
start: 2024-01-23 00:00:00
end: 2024-02-22 00:00:00
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("SPY Auto RSI Stochastics", pyramiding = 3)
// Input parameters
slowRSILength = input(64, title="SLOW RSI Length")
fastRSILength = input(9, title="FAST RSI Length")
smaRSILength = input(3, title="RSI SMA Length")
RSIUpperThreshold = input(83, title="RSI Upper")
RSILowerThreshold = input(25, title="RSI Lower")
RSIUpperDeadzone = input(61, title='RSI Upper Deadzone')
RSILowerDeadzone = input(39, title='RSI Lower Deadzone')
blockedDays = (dayofweek(time) == 1 or dayofweek(time) == 7)
sessionMarket = input("0900-0900", title="Session Start")
allowedTimes() => time(timeframe = timeframe.period, session = sessionMarket, timezone = "GMT+1")
isvalidTradeTime =true
// RSI and ATR
slowRSI = ta.rsi(close, slowRSILength)
fastRSI = ta.rsi(close, fastRSILength)
smaRSI = ta.sma(fastRSI, smaRSILength)
rsi = fastRSI
// Entry condition
RSIUptrend() => ta.crossover(fastRSI, slowRSI) and ta.crossover(fastRSI, smaRSI)
RSIDowntrend() => ta.crossunder(fastRSI, slowRSI) and ta.crossunder(fastRSI, smaRSI)
isRSIDeadzone() =>
rsi < RSIUpperDeadzone and rsi > RSILowerDeadzone
isBullishEngulfing() =>
close > high[1]
isBearishEngulfing() =>
close < low[1]
// Declare variables
var float initialSLLong = na
var float initialTPLong = na
var float initialSLShort = na
var float initialTPShort = na
//var bool inATrade = false
entryConditionLong = RSIUptrend() and not isRSIDeadzone() and isvalidTradeTime
entryConditionShort = RSIDowntrend() and not isRSIDeadzone() and isvalidTradeTime
exitConditionLong = entryConditionShort or fastRSI > RSIUpperThreshold
exitConditionShort = entryConditionLong or fastRSI < RSILowerThreshold
if (entryConditionLong)
strategy.entry(id = "Long", direction = strategy.long, alert_message = 'LONG! beep boop, all aboard the long train')
if (entryConditionShort)
strategy.entry(id = "Short", direction = strategy.short, alert_message = 'Short! beep boop, all aboard the short train')
if (exitConditionLong)
strategy.exit("Long", from_entry="Long", limit=close, alert_message = 'Stop Long, halt halt, take the profits and runnn')
if (exitConditionShort)
strategy.exit("Short", from_entry="Short", limit=close, alert_message = 'Stop Short, halt halt, take the profits and runnn')
//plot(smaRSI, "RSI MA", color=color.red)
plot(slowRSI, "Slow RSI", color=color.green)
//plot(fastRSI, "Fast RSI", color=color.white)
plot(smaRSI, "SMA RSI", color=color.white)
Published by ChaoZhang on the FMZ strategy square · last modified 2024-02-23. 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/SPY-RSI-Stochastics-Crossover-Reversal-Trend-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
- BuySell Strategy depends on AOStochRSIATRPine Script · Mean reversion · 30m
- Dual Momentum Trend Reversal Strategy Based on RSI and Stochastic RSIPine Script · Mean reversion · 1h
- Dynamic Adaptive Multi Timeframe Trend Following and Range Reversal Hybrid StrategyPine Script · Mean reversion · 2d
- Momentum Reversal Trading Strategy 428631Pine Script · Mean reversion · 2h
- Moving Average and Stochastic RSI Combination Trading StrategyPine Script · Mean reversion · 1d
- Oma and Apollo Dual Rail Trading StrategyPine Script · Mean reversion · 5m