本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("H1 Candle Box 50 | Bold 50% Dashed", overlay=true, max_boxes_count=5, max_lines_count=5)
// ───── SETTINGS ─────
boxLength = input.int(50, "Box Length (Chart Bars)", minval=1, maxval=500)
bullColor = input.color(color.green, "Bullish Box Color")
bearColor = input.color(color.red, "Bearish Box Color")
boxTransparency = input.int(85, "Box Transparency", minval=0, maxval=100)
midColor = input.color(color.orange, "50% Line Color")
midWidth = input.int(3, "50% Line Thickness", minval=2, maxval=5)
// ───── PREVIOUS CONFIRMED 1H CANDLE ─────
[hOpen, hHigh, hLow, hClose, hTime] = request.security(
syminfo.tickerid,
"60",
[open[1], high[1], low[1], close[1], time[1]],
lookahead=barmerge.lookahead_on)
// Detect new 1H candle
newHour = timeframe.change("60")
// ───── DRAWING OBJECTS ─────
var box h1Box = na
var line midLine = na
if newHour and not na(hTime)
// Delete previous box and midpoint line
if not na(h1Box)
box.delete(h1Box)
if not na(midLine)
line.delete(midLine)
// Bias from the completed 1H candle
isBullish = hClose >= hOpen
boxColor = isBullish ? bullColor : bearColor
// Exact 50% midpoint
midpoint = (hHigh + hLow) / 2.0
// Box length = exactly 50 chart bars by default
barMs = timeframe.in_seconds() * 1000
rightTime = hTime + boxLength * barMs
// Draw candle range box
h1Box := box.new(
left=hTime,
top=hHigh,
right=rightTime,
bottom=hLow,
xloc=xloc.bar_time,
border_color=boxColor,
border_width=2,
bgcolor=color.new(boxColor, boxTransparency))
// Bold, highly visible dashed 50% line
midLine := line.new(
x1=hTime,
y1=midpoint,
x2=rightTime,
y2=midpoint,
xloc=xloc.bar_time,
color=midColor,
style=line.style_dashed,
width=midWidth)