0bps

Strategy vault / Breakout

Dynamic RSI Breakout Trend Following Trading Strategy with Risk Reward Ratio Optimization System

This strategy is a trend-following trading system based on RSI (Relative Strength Index) breakouts, combined with a 1:4 risk-reward ratio to optimize trading performance. The strategy identifies trend lines formed by…

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

IMG

Overview

This strategy is a trend-following trading system based on RSI (Relative Strength Index) breakouts, combined with a 1:4 risk-reward ratio to optimize trading performance. The strategy identifies trend lines formed by RSI highs and lows, enters positions on breakouts, and uses a fixed risk-reward ratio for stop-loss and take-profit levels, implementing systematic trade management.

Strategy Principle

The core logic of the strategy is based on several key elements:

  1. RSI Trendline Breakout Signals: The system tracks local RSI highs and lows to form dynamic trend lines. Long positions are opened when RSI breaks above the high trendline, and short positions when it breaks below the low trendline.
  2. Entry Timing Identification: Uses RSI values comparison across three candles to confirm local highs and lows, improving trendline accuracy.
  3. Risk Management Mechanism: Uses the previous candle's low as stop-loss for long positions and high for short positions, ensuring clear risk control.
  4. Profit Optimization Design: Implements a 1:4 risk-reward ratio for take-profit levels, pursuing larger profit potential while controlling risk.

Strategy Advantages

  1. Systematic Decision-Making: Avoids subjective bias through programmatic RSI trendline identification and breakout detection.
  2. Strict Risk Control: Uses recent price volatility for stop-loss placement, controlling maximum risk per trade.
  3. Profit Ratio Optimization: Fixed 1:4 risk-reward ratio setup improves strategy's expected return.
  4. Trend Following Characteristics: Effectively captures medium to long-term trends, increasing profit opportunities.
  5. High Adaptability: Applicable to different markets and timeframes.

Strategy Risks

  1. False Breakout Risk: RSI breakouts may result in false signals leading to stop-loss exits.
  2. Distant Take-Profit Levels: 1:4 risk-reward ratio may set take-profit targets that are difficult to reach.
  3. Ranging Market Performance: May trigger frequent false signals in sideways markets.
  4. Slippage Impact: Actual stop-loss prices may differ from expected in less liquid markets.

Strategy Optimization Directions

  1. Dynamic Risk-Reward Ratio: Adjust risk-reward ratio based on market volatility.
  2. Trend Confirmation: Add trend confirmation indicators like moving averages or ATR.
  3. Position Management: Introduce volatility-based position sizing system.
  4. Exit Optimization: Implement trailing stops or scaled take-profit mechanisms.
  5. Time Filtering: Add trading session filters to avoid low liquidity periods.

Summary

The strategy builds a complete trend-following trading system by combining RSI breakouts with fixed risk-reward ratios. Its strengths lie in systematic decision-making processes and strict risk control, but practical application requires attention to false breakouts and market conditions. Through the suggested optimization directions, the strategy has the potential to achieve more stable performance across different market environments.

Source Pine Script

/*backtest
start: 2024-02-19 00:00:00
end: 2025-02-17 08:00:00
period: 2d
basePeriod: 2d
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/
// © Sunnysun7771

//@version=6
//@version=5
strategy("RSI Breakout Strategy with RR 1:4", overlay=true)

// Input parameters
rsi_length = input(14, title="RSI Length")
rsi_overbought = input(70, title="RSI Overbought Level")
rsi_oversold = input(30, title="RSI Oversold Level")

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

// Identify previous RSI highs and lows
var float rsi_prev_high = na
var float rsi_prev_low = na

// Update previous RSI high
if (rsi_value > rsi_value[1] and rsi_value[1] < rsi_value[2])
    rsi_prev_high := rsi_value[1]

// Update previous RSI low
if (rsi_value < rsi_value[1] and rsi_value[1] > rsi_value[2])
    rsi_prev_low := rsi_value[1]

// Conditions for entering a long position
long_condition = rsi_value > rsi_prev_high and not na(rsi_prev_high)

// Conditions for entering a short position
short_condition = rsi_value < rsi_prev_low and not na(rsi_prev_low)

// Calculate stop loss and take profit for long positions
long_stop_loss = low[1]  // Previous candle's low
long_take_profit = close + (4 * (close - long_stop_loss))  // RR 1:4

// Enter long position if all conditions are met
if (long_condition)
    strategy.entry("Long", strategy.long)
    strategy.exit("Take Profit/Stop Loss", from_entry="Long", stop=long_stop_loss, limit=long_take_profit)

// Calculate stop loss and take profit for short positions
short_stop_loss = high[1]  // Previous candle's high
short_take_profit = close - (4 * (short_stop_loss - close))  // RR 1:4

// Enter short position if all conditions are met
if (short_condition)
    strategy.entry("Short", strategy.short)
    strategy.exit("Take Profit/Stop Loss", from_entry="Short", stop=short_stop_loss, limit=short_take_profit)

// Plotting RSI for visualization
hline(rsi_overbought, "Overbought", color=color.red)
hline(rsi_oversold, "Oversold", color=color.green)
plot(rsi_value, color=color.purple, title="RSI")

Published by ChaoZhang on the FMZ strategy square · last modified 2025-02-19. 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-Breakout-Trend-Following-Trading-Strategy-with-Risk-Reward-Ratio-Optimization-System.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