本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
// Modificat dupa "HTF Candles" (c) informanerd.
// Difera prin faptul ca "ziua" incepe la o ora aleasa de tine (implicit 12:00, ora Londrei),
// iar candelele se construiesc din lumanarile graficului, fara request.security.
maxBoxes = 500
indicator("HTF Candles (Anchored)", "", true, max_boxes_count = maxBoxes)
anchorGroup = "===============[ Anchor ]==============="
anchorHour = input.int(12, "Anchor hour", 0, 23, group = anchorGroup)
anchorMinute = input.int(0, "Anchor minute", 0, 59, group = anchorGroup)
tz = input.string("Europe/London", "Time zone", options = ["Europe/London", "UTC", "America/New_York", "Europe/Bucharest", "Europe/Berlin"], group = anchorGroup)
splitOnGap = input.bool(true, "New candle after a market gap (weekend)", group = anchorGroup)
showOpen = input.bool(false, "Show open line of the current candle", group = anchorGroup)
appearGroup = "===============[ Candles Appearance ]==============="
thickWick = input.bool(false, "Thick Candle Wicks", group = appearGroup)
ascColor = input.color(color.green, "Colors → Bull:", inline = "color", group = appearGroup)
descColor = input.color(color.red, " Bear:", inline = "color", group = appearGroup)
bodyTrans = input.int(60, "Transparency → Body:", 0, 100, 10, inline = "trans", group = appearGroup)
wickTrans = input.int(80, " Wicks:", 0, 100, 10, inline = "trans", group = appearGroup)
if timeframe.isdwm
runtime.error("Use an intraday chart timeframe (for example 1m to 1h).")
barMs = timeframe.in_seconds() * 1000
// Ora locala (in fusul ales) si data locala pentru fiecare lumanare
anchorTotal = anchorHour * 60 + anchorMinute
minOfDay = hour(time, tz) * 60 + minute(time, tz)
ymd = year(time, tz) * 10000 + month(time, tz) * 100 + dayofmonth(time, tz)
pastAnchor = minOfDay >= anchorTotal
// O candela noua incepe cand ora ancora este depasita, sau dupa un gol de piata
crossedToday = bar_index > 0 and ymd == ymd[1] and pastAnchor and minOfDay[1] < anchorTotal
newDayPast = bar_index > 0 and ymd != ymd[1] and pastAnchor
gapBreak = splitOnGap and bar_index > 0 and (time - time[1]) > 12 * 60 * 60 * 1000
newSess = bar_index == 0 or crossedToday or newDayPast or gapBreak
var float sO = na
var float sH = na
var float sL = na
var int sStart = na
var color candleCol = na
if newSess
sO := open
sH := high
sL := low
sStart := time
else
sH := math.max(sH, high)
sL := math.min(sL, low)
candleCol := close > sO ? ascColor : close < sO ? descColor : na(candleCol) ? ascColor : candleCol
var bodies = array.new_box()
var wicks = array.new_box()
// Redesenam candela curenta la fiecare lumanare (sterge si recreeaza), ca in scriptul original
// Verificarea de dimensiune este separata de last(), ca last() sa nu fie apelat niciodata pe array gol
if bodies.size() > 0
if box.get_left(bodies.last()) == sStart
bodies.pop().delete()
wicks.pop().delete()
if bodies.size() >= maxBoxes / 2
bodies.shift().delete()
wicks.shift().delete()
boxRight = time + barMs
bodyTop = math.max(sO, close)
bodyBottom = math.min(sO, close)
center = int((sStart + boxRight) / 2)
wickLeft = thickWick ? sStart : int(center - barMs / 2)
wickRight = thickWick ? boxRight : int(center + barMs / 2)
bodyFill = color.new(candleCol, bodyTrans)
wickFill = color.new(candleCol, wickTrans)
bodies.push(box.new(sStart, bodyTop, boxRight, bodyBottom, sO == close ? bodyFill : na, xloc = xloc.bar_time, bgcolor = bodyFill))
wicks.push(box.new(wickLeft, sH, wickRight, sL, na, xloc = xloc.bar_time, bgcolor = wickFill))
plot(showOpen and not newSess ? sO : na, "Candle open", color.new(color.gray, 10), 1, plot.style_linebr)