OPEN-SOURCE SCRIPT
RSI Breakout Trend + TP/SL

█ OVERVIEW
"RSI Breakout Trend + TP/SL" is a trend-momentum indicator that identifies both trend continuation and potential reversals directly on the price chart.
It combines three elements of technical analysis:
• dynamic trend identification
• overbought/oversold zones
• breakouts from price ranges formed during RSI extreme zones
The indicator displays the current market direction using a trend line (Margin Line) and draws OB/OS zones as dynamic price boxes. When RSI exits an extreme zone, the box “freezes” and creates two horizontal breakout lines: one at the upper extreme and one at the lower extreme of the box. A breakout of either line generates a signal in the direction of the breakout.
Additionally, the script automatically visualizes Take Profit and Stop Loss levels, turning it into a comprehensive tool for both signal generation and position management.
█ CONCEPT
The indicator is based on a non-standard approach to trend lines (inspired by SuperTrend). First, RSI momentum is mapped and projected onto the current price range, then smoothed to create a dynamic price-based trend reference. This creates a trend base, around which an adaptive tolerance margin is added (dependent on the average candle body size). Breaking this margin changes the trend state.
Independently of the trend logic, the indicator tracks OB and OS levels. When RSI enters an extreme zone, a box is created that covers all candles in that period. When RSI returns to the normal range, the box stops expanding and two breakout lines are created:
- for the OB box → a line at the top and a line at the bottom
- for the OS box → a line at the bottom and a line at the top
Both lines are extended to the right until a breakout occurs or the next box appears (at which point the previous lines are frozen and no longer generate signals).
This system combines momentum projection, adaptive trend logic, and breakouts in both directions from RSI zones — both continuation and counter-trend.
█ FEATURES
Main Settings
- RSI Length / RSI MA Length
- Price Range Lookback
- Smoothing Length + Smoothing Type
- Tolerance Multiplier
- Overbought / Oversold Level
- Box Transparency
- TP/SL Settings
- Enable Candle Coloring (dynamic candle coloring based on trend)
- Signal Filters
• Only Trend-Following Signals
• Only Counter-Trend Signals
Breakout Functions (4 types of signals)
- obBreakSignal — breakout of the upper line of the OB box → LONG (green triangle below the candle)
- obBottomBreakSignal — breakout of the lower line of the OB box → SHORT (red triangle above the candle)
- osBreakSignal — breakout of the lower line of the OS box → SHORT (red triangle above the candle)
- osTopBreakSignal — breakout of the upper line of the OS box → LONG (green triangle below the candle)
Signal Filter Logic
- Both filters off (default) → all 4 signals are shown
- Only Trend-Following Signals enabled → only signals in the direction of the current Margin Line trend (uptrend = upward breakouts, downtrend = downward breakouts)
- Only Counter-Trend Signals enabled → only opposite (reversal) signals
- The filters work on both plotshape and alertcondition — you see and receive alerts only for the selected type of signals.
Visual Signals
- Green triangles = any upward breakout (OB top or OS top)
- Red triangles = any downward breakout (OB bottom or OS bottom)
How the boxes work
While RSI stays above OB (or below OS), the box dynamically expands with every new high/low. Once RSI exits the extreme zone, the box closes and creates two breakout lines (upper and lower). These lines continue extending until a breakout occurs or the next box closes (then the previous lines are frozen).
Automatic Take Profit & Stop Loss
- two SL calculation modes:
• ATR-based (default 1.5× ATR)
• percentage from entry price
- up to 3 Take Profit levels based on RR ratios
- independent visibility toggles for SL, TP1, TP2, TP3
Single Active Trade Logic
- TP/SL levels lock after hitting SL or the furthest TP
- lines end exactly on the exit bar (SL or TP)
Alerts
- Bullish Box Breakout (OB top or OS top)
- Bearish Box Breakout (OB bottom or OS bottom)
- Trend Changed to Bullish
- Trend Changed to Bearish
█ APPLICATIONS
- Trend-continuation trading (use "Only Trend-Following Signals"). Lower OB/OS levels may increase signal frequency.
- Catching reversals after RSI extremes (use "Only Counter-Trend Signals")
- Works on all timeframes — especially effective on high-volatility assets.
Recommended usage: first check the trend on a higher timeframe, then on the lower timeframe check the momentum to confirm that the trend is not weakening. The new Signal Filters let you instantly switch between continuation and reversal mode without changing any other parameters.
Performance can be further improved by identifying key support and resistance levels to avoid entering long trades just below resistance or short trades just above support.
█ NOTES
The indicator does not analyze the entire market structure — its sole purpose is to cleanly capture breakouts from RSI extremes (both in the direction of the trend and counter-trend) with confirmation from the trend line.
Always test and optimize the parameters for your specific instrument and timeframe. The best results are achieved on assets with high volatility.
"RSI Breakout Trend + TP/SL" is a trend-momentum indicator that identifies both trend continuation and potential reversals directly on the price chart.
It combines three elements of technical analysis:
• dynamic trend identification
• overbought/oversold zones
• breakouts from price ranges formed during RSI extreme zones
The indicator displays the current market direction using a trend line (Margin Line) and draws OB/OS zones as dynamic price boxes. When RSI exits an extreme zone, the box “freezes” and creates two horizontal breakout lines: one at the upper extreme and one at the lower extreme of the box. A breakout of either line generates a signal in the direction of the breakout.
Additionally, the script automatically visualizes Take Profit and Stop Loss levels, turning it into a comprehensive tool for both signal generation and position management.
█ CONCEPT
The indicator is based on a non-standard approach to trend lines (inspired by SuperTrend). First, RSI momentum is mapped and projected onto the current price range, then smoothed to create a dynamic price-based trend reference. This creates a trend base, around which an adaptive tolerance margin is added (dependent on the average candle body size). Breaking this margin changes the trend state.
Independently of the trend logic, the indicator tracks OB and OS levels. When RSI enters an extreme zone, a box is created that covers all candles in that period. When RSI returns to the normal range, the box stops expanding and two breakout lines are created:
- for the OB box → a line at the top and a line at the bottom
- for the OS box → a line at the bottom and a line at the top
Both lines are extended to the right until a breakout occurs or the next box appears (at which point the previous lines are frozen and no longer generate signals).
This system combines momentum projection, adaptive trend logic, and breakouts in both directions from RSI zones — both continuation and counter-trend.
█ FEATURES
Main Settings
- RSI Length / RSI MA Length
- Price Range Lookback
- Smoothing Length + Smoothing Type
- Tolerance Multiplier
- Overbought / Oversold Level
- Box Transparency
- TP/SL Settings
- Enable Candle Coloring (dynamic candle coloring based on trend)
- Signal Filters
• Only Trend-Following Signals
• Only Counter-Trend Signals
Breakout Functions (4 types of signals)
- obBreakSignal — breakout of the upper line of the OB box → LONG (green triangle below the candle)
- obBottomBreakSignal — breakout of the lower line of the OB box → SHORT (red triangle above the candle)
- osBreakSignal — breakout of the lower line of the OS box → SHORT (red triangle above the candle)
- osTopBreakSignal — breakout of the upper line of the OS box → LONG (green triangle below the candle)
Signal Filter Logic
- Both filters off (default) → all 4 signals are shown
- Only Trend-Following Signals enabled → only signals in the direction of the current Margin Line trend (uptrend = upward breakouts, downtrend = downward breakouts)
- Only Counter-Trend Signals enabled → only opposite (reversal) signals
- The filters work on both plotshape and alertcondition — you see and receive alerts only for the selected type of signals.
Visual Signals
- Green triangles = any upward breakout (OB top or OS top)
- Red triangles = any downward breakout (OB bottom or OS bottom)
How the boxes work
While RSI stays above OB (or below OS), the box dynamically expands with every new high/low. Once RSI exits the extreme zone, the box closes and creates two breakout lines (upper and lower). These lines continue extending until a breakout occurs or the next box closes (then the previous lines are frozen).
Automatic Take Profit & Stop Loss
- two SL calculation modes:
• ATR-based (default 1.5× ATR)
• percentage from entry price
- up to 3 Take Profit levels based on RR ratios
- independent visibility toggles for SL, TP1, TP2, TP3
Single Active Trade Logic
- TP/SL levels lock after hitting SL or the furthest TP
- lines end exactly on the exit bar (SL or TP)
Alerts
- Bullish Box Breakout (OB top or OS top)
- Bearish Box Breakout (OB bottom or OS bottom)
- Trend Changed to Bullish
- Trend Changed to Bearish
█ APPLICATIONS
- Trend-continuation trading (use "Only Trend-Following Signals"). Lower OB/OS levels may increase signal frequency.
- Catching reversals after RSI extremes (use "Only Counter-Trend Signals")
- Works on all timeframes — especially effective on high-volatility assets.
Recommended usage: first check the trend on a higher timeframe, then on the lower timeframe check the momentum to confirm that the trend is not weakening. The new Signal Filters let you instantly switch between continuation and reversal mode without changing any other parameters.
Performance can be further improved by identifying key support and resistance levels to avoid entering long trades just below resistance or short trades just above support.
█ NOTES
The indicator does not analyze the entire market structure — its sole purpose is to cleanly capture breakouts from RSI extremes (both in the direction of the trend and counter-trend) with confirmation from the trend line.
Always test and optimize the parameters for your specific instrument and timeframe. The best results are achieved on assets with high volatility.
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。