0bps

Strategy vault / Mean reversion

Dynamic RSI Oversold Rebound Trading Strategy with Stop Loss Optimization Model

This is a dynamic trading strategy based on the Relative Strength Index (RSI) combined with a flexible stop-loss mechanism. The strategy primarily targets oversold market conditions, aiming to capture price rebounds…

Author
ChaoZhang
Complexity
Starter · 48 lines
Parameters
0
Backtest bar
1d · swing
Tested on
BTC/USDT · futures

IMG

Overview

This is a dynamic trading strategy based on the Relative Strength Index (RSI) combined with a flexible stop-loss mechanism. The strategy primarily targets oversold market conditions, aiming to capture price rebounds for profit. The core approach involves using the RSI indicator to identify potential oversold conditions, implementing percentage-based stop-losses for risk control, and utilizing previous high breakouts as profit-taking signals.

Strategy Principles

The strategy operates based on the following key elements:

  1. RSI calculation uses a default period of 8, which is relatively short to quickly capture market oversold conditions.
  2. Entry conditions are triggered when RSI falls below a threshold of 28, indicating potentially severe oversold conditions.
  3. Stop-loss mechanism employs a percentage-based approach from entry price, defaulting to 5%, providing clear risk control boundaries.
  4. Exit signals are based on price breakouts above previous highs, allowing profits to extend.
  5. The strategy employs fixed position sizing and allows up to 2x pyramiding.

Strategy Advantages

  1. Comprehensive risk control through percentage-based stop-losses providing clear risk boundaries.
  2. Clear entry logic with RSI oversold conditions showing strong market adaptability.
  3. Exit mechanism allows profits to develop fully, avoiding premature trade closure.
  4. High parameter adjustability for optimization under different market conditions.
  5. Considers transaction costs and slippage, closely reflecting real trading conditions.

Strategy Risks

  1. RSI indicators may generate false signals, especially in range-bound markets.
  2. Fixed percentage stop-losses may be too rigid in highly volatile markets.
  3. Previous high breakout exits may miss optimal profit-taking opportunities during extreme volatility.
  4. 2x pyramiding allowance may increase risk exposure during sustained downtrends.

Optimization Directions

  1. Consider incorporating volatility indicators for dynamic stop-loss adjustment.
  2. Add trend filters to avoid frequent entries during strong downtrends.
  3. Optimize exit mechanism by incorporating RSI overbought zones as supplementary exit references.
  4. Implement volume confirmation mechanisms to improve entry signal reliability.
  5. Develop dynamic position sizing system adjusting based on market conditions.

Summary

This well-designed trading strategy achieves a good balance between risk control and profit opportunity capture through the combination of RSI oversold conditions and stop-loss mechanisms. The strategy's high adjustability makes it suitable for performance optimization under different market conditions. While there are some potential risks, the suggested optimization directions can further enhance the strategy's stability and profitability.

Source Pine Script

/*backtest
start: 2019-12-23 08:00:00
end: 2024-11-27 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("RSI Strategy with Adjustable RSI and Stop-Loss", overlay=false, 
         default_qty_type=strategy.fixed, default_qty_value=2, 
         initial_capital=10000, pyramiding=2, 
         commission_type=strategy.commission.percent, commission_value=0.05,
         slippage=1)

// Input fields for RSI parameters
rsi_length = input.int(8, title="RSI Length", minval=1)
rsi_threshold = input.float(28, title="RSI Threshold", minval=1, maxval=50)

// Input for Stop-Loss percentage
stop_loss_percent = input.float(5, title="Stop-Loss Percentage", minval=0.1, maxval=100)

// Calculate the RSI
rsi = ta.rsi(close, rsi_length)

// Condition for buying: RSI below the defined threshold
buyCondition = rsi < rsi_threshold

// Condition for selling: Close price higher than yesterday's high
sellCondition = close > ta.highest(high, 1)[1]

// Calculate the Stop-Loss level based on the entry price
var float stop_loss_level = na

if (buyCondition)
    stop_loss_level := close * (1 - stop_loss_percent / 100)
    strategy.entry("Long", strategy.long)
    // Create Stop-Loss order
    strategy.exit("Stop-Loss", from_entry="Long", stop=stop_loss_level)

// Selling signal
if (sellCondition)
    strategy.close("Long")

// Optional: Plot the RSI for visualization
plot(rsi, title="RSI", color=color.blue)
hline(rsi_threshold, "RSI Threshold", color=color.red)

Published by ChaoZhang on the FMZ strategy square · last modified 2024-11-29. 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.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Dynamic-RSI-Oversold-Rebound-Trading-Strategy-with-Stop-Loss-Optimization-Model.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. 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

esc

Try , , or .

↑↓ move↵ open