本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © CoffeeshopCrypto
//Unlike basic RSI indicators, this maps the actual price territory being contested during ranging markets.
//The dual-zone system helps distinguish between false breakouts (wicks) and legitimate closes outside the range.
//This tool automatically detects when markets transition between trending and ranging conditions using RSI dynamics.
//It visually maps potential support/resistance zones and highlights breakout opportunities - all in real-time.
//@version=6
indicator('RSI Support & Resistance Breakouts with Orderblocks', shorttitle = 'RSI SR OB Breakouts by CoffeeShopCrypto', max_bars_back = 200, max_boxes_count = 200, precision = 2, overlay = false)
//Inputs
show_hide_boxes = input.bool(true, 'Show Ranges')
use_breakout_colors = input.bool(true, title = "Use Breakout Bar Colors")
rsi_len = input.int(14, title = "RSI Length", group = "RSI Settings")
// SMA Filter
sma200 = ta.sma(close, 200)
useBullishSettings = close > sma200
//box Settings
Zone_background_color = input.color(color.rgb(60, 94, 92, 91), title = "Internal BG", inline = "Background color", group = "Zone Settings")
Zone_border_color = input.color(color.rgb(204, 64, 8, 19), title = "Internal Border", inline = "Border color", group = "Zone Settings")
Internal_Zone_background_color = input.color(color.rgb(33, 67, 189, 90), title = "External BG", inline = "Background color", group = "Zone Settings")
Internal_Zone_border_color = input.color(color.rgb(120, 123, 134, 26), title = "External Border", inline = "Border color", group = "Zone Settings")
Internal_Zone_mid_color = input.color(color.rgb(148, 159, 197, 2), title = "Internal Midline", inline = "internal color", group = "Zone Settings")
momentum_loss_bar_color = input.color(color.rgb(69, 88, 158), title = "Range Candle Color", inline = "range candle color", group = "Zone Settings")
box_extention = input.int(4, title = "Extend Box x bars into future", minval = 2, maxval = 40, group = "Zone Settings")
//Calculating Momentum
rsi_up = ta.rma(math.max(ta.change(close), 0), rsi_len)
rsi_down = ta.rma(-math.min(ta.change(close), 0), rsi_len)
_rsi = rsi_down == 0 ? 100 : rsi_up == 0 ? 0 : 100 - 100 / (1 + rsi_up / rsi_down)
adjustedRSI = _rsi - 50
//Representation of the OB and OS values. If calculation value is TRUE then it is considered to be both of these
bullish_center = 5
bearish_center = -5
spread = 2
// Dynamic thresholds
auto_rsi_center = useBullishSettings ? bullish_center : bearish_center
momentum_upper_threshold = auto_rsi_center + spread
momentum_lower_threshold = auto_rsi_center - spread
// Define bar color when condition is NOT true.
pricebarColor = adjustedRSI > momentum_upper_threshold ? color.rgb(37, 155, 41) : adjustedRSI < momentum_lower_threshold ? color.rgb(223, 48, 48) : momentum_loss_bar_color
//A place to store the values of condition and momentum calculation.
var is_range = false
var float start_range_h = na
var float start_range_l = na
var box range_bound_close = na
var box range_bound_extreme = na
var line midline = na
midpoint = (box.get_top(range_bound_extreme) + box.get_bottom(range_bound_extreme)) / 2
var float highest_close = na
var float lowest_close = na
var float highest_high = na
var float lowest_low = na
var int box_start_index = na
//What if the condition presents a FALSE.
var range_cond = false
range_cond := adjustedRSI >= momentum_lower_threshold and adjustedRSI <= momentum_upper_threshold
if range_cond and not is_range[1] and show_hide_boxes
is_range := true
start_range_h := high
start_range_l := low
highest_close := close // Initialize close tracking
lowest_close := close
box_start_index := bar_index
range_bound_close := box.new(bar_index, start_range_h, bar_index, start_range_l, bgcolor = Internal_Zone_background_color, border_color = Internal_Zone_border_color, force_overlay = true)
range_bound_extreme := box.new(bar_index, highest_close, bar_index, lowest_close, bgcolor = Zone_background_color, border_color = Zone_border_color, force_overlay = true)
midline := line.new(bar_index, midpoint, bar_index, midpoint, color = Internal_Zone_mid_color, width=1, force_overlay = true)
else if range_cond and is_range[1] and is_range
box.set_right(range_bound_close, bar_index + box_extention)
box.set_right(range_bound_extreme, bar_index + box_extention)
highest_close := math.max(highest_close, close) // Track highest close
lowest_close := math.min(lowest_close, close) // Track lowest close
highest_high := math.max(start_range_h, high) // Track highest high
lowest_low := math.min(start_range_l, low) // Track lowest low
box.set_top(range_bound_close, start_range_h) // Apply to box
box.set_bottom(range_bound_close, start_range_l)
box.set_top(range_bound_extreme, highest_close) // Apply to box
box.set_bottom(range_bound_extreme, lowest_close)
box.set_text(range_bound_extreme, "OB")
line.set_xy1(midline, box_start_index, midpoint)
line.set_xy2(midline, bar_index + box_extention, midpoint)
line.set_style(midline, line.style_dashed)
// Still track extreme highs/lows if needed
if high > start_range_h
start_range_h := high
if low < start_range_l
start_range_l := low
else
is_range := false
start_range_h := 0.0
start_range_l := 0.0
highest_close := na
lowest_close := na
//End of boxes
boxEnded = not range_cond and is_range[1]
// Color the bars
barcolor(use_breakout_colors ? pricebarColor : na, title = 'Breakout')
plot(adjustedRSI, title = 'RSI', color = color.rgb(255, 235, 59), display = display.all)
plot(sma200, force_overlay = true, display = display.all - display.status_line)
hline(0, color = color.white)