本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// ==============================================================================
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © 2026 kurutologic.
//
//@version=6
// Indicator : Honey Bear RSI
// Developer : kurutologic
// ==============================================================================
indicator("Honey Bear RSI", shorttitle = "HB-RSI", overlay = false, max_polylines_count = 100, max_lines_count = 500, max_labels_count = 100)
string grp_rsi = "1. RSI Settings"
string grp_rsi_style = "2. RSI & MA Style"
string grp_trend = "3. MTF Trend Filter"
string grp_art = "4. Visual Flavor Settings"
string grp_col = "5. Art Colors"
int rsi_length = input.int(14, "Length [RSI]", minval = 1, group = grp_rsi, tooltip = "Number of bars used to calculate the Relative Strength Index (RSI).")
int overbought = input.int(70, "Level [Overbought]", minval = 50, maxval = 100, group = grp_rsi, tooltip = "Overbought threshold. When RSI reaches or exceeds this level, the honey pot overflows and the Honey Bear appears!")
int oversold = input.int(30, "Level [Oversold]", minval = 0, maxval = 50, group = grp_rsi, tooltip = "Oversold threshold. When RSI drops to or below this level, the honey pot tips over and spills!")
color rsi_color = input.color(color.new(#FFD54F, 10), "Default RSI Color", group = grp_rsi_style, tooltip = "Default color of the RSI line when the MTF Trend Filter is disabled.")
int rsi_width = input.int(2, "RSI Line Width", minval = 1, maxval = 5, group = grp_rsi_style)
bool show_ma = input.bool(true, "Show RSI MA", group = grp_rsi_style, tooltip = "Toggles the display of a Moving Average smoothed line over the RSI.")
string ma_type = input.string("EMA", "MA Type", options = ["SMA", "EMA"], group = grp_rsi_style)
int ma_length = input.int(14, "Length [MA]", minval = 1, group = grp_rsi_style)
color ma_color = input.color(color.new(color.white, 30), "MA Line Color", group = grp_rsi_style)
int ma_width = input.int(1, "MA Line Width", minval = 1, maxval = 5, group = grp_rsi_style)
bool use_trend = input.bool(false, "Enable MTF Trend Color on RSI", group = grp_trend, tooltip = "When enabled, dynamically colors the RSI line based on the Higher Timeframe (HTF) trend direction.")
string trend_mode = input.string("KAMA", "Trend Mode", options = ["KAMA", "SuperTrend", "200 MA"], group = grp_trend, tooltip = "Select the algorithm used to determine the Higher Timeframe trend.")
string trend_tf = input.timeframe("240", "Trend Timeframe", group = grp_trend, tooltip = "Target timeframe used to calculate the trend filter (e.g., 240 = 4H).")
color col_bull = input.color(color.new(#089981, 0), "Bullish Trend Color", group = grp_trend)
color col_bear = input.color(color.new(#f23645, 0), "Bearish Trend Color", group = grp_trend)
int kama_len = input.int(10, "Length [KAMA]", minval = 1, group = grp_trend)
int kama_fast = input.int(2, "KAMA Fast EMA", minval = 1, group = grp_trend)
int kama_slow = input.int(30, "KAMA Slow EMA", minval = 1, group = grp_trend)
float st_factor = input.float(3.0, "SuperTrend Factor", minval = 0.1, step = 0.1, group = grp_trend)
int st_atr = input.int(10, "Length [ST ATR]", minval = 1, group = grp_trend)
int posOffset = input.int(70, "Position Offset (Bars)", minval = 5, group = grp_art, tooltip = "Horizontal distance (in bars to the right of the current candle) where the Honey Bear vector art is drawn.")
float sizeScale = input.float(1.0, "Art Scale", minval = 0.1, step = 0.1, group = grp_art, tooltip = "Overall size multiplier for the Honey Pot and Bear illustration.")
float xRatio = input.float(1.5, "X-Axis Stretch", minval = 0.5, step = 0.5, group = grp_art, tooltip = "Adjusts horizontal aspect ratio. Increase if the art looks too narrow on your screen.")
float yRatio = input.float(1.0, "Y-Axis Stretch", minval = 0.1, step = 0.1, group = grp_art, tooltip = "Adjusts vertical aspect ratio of the illustration.")
color POT_COL = input.color(color.new(#FF9800, 10), "Pot Color", group = grp_col)
color HONEY_COL = input.color(color.new(#FFC107, 10), "Honey Color", group = grp_col)
color BEAR_COL = input.color(color.new(#795548, 0), "Bear Color", group = grp_col)
get_trend_status() =>
int dir = 0
if trend_mode == "KAMA"
float mom = math.abs(close - nz(close[kama_len], close))
float vol = math.sum(math.abs(close - nz(close[1], close)), kama_len)
float er = vol != 0.0 ? mom / vol : 0.0
float fA = 2.0 / (kama_fast + 1.0)
float sA = 2.0 / (kama_slow + 1.0)
float sc = math.pow(er * (fA - sA) + sA, 2)
var float k = close
k := nz(k[1], close) + sc * (close - nz(k[1], close))
dir := k > nz(k[1], k) ? 1 : k < nz(k[1], k) ? -1 : 0
else if trend_mode == "SuperTrend"
[_, st_dir] = ta.supertrend(st_factor, st_atr)
dir := st_dir < 0 ? 1 : -1
else if trend_mode == "200 MA"
float ma200 = ta.sma(close, 200)
dir := close > ma200 ? 1 : -1
dir
int mtf_trend = request.security(syminfo.tickerid, trend_tf, get_trend_status()[barstate.isrealtime ? 1 : 0], gaps = barmerge.gaps_off, lookahead = barmerge.lookahead_off)
color active_rsi_col = use_trend ? (mtf_trend == 1 ? col_bull : mtf_trend == -1 ? col_bear : rsi_color) : rsi_color
float rsi_val = ta.rsi(close, rsi_length)
float rsi_ma = ma_type == "SMA" ? ta.sma(rsi_val, ma_length) : ta.ema(rsi_val, ma_length)
hline(overbought, "Overbought", color = color.new(color.red, 60), linestyle = hline.style_dashed)
hline(50, "Center", color = color.new(color.gray, 80), linestyle = hline.style_dotted)
hline(oversold, "Oversold", color = color.new(color.blue, 60), linestyle = hline.style_dashed)
plot(rsi_val, "RSI Line", color = active_rsi_col, linewidth = rsi_width)
plot(show_ma ? rsi_ma : na, "RSI MA Line", color = ma_color, linewidth = ma_width)
var array<polyline> art_polys = array.new<polyline>()
var array<line> art_lines = array.new<line>()
var array<label> art_labels = array.new<label>()
getXY(int cX, float cY, float dX, float dY) =>
chart.point.from_index(int(cX + dX * xRatio), cY + dY * yRatio)
getRotatedXY(int cX, float cY, float offsetX, float offsetY, float rotDeg) =>
float rad = rotDeg * math.pi / 180.0
float rX = offsetX * math.cos(rad) - offsetY * math.sin(rad)
float rY = offsetX * math.sin(rad) + offsetY * math.cos(rad)
chart.point.from_index(int(cX + rX * xRatio), cY + rY * yRatio)
drawCircRot(int cX, float cY, float offsetX, float offsetY, float radius, float rotDeg, color fillCol) =>
array<chart.point> pts = array.new<chart.point>()
float radRot = rotDeg * math.pi / 180.0
float rCx = offsetX * math.cos(radRot) - offsetY * math.sin(radRot)
float rCy = offsetX * math.sin(radRot) + offsetY * math.cos(radRot)
for i = 0 to 20
float angle = i * 18.0
float rad = angle * math.pi / 180.0
float px = rCx + radius * math.cos(rad)
float py = rCy + radius * math.sin(rad)
pts.push(getXY(cX, cY, px, py))
array.push(art_polys, polyline.new(pts, closed = true, fill_color = fillCol, line_color = color.new(color.black, 60)))
drawCircNoBorder(int cX, float cY, float offsetX, float offsetY, float radius, float rotDeg, color fillCol) =>
array<chart.point> pts = array.new<chart.point>()
float radRot = rotDeg * math.pi / 180.0
float rCx = offsetX * math.cos(radRot) - offsetY * math.sin(radRot)
float rCy = offsetX * math.sin(radRot) + offsetY * math.cos(radRot)
for i = 0 to 20
float angle = i * 18.0
float rad = angle * math.pi / 180.0
float px = rCx + radius * math.cos(rad)
float py = rCy + radius * math.sin(rad)
pts.push(getXY(cX, cY, px, py))
array.push(art_polys, polyline.new(pts, closed = true, fill_color = fillCol, line_color = fillCol))
drawRectRot(int cX, float cY, float offsetX, float offsetY, float w, float h, float rotDeg, color fillCol) =>
array<chart.point> pts = array.new<chart.point>()
pts.push(getRotatedXY(cX, cY, offsetX - w / 2.0, offsetY - h / 2.0, rotDeg))
pts.push(getRotatedXY(cX, cY, offsetX + w / 2.0, offsetY - h / 2.0, rotDeg))
pts.push(getRotatedXY(cX, cY, offsetX + w / 2.0, offsetY + h / 2.0, rotDeg))
pts.push(getRotatedXY(cX, cY, offsetX - w / 2.0, offsetY + h / 2.0, rotDeg))
array.push(art_polys, polyline.new(pts, closed = true, fill_color = fillCol, line_color = color.new(color.black, 60)))
drawPot2D(int cX, float cY, float scale, bool isSealed, bool isOverflowing, float tiltDeg) =>
drawCircRot(cX, cY, 0.0, 0.0, 15.0 * scale, tiltDeg, POT_COL)
drawRectRot(cX, cY, 0.0, 0.0, 28.0 * scale, 6.0 * scale, tiltDeg, color.new(#FFFDE7, 10))
chart.point h1 = getRotatedXY(cX, cY, -4.0 * scale, 0.0, tiltDeg)
chart.point h2 = getRotatedXY(cX, cY, 4.0 * scale, 0.0, tiltDeg)
array.push(art_lines, line.new(h1, h2, color = color.black, width = 1))
chart.point txtPt = getRotatedXY(cX, cY, 0.0, 0.0, tiltDeg)
array.push(art_labels, label.new(txtPt.index, txtPt.price, text = "✨HONEY✨", color = color.new(color.white, 100), textcolor = color.new(#5D4037, 0), style = label.style_none, size = size.normal))
drawRectRot(cX, cY, 0.0, 13.0 * scale, 18.0 * scale, 6.0 * scale, tiltDeg, POT_COL)
drawRectRot(cX, cY, 0.0, 17.0 * scale, 24.0 * scale, 4.0 * scale, tiltDeg, color.new(#E65100, 0))
if isSealed
drawRectRot(cX, cY, 0.0, 20.0 * scale, 16.0 * scale, 4.0 * scale, tiltDeg, color.new(#4E342E, 0))
if isOverflowing
drawCircNoBorder(cX, cY, 0.0, 19.0 * scale, 10.0 * scale, tiltDeg, HONEY_COL)
array<chart.point> drip = array.new<chart.point>()
drip.push(getRotatedXY(cX, cY, -11.0 * scale, 19.0 * scale, tiltDeg))
drip.push(getRotatedXY(cX, cY, 11.0 * scale, 19.0 * scale, tiltDeg))
drip.push(getRotatedXY(cX, cY, 5.0 * scale, 2.0 * scale, tiltDeg))
drip.push(getRotatedXY(cX, cY, -3.0 * scale, 6.0 * scale, tiltDeg))
array.push(art_polys, polyline.new(drip, closed = true, fill_color = HONEY_COL, line_color = HONEY_COL))
drawCircNoBorder(cX, cY, 5.0 * scale, 2.0 * scale, 2.5 * scale, tiltDeg, HONEY_COL)
drawCircNoBorder(cX, cY, -3.0 * scale, 6.0 * scale, 2.0 * scale, tiltDeg, HONEY_COL)
drawBear2D(int cX, float cY, float scale, bool hasHoney) =>
int bX = cX + int(32.0 * scale * xRatio)
float bY = cY + 4.0 * scale
drawCircRot(bX, bY, -6.0 * scale, -6.0 * scale, 4.0 * scale, 0.0, BEAR_COL)
drawCircRot(bX, bY, 6.0 * scale, -6.0 * scale, 4.0 * scale, 0.0, BEAR_COL)
drawCircRot(bX, bY, 0.0, 0.0, 11.0 * scale, 0.0, BEAR_COL)
drawCircRot(bX, bY, 0.0, -2.0 * scale, 7.0 * scale, 0.0, color.new(#D7CCC8, 40))
drawCircRot(bX, bY, -8.0 * scale, 3.0 * scale, 3.5 * scale, 0.0, BEAR_COL)
drawCircRot(bX, bY, 8.0 * scale, 3.0 * scale, 3.5 * scale, 0.0, BEAR_COL)
float hY = bY + 12.0 * scale
drawCircRot(bX, hY, -7.0 * scale, 6.0 * scale, 4.0 * scale, 0.0, BEAR_COL)
drawCircRot(bX, hY, 7.0 * scale, 6.0 * scale, 4.0 * scale, 0.0, BEAR_COL)
drawCircRot(bX, hY, 0.0, 0.0, 9.0 * scale, 0.0, BEAR_COL)
drawCircRot(bX, hY, 0.0, -2.0 * scale, 4.5 * scale, 0.0, color.new(#D7CCC8, 0))
drawCircRot(bX, hY, 0.0, -1.0 * scale, 1.5 * scale, 0.0, color.black)
drawCircRot(bX, hY, -3.0 * scale, 2.0 * scale, 1.5 * scale, 0.0, color.black)
drawCircRot(bX, hY, 3.0 * scale, 2.0 * scale, 1.5 * scale, 0.0, color.black)
if hasHoney
drawCircNoBorder(bX, bY, -8.0 * scale, 3.0 * scale, 2.2 * scale, 0.0, HONEY_COL)
drawCircNoBorder(bX, bY, 8.0 * scale, 3.0 * scale, 2.2 * scale, 0.0, HONEY_COL)
drawCircNoBorder(bX, hY, 0.0, -3.0 * scale, 1.5 * scale, 0.0, HONEY_COL)
drawSpill2D(int cX, float cY, float scale) =>
array<chart.point> spill = array.new<chart.point>()
for i = 0 to 20
float angle = i * 18.0
float rad = angle * math.pi / 180.0
float r = 20.0 * scale + 3.0 * scale * math.sin(angle * 4.0 * math.pi / 180.0)
float dX = 22.0 * scale + r * math.cos(rad)
float dY = -10.0 * scale + (r * 0.3) * math.sin(rad)
spill.push(getXY(cX, cY, dX, dY))
array.push(art_polys, polyline.new(spill, closed = true, fill_color = HONEY_COL, line_color = HONEY_COL))
if barstate.islast
for p in art_polys
polyline.delete(p)
for l in art_lines
line.delete(l)
for lbl in art_labels
label.delete(lbl)
array.clear(art_polys)
array.clear(art_lines)
array.clear(art_labels)
int cX = last_bar_index + posOffset
float cY = 50.0
if rsi_val >= overbought
drawPot2D(cX, cY, sizeScale, false, true, 0.0)
drawBear2D(cX, cY, sizeScale, true)
else if rsi_val <= oversold
drawPot2D(cX, cY, sizeScale, false, false, -90.0)
drawSpill2D(cX, cY, sizeScale)
else
drawPot2D(cX, cY, sizeScale, true, false, 0.0)
alertcondition(ta.crossover(rsi_val, overbought), title = "Honey Bear: Overbought", message = "Honey Bear RSI: RSI crossed above Overbought level.")
alertcondition(ta.crossunder(rsi_val, oversold), title = "Honey Bear: Oversold", message = "Honey Bear RSI: RSI crossed below Oversold level.")