Strategy vault / Mean reversion
Adaptive RSI Oscillator Dynamic Trading Strategy with Threshold Optimization
This strategy is an adaptive trading system based on the Relative Strength Index (RSI), which optimizes trade signal generation through dynamic adjustment of overbought and oversold thresholds. The core innovation…

Overview
This strategy is an adaptive trading system based on the Relative Strength Index (RSI), which optimizes trade signal generation through dynamic adjustment of overbought and oversold thresholds. The core innovation lies in the introduction of Bufi's Adaptive Threshold (BAT) method, which dynamically adjusts RSI trigger thresholds based on market trends and price volatility, thereby improving the effectiveness of traditional RSI strategies.
Strategy Principles
The core concept is upgrading traditional fixed-threshold RSI systems to dynamic threshold systems. Implementation details:
- Using short-period RSI to calculate market overbought/oversold conditions
- Calculating price trend slope through linear regression
- Measuring price volatility using standard deviation
- Integrating trend and volatility information to dynamically adjust RSI thresholds
- Raising thresholds in uptrends and lowering them in downtrends
- Reducing threshold sensitivity when prices deviate significantly from means
The strategy includes two risk control mechanisms:
- Fixed-period position closing
- Maximum loss stop-loss
Strategy Advantages
- Strong Dynamic Adaptability:
- Automatically adjusts trading thresholds based on market conditions
- Avoids drawbacks of fixed parameters in different market environments
- Comprehensive Risk Control:
- Maximum holding time limits
- Capital stop-loss protection
- Percentage-based position management
- Improved Signal Quality:
- Reduces false signals in oscillating markets
- Enhances trend capture capability
- Balances sensitivity and stability
Strategy Risks
- Parameter Sensitivity:
- BAT coefficient selection affects strategy performance
- RSI period settings require thorough testing
- Adaptive length parameters need optimization
- Market Environment Dependence:
- May miss opportunities in high volatility markets
- Significant slippage possible during extreme volatility
- Parameters need adjustment for different markets
- Technical Limitations:
- Relies on historical data for threshold calculation
- Potential lag in signal generation
- Trading costs need consideration
Strategy Optimization Directions
- Parameter Optimization:
- Introduce adaptive parameter selection mechanisms
- Dynamically adjust parameters for different market cycles
- Add automatic parameter optimization functionality
- Signal Optimization:
- Incorporate additional technical indicators for validation
- Add market cycle identification functionality
- Optimize entry timing determination
- Risk Control Optimization:
- Implement dynamic stop-loss mechanisms
- Optimize position management strategies
- Add drawdown control mechanisms
Summary
This innovative adaptive trading strategy addresses the limitations of traditional RSI strategies through dynamic threshold optimization. The strategy comprehensively considers market trends and volatility, featuring strong adaptability and risk control capabilities. While challenges exist in parameter optimization, continuous improvement and optimization make this strategy promising for actual trading. Traders are advised to conduct thorough backtesting and parameter optimization before live implementation, with appropriate adjustments based on specific market characteristics.
Source Pine Script
/*backtest
start: 2019-12-23 08:00:00
end: 2024-11-11 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © PineCodersTASC
// TASC Issue: October 2024
// Article: Overbought/Oversold
// Oscillators: Useless Or Just Misused
// Article By: Francesco P. Bufi
// Language: TradingView's Pine Script™ v5
// Provided By: PineCoders, for tradingview.com
//@version=5
title ='TASC 2024.10 Adaptive Oscillator Threshold'
stitle = 'AdapThrs'
strategy(title, stitle, false, default_qty_type = strategy.percent_of_equity,
default_qty_value = 10, slippage = 5)
// --- Inputs ---
string sys = input.string("BAT", "System", options=["Traditional", "BAT"])
int rsiLen = input.int(2, "RSI Length", 1)
int buyLevel = input.int(14, "Buy Level", 0)
int adapLen = input.int(8, "Adaptive Length", 2)
float adapK = input.float(6, "Adaptive Coefficient")
int exitBars = input.int(28, "Fixed-Bar Exit", 1, group = "Strategy Settings")
float DSL = input.float(1600, "Dollar Stop-Loss", 0, group = "Strategy Settings")
// --- Functions ---
// Bufi's Adaptive Threshold
BAT(float price, int length) =>
float sd = ta.stdev(price, length)
float lr = ta.linreg(price, length, 0)
float slope = (lr - price[length]) / (length + 1)
math.min(0.5, math.max(-0.5, slope / sd))
// --- Calculations ---
float osc = ta.rsi(close, rsiLen)
// Strategy entry rules
// - Traditional system
if sys == "Traditional" and osc < buyLevel
strategy.entry("long", strategy.long)
// - BAT system
float thrs = buyLevel * adapK * BAT(close, adapLen)
if sys == "BAT" and osc < thrs
strategy.entry("long", strategy.long)
// Strategy exit rules
// - Fixed-bar exit
int nBar = bar_index - strategy.opentrades.entry_bar_index(0)
if exitBars > 0 and nBar >= exitBars
strategy.close("long", "exit")
// - Dollar stop-loss
if DSL > 0 and strategy.opentrades.profit(0) <= - DSL
strategy.close("long", "Stop-loss", immediately = true)
// Visuals
rsiColor = #1b9e77
thrsColor = #d95f02
rsiLine = plot(osc, "RSI", rsiColor, 1)
thrsLine = plot(sys == "BAT" ? thrs : buyLevel, "Threshold", thrsColor, 1)
zeroLine = plot(0.0, "Zero", display = display.none)
fill(zeroLine, thrsLine, sys == "BAT" ? thrs : buyLevel, 0.0, color.new(thrsColor, 60), na)
Published by ChaoZhang on the FMZ strategy square · last modified 2024-11-12. 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/Adaptive-RSI-Oscillator-Dynamic-Trading-Strategy-with-Threshold-Optimization.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
- 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
- Advanced Quantitative Trading Strategy Combining RSI Divergence and Moving AveragesPine Script · Mean reversion · 1h