Strategy vault / Machine learning
Dynamic RSI Trading Strategy
This strategy builds a trading system using RSI indicator to determine overbought and oversold levels, together with dynamic trailing stop loss and profit target exit. It goes short when RSI crosses above overbought…

Overview
This strategy builds a trading system using RSI indicator to determine overbought and oversold levels, together with dynamic trailing stop loss and profit target exit. It goes short when RSI crosses above overbought level and goes long when RSI crosses below oversold level. Trailing stop loss and profit target exit are used to close positions.
Strategy Logic
This strategy uses 14-period RSI indicator to judge market technical patterns. RSI reflects the ratio of rising and falling power over a period of time, to tell if the market is overbought or oversold. The RSI length here is 14. When RSI crosses above 70, the market is considered overbought, and we go short. When RSI crosses below 30, the market is considered oversold, and we go long.
In addition, this strategy uses dynamic trailing stop loss mechanism. When holding long position, trailing stop price is set at 97% of closing price. When holding short position, trailing stop price is 103% of closing price. This locks in most profits while avoiding being stopped out by market noise.
Finally, this strategy uses profit target exit. When position profit reaches 20%, it will be closed. This locks in some profits and avoids profit retracement.
Advantage Analysis
The advantages of this strategy include:
- Using RSI indicator to determine overbought/oversold market effectively
- Adopting dynamic trailing stop loss to control risk
- Setting proper profit target to lock in profits
- Clear logic and few parameters, easy to implement for live trading
- Easy to optimize parameters like RSI length, overbought/oversold levels, stop loss percentage etc.
Risk Analysis
Some risks of this strategy to note:
- Potential false signals from RSI, causing unnecessary losses
- Probability of stop loss being hit, enlarging losses
- Profit target set too low, unable to hold position long enough to earn adequate profits
To cope with these risks, optimizing RSI parameters, adjusting stop loss percentage, relaxing profit target requirements reasonably can help.
Optimization Directions
Some directions to optimize the strategy:
- Optimize RSI parameters and overbought/oversold judge standards to reduce false signals
- Add other indicator filters to avoid erroneous signals caused by single RSI
- Dynamically optimize profit target according to market conditions
- Incorporate trading volume indicators to avoid low volume false breakouts
- Introduce machine learning algorithms to auto-tune parameters
Summary
The strategy has clear logic of using RSI to determine overbought/oversold market, with dynamic stops and profit taking. Its pros are easy understanding and implementation, good risk control, and high extensibility. Next step is to enhance signal quality, auto-tune parameters etc to make strategy more intelligent.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 14 | RSI Length |
| v_input_2 | 3 | Trailing Stop Percentage (%) |
| v_input_3 | 20 | Profit Target Percentage (%) |
Source Pine Script
/*backtest
start: 2024-01-04 00:00:00
end: 2024-02-03 00:00:00
period: 4h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Modified RSI-Based Trading Strategy", overlay=true)
// RSI settings
rsiLength = input(14, title="RSI Length")
overboughtLevel = 70
oversoldLevel = 30
// User-defined parameters
trailingStopPercentage = input(3, title="Trailing Stop Percentage (%)")
profitTargetPercentage = input(20, title="Profit Target Percentage (%)")
rsiValue = ta.rsi(close, rsiLength)
var float trailingStopLevel = na
var float profitTargetLevel = na
// Entry criteria
enterLong = ta.crossover(rsiValue, oversoldLevel)
enterShort = ta.crossunder(rsiValue, overboughtLevel)
// Exit criteria
exitLong = ta.crossover(rsiValue, overboughtLevel)
exitShort = ta.crossunder(rsiValue, oversoldLevel)
// Trailing stop calculation
if (strategy.position_size > 0)
trailingStopLevel := close * (1 - trailingStopPercentage / 100)
if (strategy.position_size < 0)
trailingStopLevel := close * (1 + trailingStopPercentage / 100)
// Execute the strategy
if (enterLong)
strategy.entry("Buy", strategy.long)
if (exitLong or ta.crossover(close, trailingStopLevel) or ta.change(close) > profitTargetPercentage / 100)
strategy.close("Buy")
if (enterShort)
strategy.entry("Sell", strategy.short)
if (exitShort or ta.crossunder(close, trailingStopLevel) or ta.change(close) < -profitTargetPercentage / 100)
strategy.close("Sell")
// Plot RSI and overbought/oversold levels
plot(rsiValue, title="RSI", color=color.blue)
hline(overboughtLevel, "Overbought", color=color.red, linestyle=hline.style_dashed)
hline(oversoldLevel, "Oversold", color=color.green, linestyle=hline.style_dashed)
Published by ChaoZhang on the FMZ strategy square · last modified 2024-02-04. 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/Dynamic-RSI-Trading-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
- AI Driven Dynamic Volatility Adaptive Trend Breakout Trading StrategyPine Script · Machine learning · 2d
- AI Powered Volatility Price System Divergence Trading StrategyPine Script · Machine learning · 1h
- Configurable BBRSIAroon Strategy BacktestPine Script · Machine learning · 5m
- Double Decker RSI Trading StrategyPine Script · Machine learning · 1h
- EMA and RSI Quantitative Trading StrategyPine Script · Machine learning · 1h
- Fibonacci HMA AI Buy Sell Signal StrategyPine Script · Machine learning · 1d