Multi Day Profiles

Drizzle_Algo56 · study · 413 行 · 点赞 117 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=6
indicator("Multi Day Profiles ", shorttitle="MDP", overlay=true, max_boxes_count=500, max_lines_count=40, max_labels_count=40)
 
// OHLCV estimate: source candle volume is distributed uniformly over its range.
// Frozen uses only the column's anchor session; Rolling includes anchor to now.
// Premium = VAH to profile high. Discount = profile low to VAL.
// Zone rectangles stop at the LEFT edge of their selected profile.
// LVN = lowest-volume nonempty histogram row inside the enabled zone.
// LVN ties favor the row nearest the value-area boundary. No eligible row means
// no LVN box. Frozen profiles use frozen data for levels, zones and LVN alike.
// Use a standard intraday chart >= 1 minute, and leave room to the right.
 
const string G_PROFILE = "Profiles"
const string G_COL1 = "Column 1 - Current / latest"
const string G_COL2 = "Column 2 - Previous trading day (D-1)"
const string G_COL3 = "Column 3 - Two trading days back (D-2)"
const string G_COL4 = "Column 4 - Three trading days back (D-3)"
const string G_ZONES = "Premium / discount appearance"
const string G_LVN = "Lowest-volume node highlight"
const string G_SESSION = "Trading session"
const string G_LAYOUT = "Layout"
const string G_STYLE = "Colors and labels"
 
int profileCount = input.int(4, "Number of profiles", minval=1, maxval=4, group=G_PROFILE)
int requestedRows = input.int(64, "Maximum price rows", minval=12, maxval=100, group=G_PROFILE)
float valuePercent = input.float(70.0, "Value area %", minval=1.0, maxval=100.0, step=1.0, group=G_PROFILE, tooltip="Grow from POC by adding the larger adjacent row until at least this percentage of volume is included.")
string sampleTf = input.timeframe("1", "Calculation timeframe", options=["1", "3", "5", "15"], group=G_PROFILE, tooltip="Use 1 minute for more detail. If the chart timeframe is smaller than or equal to this, chart candles are used.")
 
string mode0 = input.string("Rolling", "Mode", options=["Frozen", "Rolling"], group=G_COL1, tooltip="Frozen uses only the anchor session. Rolling includes anchor through latest session. The current session develops in either mode until it closes.")
bool premium0 = input.bool(false, "Premium", inline="zones0", group=G_COL1)
bool discount0 = input.bool(false, "Discount", inline="zones0", group=G_COL1)
bool extend0 = input.bool(true, "Extend zones back to session start", group=G_COL1, tooltip="Off: zones cover only the gap from the latest candle to the profile's left edge. LVN boxes follow the same extent.")
bool pocExtend0 = input.bool(false, "Extend POC", inline="levels0", group=G_COL1, tooltip="Extend into the chart back to this profile's starting session.")
bool vaExtend0 = input.bool(false, "Extend VAH / VAL", inline="levels0", group=G_COL1, tooltip="Extend into the chart back to this profile's starting session.")
 
string mode1 = input.string("Frozen", "Mode", options=["Frozen", "Rolling"], group=G_COL2)
bool premium1 = input.bool(false, "Premium", inline="zones1", group=G_COL2)
bool discount1 = input.bool(false, "Discount", inline="zones1", group=G_COL2)
bool extend1 = input.bool(true, "Extend zones back to session start", group=G_COL2, tooltip="Off: zones cover only the gap from the latest candle to the profile's left edge. LVN boxes follow the same extent.")
bool pocExtend1 = input.bool(false, "Extend POC", inline="levels1", group=G_COL2, tooltip="Extend into the chart back to this profile's starting session.")
bool vaExtend1 = input.bool(false, "Extend VAH / VAL", inline="levels1", group=G_COL2, tooltip="Extend into the chart back to this profile's starting session.")
 
string mode2 = input.string("Frozen", "Mode", options=["Frozen", "Rolling"], group=G_COL3)
bool premium2 = input.bool(false, "Premium", inline="zones2", group=G_COL3)
bool discount2 = input.bool(false, "Discount", inline="zones2", group=G_COL3)
bool extend2 = input.bool(true, "Extend zones back to session start", group=G_COL3, tooltip="Off: zones cover only the gap from the latest candle to the profile's left edge. LVN boxes follow the same extent.")
bool pocExtend2 = input.bool(false, "Extend POC", inline="levels2", group=G_COL3, tooltip="Extend into the chart back to this profile's starting session.")
bool vaExtend2 = input.bool(false, "Extend VAH / VAL", inline="levels2", group=G_COL3, tooltip="Extend into the chart back to this profile's starting session.")
 
string mode3 = input.string("Frozen", "Mode", options=["Frozen", "Rolling"], group=G_COL4)
bool premium3 = input.bool(false, "Premium", inline="zones3", group=G_COL4)
bool discount3 = input.bool(false, "Discount", inline="zones3", group=G_COL4)
bool extend3 = input.bool(true, "Extend zones back to session start", group=G_COL4, tooltip="Off: zones cover only the gap from the latest candle to the profile's left edge. LVN boxes follow the same extent.")
bool pocExtend3 = input.bool(false, "Extend POC", inline="levels3", group=G_COL4, tooltip="Extend into the chart back to this profile's starting session.")
bool vaExtend3 = input.bool(false, "Extend VAH / VAL", inline="levels3", group=G_COL4, tooltip="Extend into the chart back to this profile's starting session.")
 
color premiumColor = input.color(#ef5350, "Premium zone", group=G_ZONES)
color discountColor = input.color(#26a69a, "Discount zone", group=G_ZONES)
int zoneTransparency = input.int(92, "Zone transparency", minval=0, maxval=100, group=G_ZONES)
bool showLvn = input.bool(true, "Highlight lowest-volume row in enabled zones", group=G_LVN, tooltip="One box per enabled premium/discount zone. Uses the smallest positive-volume profile row in that zone, ignoring empty rows and tiny numerical residue. Equal-volume ties favor the row nearest VAH/VAL.")
int lvnDarkening = input.int(45, "Darken zone color (%)", minval=0, maxval=90, group=G_LVN)
int lvnTransparency = input.int(45, "LVN box transparency", minval=0, maxval=100, group=G_LVN)
 
string sessionMode = input.string("Chart session", "Session source", options=["Chart session", "Custom session"], group=G_SESSION, tooltip="Chart session follows exchange trading days and available chart data. Custom session filters that data; it cannot retrieve hours excluded from the chart.")
string customSession = input.session("0930-1600", "Custom session hours", group=G_SESSION, tooltip="One continuous session, including overnight sessions such as 1800-1700. Custom profile dates refer to the START date. Align boundaries with the calculation timeframe.")
string customDays = input.string("1234567", "Custom session days", group=G_SESSION, tooltip="1=Sunday, 2=Monday, ... 7=Saturday. Example: 23456 for Monday-Friday. TradingView's convention applies to overnight sessions.")
string zoneInput = input.string("Exchange", "Custom session timezone", group=G_SESSION, tooltip="Exchange, or an IANA name such as America/New_York or Europe/Berlin.")
string sessionZone = zoneInput == "Exchange" ? syminfo.timezone : zoneInput
int sessionHour = int(str.tonumber(str.substring(customSession, 0, 2)))
int sessionMinute = int(str.tonumber(str.substring(customSession, 2, 4)))
 
int rightOffset = input.int(8, "Distance from latest candle (bars)", minval=2, maxval=50, group=G_LAYOUT)
int columnWidth = input.int(36, "Profile width (bars)", minval=8, maxval=60, group=G_LAYOUT)
int columnGap = input.int(18, "Space between profiles (bars)", minval=8, maxval=30, group=G_LAYOUT)
bool showLivePrice = input.bool(true, "Live price line (no label)", group=G_LAYOUT)
bool showHeaders = input.bool(true, "Profile headings", group=G_LAYOUT)
float nameLiftPercent = input.float(3.0, "Name distance above its profile (%)", minval=0.0, maxval=20.0, step=0.5, group=G_LAYOUT)
bool showLevelLabels = input.bool(true, "VAH / POC / VAL price labels", group=G_LAYOUT)
bool showTable = input.bool(true, "Summary table", group=G_LAYOUT)
 
color currentColor = input.color(#26a69a, "Current profile", group=G_STYLE)
color previousColor = input.color(#5c8de6, "Previous profiles", group=G_STYLE)
color pocColor = input.color(#ffb74d, "POC", group=G_STYLE)
color valueColor = input.color(#b3c7e6, "VAH / VAL", group=G_STYLE)
color livePriceColor = input.color(#ffeb3b, "Live price line", group=G_STYLE)
string textChoice = input.string("Black", "Label and table text", options=["Black", "White"], group=G_STYLE)
color textInk = textChoice == "Black" ? color.black : color.white
 
f_mode(int column) =>
    column == 0 ? mode0 : column == 1 ? mode1 : column == 2 ? mode2 : mode3
f_premium(int column) =>
    column == 0 ? premium0 : column == 1 ? premium1 : column == 2 ? premium2 : premium3
f_discount(int column) =>
    column == 0 ? discount0 : column == 1 ? discount1 : column == 2 ? discount2 : discount3
f_extend(int column) =>
    column == 0 ? extend0 : column == 1 ? extend1 : column == 2 ? extend2 : extend3
f_pocExtend(int column) =>
    column == 0 ? pocExtend0 : column == 1 ? pocExtend1 : column == 2 ? pocExtend2 : pocExtend3
f_vaExtend(int column) =>
    column == 0 ? vaExtend0 : column == 1 ? vaExtend1 : column == 2 ? vaExtend2 : vaExtend3
 
type SessionData
    int key
    int firstTime
    array<float> highs
    array<float> lows
    array<float> volumes
    float top
    float bottom
    bool partial
 
type ProfileData
    array<float> bins
    float base
    float rowSize
    float maximum
    float total
    float poc
    float vah
    float val
    int vaLow
    int vaHigh
    bool partial
    float highest
    float lowest
 
f_sessionKey() =>
    int result = time_tradingday
    if sessionMode == "Custom session"
        bool included = not na(time(timeframe.period, customSession + ":" + customDays, sessionZone))
        int minutesToday = hour(time, sessionZone) * 60 + minute(time, sessionZone)
        int dateOffset = minutesToday < sessionHour * 60 + sessionMinute ? 1 : 0
        result := included ? timestamp(sessionZone, year(time, sessionZone), month(time, sessionZone), dayofmonth(time, sessionZone) - dateOffset, sessionHour, sessionMinute) : na
    result
 
// Normal var rollback prevents repeated accumulation of a developing candle.
f_store(array<SessionData> sessions, int sampleTime, int key, float hi, float lo, float vol) =>
    if not na(key) and not na(hi) and not na(lo)
        bool firstSession = sessions.size() == 0
        bool newSession = firstSession
        if not firstSession
            SessionData latest = sessions.get(0)
            newSession := latest.key != key
        if newSession
            sessions.unshift(SessionData.new(key, sampleTime, array.new<float>(), array.new<float>(), array.new<float>(), hi, lo, firstSession))
            if sessions.size() > 4
                sessions.pop()
        SessionData day = sessions.get(0)
        if day.highs.size() >= 10000
            runtime.error("Too many samples in one session. Use a larger calculation timeframe.")
        day.highs.push(hi)
        day.lows.push(lo)
        day.volumes.push(math.max(nz(vol), 0.0))
        day.top := math.max(day.top, hi)
        day.bottom := math.min(day.bottom, lo)
        day.partial := day.partial or na(vol)
    0
 
f_add(array<float> values, int index, float amount) =>
    values.set(index, values.get(index) + amount)
 
// Whole ticks avoid decimal boundary errors. The difference array allows
// uniform range allocation without a rows-per-candle inner loop.
f_distribute(array<float> bins, array<float> difference, float base, float step, float lo, float hi, float vol) =>
    if vol > 0
        int n = bins.size()
        int baseTick = int(math.round(base / syminfo.mintick))
        int rowTicks = math.max(1, int(math.round(step / syminfo.mintick)))
        int lowTick = int(math.round(lo / syminfo.mintick))
        int highTick = int(math.round(hi / syminfo.mintick))
        int lower = math.max(0, math.min(n - 1, int(math.floor(float(lowTick - baseTick) / rowTicks))))
        int upper = math.max(0, math.min(n - 1, int(math.floor(float(highTick - baseTick) / rowTicks))))
        if highTick <= lowTick or lower == upper
            f_add(bins, lower, vol)
        else
            float density = vol / (highTick - lowTick)
            f_add(bins, lower, density * math.max(0, baseTick + (lower + 1) * rowTicks - lowTick))
            f_add(bins, upper, density * math.max(0, highTick - (baseTick + upper * rowTicks)))
            if upper > lower + 1
                f_add(difference, lower + 1, density * rowTicks)
                f_add(difference, upper, -density * rowTicks)
    0
 
f_profile(array<SessionData> sessions, int anchor, string mode) =>
    int first = mode == "Rolling" ? 0 : anchor
    SessionData start = sessions.get(anchor)
    float highest = start.top
    float lowest = start.bottom
    bool partial = false
    for d = first to anchor
        SessionData day = sessions.get(d)
        highest := math.max(highest, day.top)
        lowest := math.min(lowest, day.bottom)
        partial := partial or day.partial
    int bottomTick = int(math.round(lowest / syminfo.mintick))
    int topTick = int(math.round(highest / syminfo.mintick))
    int ticksPerRow = math.max(1, int(math.ceil(float(topTick - bottomTick) / requestedRows)))
    int rowCount = math.max(1, math.min(requestedRows, int(math.ceil(float(topTick - bottomTick) / ticksPerRow))))
    float base = bottomTick * syminfo.mintick
    float rowSize = ticksPerRow * syminfo.mintick
    array<float> bins = array.new<float>(rowCount, 0.0)
    array<float> difference = array.new<float>(rowCount, 0.0)
    for d = first to anchor
        SessionData day = sessions.get(d)
        for j = 0 to day.highs.size() - 1
            f_distribute(bins, difference, base, rowSize, day.lows.get(j), day.highs.get(j), day.volumes.get(j))
    float running = 0.0
    float total = 0.0
    float maximum = 0.0
    int pocIndex = 0
    for r = 0 to rowCount - 1
        running += difference.get(r)
        float rowVolume = math.max(0.0, bins.get(r) + running)
        bins.set(r, rowVolume)
        total += rowVolume
        if rowVolume > maximum
            maximum := rowVolume
            pocIndex := r
    int vaLow = pocIndex
    int vaHigh = pocIndex
    float included = maximum
    float target = total * valuePercent / 100.0
    while included < target and (vaLow > 0 or vaHigh < rowCount - 1)
        float above = vaHigh < rowCount - 1 ? bins.get(vaHigh + 1) : -1.0
        float below = vaLow > 0 ? bins.get(vaLow - 1) : -1.0
        bool takeAbove = above > below or (above == below and vaHigh - pocIndex <= pocIndex - vaLow)
        if takeAbove
            vaHigh += 1
            included += above
        else
            vaLow -= 1
            included += below
    float poc = total > 0 ? base + (pocIndex + 0.5) * rowSize : na
    float vah = total > 0 ? base + (vaHigh + 1) * rowSize : na
    float val = total > 0 ? base + vaLow * rowSize : na
    ProfileData.new(bins, base, rowSize, maximum, total, poc, vah, val, vaLow, vaHigh, partial, highest, lowest)
 
// One borderless timestamp box, ending at the profile's LEFT edge. No join
// seam at the current candle and no historical bar-index buffer lookup.
f_zone(array<box> boxes, SessionData day, int profileStartTime, float top, float bottom, color ink, bool extendToStart, int transparency) =>
    int startTime = extendToStart ? day.firstTime : time
    if top > bottom and not na(profileStartTime) and startTime < profileStartTime
        boxes.push(box.new(left=startTime, top=top, right=profileStartTime, bottom=bottom, xloc=xloc.bar_time, border_color=na, border_width=0, bgcolor=color.new(ink, transparency)))
    0
 
f_darkColor(color ink) =>
    float factor = 1.0 - lvnDarkening / 100.0
    color.rgb(int(math.round(color.r(ink) * factor)), int(math.round(color.g(ink) * factor)), int(math.round(color.b(ink) * factor)))
 
// Select the smallest positive-volume row intersecting this zone. Premium
// scans up from VAH; discount scans down from VAL, giving deterministic ties.
f_lowestRow(ProfileData p, float zoneLow, float zoneHigh, bool upperZone) =>
    float bestVolume = na
    float nodeLow = na
    float nodeHigh = na
    float epsilon = p.maximum * 0.0000000001
    if zoneHigh > zoneLow and p.maximum > 0
        int n = p.bins.size()
        for i = 0 to n - 1
            int r = upperZone ? i : n - 1 - i
            float rowLow = p.base + r * p.rowSize
            float clippedLow = math.max(rowLow, zoneLow)
            float clippedHigh = math.min(rowLow + p.rowSize, zoneHigh)
            float rowVolume = p.bins.get(r)
            if clippedHigh - clippedLow > syminfo.mintick * 0.000001 and rowVolume > epsilon
                if na(bestVolume) or rowVolume < bestVolume - epsilon
                    bestVolume := rowVolume
                    nodeLow := clippedLow
                    nodeHigh := clippedHigh
    [nodeLow, nodeHigh]
 
f_lvn(array<box> boxes, SessionData day, ProfileData p, int profileStartTime, float zoneLow, float zoneHigh, bool upperZone, color ink, bool extendToStart) =>
    [nodeLow, nodeHigh] = f_lowestRow(p, zoneLow, zoneHigh, upperZone)
    if not na(nodeLow) and not na(nodeHigh)
        f_zone(boxes, day, profileStartTime, nodeHigh, nodeLow, f_darkColor(ink), extendToStart, lvnTransparency)
    0
 
f_name(array<line> lines, array<label> labels, int left, float highest, float lowest, string labelText) =>
    float lift = math.max(syminfo.mintick * 2, (highest - lowest) * nameLiftPercent / 100.0)
    float nameY = highest + lift
    lines.push(line.new(left, highest, left, nameY, xloc=xloc.bar_index, color=color.black, width=1))
    lines.push(line.new(left, nameY, left + 3, nameY, xloc=xloc.bar_index, color=color.black, width=1))
    labels.push(label.new(left + 3, nameY, labelText, xloc=xloc.bar_index, style=label.style_label_left, color=color.new(color.black, 100), textcolor=textInk, textalign=text.align_left, size=size.small))
    0
 
// The optional historical extension is timestamp-based. The original level
// across the profile stays visible whether chart extension is on or off.
f_level(array<line> lines, array<label> labels, SessionData day, int profileStartTime, int left, int right, float price, string name, color ink, bool isPoc, bool extendIntoChart) =>
    if extendIntoChart and not na(profileStartTime) and day.firstTime < profileStartTime
        lines.push(line.new(day.firstTime, price, profileStartTime, price, xloc=xloc.bar_time, color=ink, width=isPoc ? 2 : 1, style=isPoc ? line.style_solid : line.style_dashed))
    lines.push(line.new(left, price, right, price, xloc=xloc.bar_index, color=ink, width=isPoc ? 2 : 1, style=isPoc ? line.style_solid : line.style_dashed))
    if showLevelLabels
        labels.push(label.new(right + 1, price, name + " " + str.tostring(price, format.mintick), xloc=xloc.bar_index, style=label.style_label_left, color=color.new(ink, 100), textcolor=textInk, size=size.tiny))
    0
 
f_location(float price, float vah, float val, float highest, float lowest) =>
    string result = "NO VOLUME"
    if not na(vah)
        result := price > highest ? "ABOVE HIGH" : price < lowest ? "BELOW LOW" : price > vah ? "ABOVE VAH" : price < val ? "BELOW VAL" : "IN VALUE"
    result
 
if barstate.isfirst
    if not timeframe.isintraday or timeframe.in_seconds() < 60
        runtime.error("Use a time-based intraday chart of 1 minute or higher, below 1 day.")
    if not chart.is_standard
        runtime.error("Use standard candles or bars for volume profiles.")
    if str.length(customDays) == 0
        runtime.error("Enter at least one custom session day: 1=Sunday through 7=Saturday.")
    for j = 0 to str.length(customDays) - 1
        if not str.contains("1234567", str.substring(customDays, j, j + 1))
            runtime.error("Custom session days must contain only digits 1 through 7.")
 
var array<SessionData> sessions = array.new<SessionData>()
bool useLowerTf = timeframe.in_seconds(sampleTf) < timeframe.in_seconds()
int chartKey = f_sessionKey()
if useLowerTf
    [sampleTimes, sampleHighs, sampleLows, sampleVolumes, sampleKeys] = request.security_lower_tf(syminfo.tickerid, sampleTf, [time, high, low, volume, f_sessionKey()])
    [liveTime, liveHigh, liveLow, liveVolume, liveKey] = request.security(syminfo.tickerid, sampleTf, [time, high, low, volume, f_sessionKey()], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off)
    int n = sampleTimes.size()
    bool useLive = barstate.isrealtime and not na(liveTime) and not na(liveHigh) and not na(liveLow) and liveTime >= time and liveTime < time_close
    if n > 0
        useLive := useLive and liveTime >= sampleTimes.get(n - 1)
        for j = 0 to n - 1
            if not (useLive and sampleTimes.get(j) == liveTime)
                f_store(sessions, sampleTimes.get(j), sampleKeys.get(j), sampleHighs.get(j), sampleLows.get(j), sampleVolumes.get(j))
    if useLive
        f_store(sessions, liveTime, liveKey, liveHigh, liveLow, liveVolume)
    if n == 0 and not useLive and sessions.size() > 0 and not na(chartKey)
        SessionData latest = sessions.get(0)
        if latest.key == chartKey
            latest.partial := true
else
    f_store(sessions, time, chartKey, high, low, volume)
 
var array<box> drawnBoxes = array.new<box>()
var array<line> drawnLines = array.new<line>()
var array<label> drawnLabels = array.new<label>()
var table summary = table.new(position.bottom_right, 5, 8, border_width=1, border_color=color.new(color.gray, 65))
 
if barstate.islast
    while drawnBoxes.size() > 0
        box.delete(drawnBoxes.pop())
    while drawnLines.size() > 0
        line.delete(drawnLines.pop())
    while drawnLabels.size() > 0
        label.delete(drawnLabels.pop())
    table.clear(summary, 0, 0, 4, 7)
    int count = math.min(profileCount, sessions.size())
    if count > 0
        array<ProfileData> profiles = array.new<ProfileData>()
        array<int> profileTimes = array.new<int>()
        // All ordinary zones first, so none can wash out another LVN box.
        for d = 0 to count - 1
            SessionData day = sessions.get(d)
            ProfileData p = f_profile(sessions, d, f_mode(d))
            profiles.push(p)
            int columnOffset = rightOffset + d * (columnWidth + columnGap)
            int profileStartTime = time(timeframe.period, bars_back=-columnOffset)
            profileTimes.push(profileStartTime)
            if p.total > 0
                if f_premium(d)
                    f_zone(drawnBoxes, day, profileStartTime, p.highest, p.vah, premiumColor, f_extend(d), zoneTransparency)
                if f_discount(d)
                    f_zone(drawnBoxes, day, profileStartTime, p.val, p.lowest, discountColor, f_extend(d), zoneTransparency)
        // LVN boxes above zone fills, below histograms and level labels.
        if showLvn
            for d = 0 to count - 1
                SessionData day = sessions.get(d)
                ProfileData p = profiles.get(d)
                int profileStartTime = profileTimes.get(d)
                if p.total > 0
                    if f_premium(d)
                        f_lvn(drawnBoxes, day, p, profileStartTime, p.vah, p.highest, true, premiumColor, f_extend(d))
                    if f_discount(d)
                        f_lvn(drawnBoxes, day, p, profileStartTime, p.lowest, p.val, false, discountColor, f_extend(d))
        if showTable
            array<string> names = array.from("Column / mode", "Session / anchor", "VAH", "POC", "VAL", "Price position", "Total volume", "Coverage")
            for row = 0 to 7
                table.cell(summary, 0, row, names.get(row), text_color=textInk, bgcolor=color.new(chart.bg_color, 10), text_size=size.tiny)
        for d = 0 to count - 1
            SessionData day = sessions.get(d)
            ProfileData p = profiles.get(d)
            int profileStartTime = profileTimes.get(d)
            string mode = f_mode(d)
            int left = bar_index + rightOffset + d * (columnWidth + columnGap)
            int right = left + columnWidth
            color ink = d == 0 ? currentColor : previousColor
            string dateText = str.format_time(day.key, "dd MMM", sessionMode == "Chart session" ? "UTC" : sessionZone)
            string heading = d == 0 ? "CURRENT" : "D-" + str.tostring(d)
            if showHeaders
                f_name(drawnLines, drawnLabels, left, p.highest, p.lowest, str.tostring(d + 1) + " " + heading + " · " + mode + "\n" + dateText + (p.partial ? " *" : ""))
            if p.maximum > 0
                for r = 0 to p.bins.size() - 1
                    float rowVolume = p.bins.get(r)
                    if rowVolume > p.maximum * 0.0000001
                        int width = math.max(1, int(math.round(columnWidth * rowVolume / p.maximum)))
                        bool inValue = r >= p.vaLow and r <= p.vaHigh
                        float bottom = p.base + r * p.rowSize
                        drawnBoxes.push(box.new(left=left, top=bottom + p.rowSize * 0.96, right=left + width, bottom=bottom + p.rowSize * 0.04, xloc=xloc.bar_index, border_color=color.new(ink, 100), bgcolor=color.new(ink, inValue ? 15 : 72)))
                f_level(drawnLines, drawnLabels, day, profileStartTime, left, right, p.vah, "VAH", valueColor, false, f_vaExtend(d))
                f_level(drawnLines, drawnLabels, day, profileStartTime, left, right, p.val, "VAL", valueColor, false, f_vaExtend(d))
                f_level(drawnLines, drawnLabels, day, profileStartTime, left, right, p.poc, "POC", pocColor, true, f_pocExtend(d))
            else
                drawnLabels.push(label.new(left + int(columnWidth / 2), (p.highest + p.lowest) / 2, "No volume", style=label.style_none, textcolor=textInk, size=size.small))
            if showTable
                array<string> values = array.from(str.tostring(d + 1) + " " + heading + " · " + mode, dateText + (mode == "Rolling" and d > 0 ? " → latest" : ""), str.tostring(p.vah, format.mintick), str.tostring(p.poc, format.mintick), str.tostring(p.val, format.mintick), f_location(close, p.vah, p.val, p.highest, p.lowest), str.tostring(p.total, format.volume), p.partial ? "PARTIAL *" : "Available data")
                for row = 0 to 7
                    table.cell(summary, d + 1, row, values.get(row), text_color=textInk, bgcolor=color.new(chart.bg_color, 10), text_size=size.tiny)
        if showLivePrice
            int farRight = bar_index + rightOffset + (count - 1) * (columnWidth + columnGap) + columnWidth
            drawnLines.push(line.new(bar_index, close, farRight, close, xloc=xloc.bar_index, color=livePriceColor, width=2, style=line.style_dotted))
    else
        table.cell(summary, 0, 0, "No session samples. Check session hours, chart history and volume feed.", text_color=textInk, bgcolor=chart.bg_color, text_size=size.small)

← 返回列表