本页源码来自 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/
// © ahmad1darwich
//@version=6
indicator("Nexus Volume Profile - Session POC and Value Area", shorttitle = "NX VP", overlay = true, max_boxes_count = 500, max_lines_count = 500, max_labels_count = 200)
// ---------- Inputs ----------
string GRP_P = "Profile"
string modeInput = input.string("Auto", "Period", options = ["Auto", "Auto session", "Day", "Week", "Month", "Year", "Custom session", "Last N bars"], group = GRP_P, tooltip = "Auto: 1m-1h charts use the day, 2h-12h the week, daily charts the month, weekly charts the year, monthly and yearly charts the last N bars. Auto session: one profile per Asia / London / New York session (up to 1h charts). Custom session builds one profile per hours range you set.")
string sessInput = input.session("0800-1700", "Custom session hours", group = GRP_P)
string tzInput = input.string("Auto", "Session timezone", options = ["Auto", "America/New_York", "Europe/London", "Asia/Tokyo", "Australia/Sydney", "Asia/Dubai", "UTC"], group = GRP_P, tooltip = "Auto: stocks and indices use the exchange timezone; gold, forex, crypto and futures use America/New_York (the Asia / London / New York sessions are defined in that time). IANA timezones follow daylight saving automatically.")
int barsInput = input.int(200, "Bars (Last N bars mode)", minval = 20, maxval = 5000, group = GRP_P)
int rowsInput = input.int(16, "Rows", minval = 8, maxval = 40, group = GRP_P, tooltip = "Price rows in each profile. Fewer rows = cleaner chart.")
float vaInput = input.float(70.0, "Value area (%)", minval = 50.0, maxval = 95.0, step = 1.0, group = GRP_P)
int widthInput = input.int(25, "Max profile width (bars)", minval = 5, maxval = 200, group = GRP_P, tooltip = "Width of the longest row. Short periods are capped automatically so the profile never covers the chart.")
string alignInput = input.string("Right", "Profile side", options = ["Left", "Right"], group = GRP_P)
int keepInput = input.int(0, "Finished profiles to keep", minval = 0, maxval = 6, group = GRP_P, tooltip = "0 = only the live profile (default). Set 1 or more to also show the previous periods next to it.")
bool farRightInput = input.bool(true, "Profile at far right", group = GRP_P, tooltip = "Places the live profile rows after the last candle, at the far right of the chart, so they do not cover the candles.")
int farGapInput = input.int(1, "Gap from last bar (bars)", minval = 0, maxval = 50, group = GRP_P)
string tagSizeInput = input.string("Tiny", "Price tag size", options = ["Tiny", "Small", "Normal"], group = GRP_P, tooltip = "Size of the POC / VAH / VAL price capsules. Tiny is the most compact.")
bool pocExtInput = input.bool(true, "POC line extends right", group = GRP_P, tooltip = "The live POC line keeps going to the right edge of the chart.")
bool pocExtLeftInput = input.bool(true, "POC line extends left", group = GRP_P, tooltip = "The live POC line keeps going to the left edge of the chart (long on the left), while its right side stays short (see POC right length). Turn off for a short line on the right side only.")
int pocLenInput = input.int(8, "POC right length (bars)", minval = 2, maxval = 400, group = GRP_P, tooltip = "Length of the short POC line that runs to the right of the profile, ending in the POC price capsule. Used when POC line extends right is on.")
string vaTagSideInput = input.string("Left", "VAH / VAL tags side", options = ["Left", "Right"], group = GRP_P, tooltip = "Left puts the VAH and VAL price capsules on the left (north) side of the profile rows. Right keeps them on the right.")
bool vaFlipInput = input.bool(true, "VAH / VAL tags: flip the pointer", group = GRP_P, tooltip = "On: the capsule pointer faces away from the profile rows (towards the north / outer side) and the capsule sits next to the rows. Off: the pointer faces the rows.")
int vaFlipGapInput = input.int(8, "VAH / VAL flipped tag offset (bars)", minval = 0, maxval = 40, group = GRP_P, tooltip = "Extra distance used when the pointer is flipped, so the capsule does not cover the rows. Raise it if your chart is zoomed in.")
bool tagsInFrameInput = input.bool(true, "Price tags inside the frame", group = GRP_P, tooltip = "Puts the POC / VAH / VAL capsules inside the frame, near its right edge, instead of next to the profile rows.")
int tagStaggerInput = input.int(11, "POC tag shift left (bars)", minval = 0, maxval = 60, group = GRP_P, tooltip = "Moves the POC capsule left of the VAH / VAL capsules so they never overlap.")
string GRP_L = "Layers"
bool showFrameInput = input.bool(true, "Frame (lines, circles, arrow)", group = GRP_L)
bool showPocInput = input.bool(true, "POC line", group = GRP_L)
bool showVaInput = input.bool(true, "VAH / VAL lines", group = GRP_L)
bool showTagsInput = input.bool(true, "Price tags on the right", group = GRP_L)
bool showNakedInput = input.bool(true, "Naked POC from past periods", group = GRP_L)
int nakedKeepInput = input.int(4, "Naked POCs to keep", minval = 1, maxval = 10, group = GRP_L)
bool showDashInput = input.bool(true, "Dashboard", group = GRP_L)
bool showCandlesInput = input.bool(true, "Recolor candles blue / yellow (v3)", group = GRP_L, tooltip = "Colors every candle in one solid color, including wick and border. Pick the pair in Colors > Candle style. Independent of the Theme setting.")
bool glassInput = input.bool(true, "Glass effect (bright edges and glow)", group = GRP_L)
bool showSigInput = input.bool(true, "Buy / Sell triangles", group = GRP_L, tooltip = "Blue triangle = buy: price touches the bottom edge of the frame and a bullish candle closes. Yellow triangle = sell: price touches the top edge of the frame and a bearish candle closes. Signals alternate.")
int minFrameBarsInput = input.int(12, "Frame minimum bars", minval = 3, maxval = 200, group = GRP_L, tooltip = "No frame signals until the current period has at least this many bars, so the frame range is meaningful.")
float edgeTolInput = input.float(0.25, "Edge touch tolerance (x ATR)", minval = 0.0, step = 0.05, group = GRP_L, tooltip = "How close to the frame edge the wick must reach to count as a touch.")
int sigGapInput = input.int(5, "Minimum bars between signals", minval = 0, group = GRP_L)
bool solidWickInput = input.bool(true, "Solid wicks (same color as body)", group = GRP_L, tooltip = "Draws each candle wick as a line in the body color on top of the chart's own wick, so no red or green wick shows. Older bars beyond the coverage below keep the chart's own wick color.")
int wickBarsInput = input.int(450, "Solid wick coverage (bars) v6", minval = 10, maxval = 465, group = GRP_L, tooltip = "How many recent bars get a solid wick line in the body color, so every visible wick matches its candle. Lower it if you keep many finished profiles, since TradingView allows at most 500 lines in total.")
int wickWidthInput = input.int(2, "Solid wick width v6", minval = 1, maxval = 4, group = GRP_L, tooltip = "Thickness of the solid wick lines. 2 covers the chart's own wick completely so only the body color shows.")
string dashPosInput = input.string("Bottom right", "Dashboard position", options = ["Top right", "Bottom right", "Top left", "Bottom left"], group = GRP_L)
string GRP_C = "Colors"
string themeInput = input.string("Custom", "Theme", options = ["Custom", "Neon", "Classic", "Minimal", "Mono"], group = GRP_C, tooltip = "Custom uses the color pickers below. The other themes override them with a calm palette.")
color lowCIn = input.color(#1565C0, "Row color - low volume", group = GRP_C)
color highCIn = input.color(#00D9FF, "Row color - high volume", group = GRP_C)
color pocCIn = input.color(#FF9800, "POC", group = GRP_C)
color vaCIn = input.color(#4FC3F7, "VAH / VAL lines", group = GRP_C)
color frameCIn = input.color(#FFD600, "Frame and circles", group = GRP_C)
color buyCIn = input.color(#00B0FF, "Buy side (dashboard)", group = GRP_C)
color sellCIn = input.color(#FF9800, "Sell side (dashboard)", group = GRP_C)
color nakedCIn = input.color(#FFD180, "Naked POC", group = GRP_C)
color vahTagCIn = input.color(#2979FF, "VAH tag color", group = GRP_C)
color valTagCIn = input.color(#00BFA5, "VAL tag color", group = GRP_C)
string candleStyleInput = input.string("Blue / Yellow", "Candle style (v3)", options = ["Blue / Yellow", "Yellow / Red", "All yellow", "Custom colors"], group = GRP_C, tooltip = "Blue / Yellow (default): up candles blue, down candles yellow, with matching wick and border. Yellow / Red: up yellow, down red. All yellow: every candle yellow. Custom colors uses the two pickers below.")
color candleUpIn = input.color(#FFD600, "Custom candle up", group = GRP_C)
color candleDnIn = input.color(#F23645, "Custom candle down", group = GRP_C)
color textCInput = input.color(#B2B5BE, "Dashboard text", group = GRP_C)
color tagTextInput = input.color(#FFFFFF, "Tag text", group = GRP_C)
int inTrInput = input.int(10, "Row transparency - inside value area", minval = 0, maxval = 95, group = GRP_C)
int outTrInput = input.int(45, "Row transparency - outside value area", minval = 0, maxval = 95, group = GRP_C)
pick5(color custom, color neon, color classic, color minimal, color mono) =>
themeInput == "Custom" ? custom : themeInput == "Neon" ? neon : themeInput == "Classic" ? classic : themeInput == "Minimal" ? minimal : mono
color lowCInput = pick5(lowCIn, #1E5FB8, #1F4E9C, #4A5F7A, #5D606B)
color highCInput = pick5(highCIn, #2BC4F5, #4FA3D9, #8FA8C8, #B2B5BE)
color pocCInput = pick5(pocCIn, #FFA726, #F5A623, #C9A227, #E0E3EB)
color vaCInput = pick5(vaCIn, #8FA8C8, #787B86, #9598A1, #9598A1)
color frameCInput = pick5(frameCIn, #FFC247, #B8860B, #B2B5BE, #B2B5BE)
color buyCInput = pick5(buyCIn, #29B6F6, #089981, #26A69A, #D1D4DC)
color sellCInput = pick5(sellCIn, #FFA726, #F23645, #EF5350, #787B86)
color nakedCInput = pick5(nakedCIn, #FFD180, #FFC107, #C9A227, #B2B5BE)
color candleUpC = candleStyleInput == "Yellow / Red" ? #FFD600 : candleStyleInput == "Blue / Yellow" ? #1E9BFF : candleStyleInput == "All yellow" ? #FFD600 : candleUpIn
color candleDnC = candleStyleInput == "Yellow / Red" ? #FF3B3B : candleStyleInput == "Blue / Yellow" ? #FFC21A : candleStyleInput == "All yellow" ? #FFD600 : candleDnIn
// ---------- Types and state ----------
type Prof
array<box> boxes
array<line> lines
array<label> labs
float poc
float vah
float val
float total
float upV
float dnV
int n
type Naked
line ln
float price
int born
bool open
var array<float> loArr = array.new<float>()
var array<float> hiArr = array.new<float>()
var array<float> wArr = array.new<float>()
var array<bool> upArr = array.new<bool>()
var array<Prof> profs = array.new<Prof>()
var array<Naked> nakeds = array.new<Naked>()
var Prof liveP = na
var float prevPoc = na
var float prevVah = na
var float prevVal = na
var int finished = 0
// ---------- Period logic ----------
int tfSec = timeframe.in_seconds()
string autoMode = tfSec <= 3600 ? "Day" : tfSec < 86400 ? "Week" : tfSec <= 86400 ? "Month" : tfSec <= 604800 ? "Year" : "Last N bars"
string modeEff = modeInput == "Auto session" ? (tfSec <= 3600 ? "Auto session" : autoMode) : modeInput != "Auto" ? modeInput : autoMode
bool chD = timeframe.change("D")
bool chW = timeframe.change("W")
bool chM = timeframe.change("M")
bool chY = timeframe.change("12M")
bool exchangeTz = syminfo.type == "stock" or syminfo.type == "index" or syminfo.type == "fund" or syminfo.type == "dr"
string tzEff = tzInput != "Auto" ? tzInput : exchangeTz ? syminfo.timezone : "America/New_York"
bool inS = not na(time(timeframe.period, sessInput, tzEff))
bool inSPrev = inS[1]
bool inAsiaS = not na(time(timeframe.period, "2000-0200", tzEff))
bool inLonS = not na(time(timeframe.period, "0200-0800", tzEff))
bool inNyS = not na(time(timeframe.period, "0800-1700", tzEff))
int sessId = inAsiaS ? 1 : inLonS ? 2 : inNyS ? 3 : 0
bool sessChanged = sessId[1] != 0 and sessId != sessId[1]
bool newBoundary = modeEff == "Day" ? chD : modeEff == "Week" ? chW : modeEff == "Month" ? chM : modeEff == "Year" ? chY : false
bool closeP = bar_index > 0 and (modeEff == "Custom session" ? (inSPrev and not inS) : modeEff == "Auto session" ? sessChanged : newBoundary)
bool active = modeEff == "Custom session" ? inS : modeEff == "Auto session" ? sessId != 0 : true
bool hasVol = ta.cum(nz(volume)) > 0
float atr = ta.atr(14)
// ---------- Helpers ----------
deleteProf(Prof p) =>
for b in p.boxes
b.delete()
for l in p.lines
l.delete()
for t in p.labs
t.delete()
true
// Builds one profile from the stored bars of the current period and draws it ending at bar x1.
drawProfile(int x1, bool isLive) =>
int n = loArr.size()
float lo = loArr.min()
float hi = hiArr.max()
int rows = rowsInput
float rng = math.max(hi - lo, syminfo.mintick * rows)
float step = rng / rows
array<float> v = array.new_float(rows, 0.0)
float upV = 0.0
float dnV = 0.0
for k = 0 to n - 1
float l = loArr.get(k)
float h = hiArr.get(k)
float wv = wArr.get(k)
int r1 = math.max(0, math.min(rows - 1, int(math.floor((l - lo) / step))))
int r2 = math.max(r1, math.min(rows - 1, int(math.floor((h - lo) / step))))
float part = wv / (r2 - r1 + 1)
for r = r1 to r2
v.set(r, v.get(r) + part)
if upArr.get(k)
upV += wv
else
dnV += wv
float maxV = v.max()
float total = v.sum()
int pocI = v.indexof(maxV)
// Value area: start at the POC and add the bigger neighbour until the target share is inside.
int loI = pocI
int hiI = pocI
float acc = maxV
float target = total * vaInput / 100.0
while acc < target and (loI > 0 or hiI < rows - 1)
float upN = hiI < rows - 1 ? v.get(hiI + 1) : -1.0
float dnN = loI > 0 ? v.get(loI - 1) : -1.0
if upN >= dnN
hiI += 1
acc += upN
else
loI -= 1
acc += dnN
float pocP = lo + (pocI + 0.5) * step
float vahP = lo + (hiI + 1) * step
float valP = lo + loI * step
Prof p = Prof.new()
p.boxes := array.new<box>()
p.lines := array.new<line>()
p.labs := array.new<label>()
p.poc := pocP
p.vah := vahP
p.val := valP
p.total := total
p.upV := upV
p.dnV := dnV
p.n := n
int x0 = x1 - n + 1
int maxW = math.max(3, math.min(widthInput, int(n * 0.85)))
int xe = isLive and farRightInput ? x1 + farGapInput + maxW : x1
// Histogram rows
for i = 0 to rows - 1
float vv = v.get(i)
if vv > 0 and maxV > 0
float frac = vv / maxV
int wb = math.max(1, int(math.round(frac * maxW)))
bool inVa = i >= loI and i <= hiI
bool isPoc = i == pocI
color base = isPoc ? pocCInput : color.from_gradient(frac, 0.0, 1.0, lowCInput, highCInput)
int tr = isPoc ? 0 : inVa ? inTrInput : outTrInput
int l = alignInput == "Left" ? x0 : xe - wb
int r = alignInput == "Left" ? x0 + wb : xe
float top = lo + (i + 1) * step - step * 0.07
float bot = lo + i * step + step * 0.07
color edgeC = glassInput ? color.new(isPoc ? pocCInput : highCInput, inVa ? 35 : 60) : na
p.boxes.push(box.new(l, top, r, bot, border_color = edgeC, border_width = 1, bgcolor = color.new(base, tr)))
// POC, VAH, VAL
if showPocInput
bool extR = isLive and pocExtInput
bool extL = isLive and pocExtLeftInput
// Left side may extend to the chart edge; the right side ends at the set length (no infinite extension)
string exMode = extL ? extend.left : extend.none
int pocEnd = extR ? xe + pocLenInput : xe
// Live profile at far right: short line starting at the last bar, not at the period start
int pocStart = isLive and farRightInput and not extL ? (extR ? xe : x1) : x0
if glassInput
p.lines.push(line.new(pocStart, pocP, pocEnd, pocP, color = color.new(pocCInput, 95), width = 3, extend = exMode))
p.lines.push(line.new(pocStart, pocP, pocEnd, pocP, color = pocCInput, width = 1, extend = exMode))
if showVaInput
p.lines.push(line.new(x0, vahP, x1, vahP, color = color.new(vaCInput, 20), width = 1, style = line.style_dashed))
p.lines.push(line.new(x0, valP, x1, valP, color = color.new(vaCInput, 20), width = 1, style = line.style_dashed))
// Frame: vertical lines, corner circles, double arrow
float botY = lo - step
if showFrameInput
p.lines.push(line.new(x0, hi, x1, hi, color = color.new(frameCInput, 25), width = 1))
p.lines.push(line.new(x0, hi, x0, botY, color = color.new(frameCInput, 25), width = 1))
p.lines.push(line.new(x1, hi, x1, botY, color = color.new(frameCInput, 25), width = 1))
p.lines.push(line.new(x0, botY, x1, botY, color = frameCInput, width = 1, style = line.style_arrow_both))
p.labs.push(label.new(x0, hi, "", style = label.style_circle, color = frameCInput, size = size.tiny))
p.labs.push(label.new(x1, hi, "", style = label.style_circle, color = frameCInput, size = size.tiny))
p.labs.push(label.new(x0, botY, "", style = label.style_circle, color = frameCInput, size = size.tiny))
p.labs.push(label.new(x1, botY, "", style = label.style_circle, color = frameCInput, size = size.tiny))
string vtxt = (hasVol ? "Vol " : "TPO ") + str.tostring(total, format.volume) + " • Range " + str.tostring(hi - lo, format.mintick)
string tip = "Buy/sell split is a candle-direction proxy, not real delta. Buy " + str.tostring(total > 0 ? upV * 100.0 / total : 0.0, "#") + "%"
p.labs.push(label.new(int(math.round((x0 + x1) / 2.0)), hi - step * 0.15, vtxt, style = label.style_label_up, color = color.new(#131722, 15), textcolor = textCInput, size = size.tiny, tooltip = tip))
// Price tags (live profile only)
if isLive and showTagsInput
string tagSz = tagSizeInput == "Tiny" ? size.tiny : tagSizeInput == "Small" ? size.small : size.normal
color pocSolid = color.new(pocCInput, 0)
color vahSolid = color.new(vahTagCIn, 0)
color valSolid = color.new(valTagCIn, 0)
if tagsInFrameInput
// Capsules sit inside the frame, near its right edge; POC is shifted left so the three never overlap
int inX = math.max(x0, x1 - 1)
int pocX = math.max(x0, x1 - 1 - tagStaggerInput)
p.labs.push(label.new(pocX, pocP, "POC: " + str.tostring(pocP, format.mintick), style = label.style_label_left, color = pocSolid, textcolor = tagTextInput, size = tagSz, text_formatting = text.format_bold))
p.labs.push(label.new(inX, vahP, "VAH: " + str.tostring(vahP, format.mintick), style = label.style_label_left, color = vahSolid, textcolor = tagTextInput, size = tagSz, text_formatting = text.format_bold))
p.labs.push(label.new(inX, valP, "VAL: " + str.tostring(valP, format.mintick), style = label.style_label_left, color = valSolid, textcolor = tagTextInput, size = tagSz, text_formatting = text.format_bold))
else
int pocTagX = showPocInput and pocExtInput ? xe + pocLenInput : xe + 2
p.labs.push(label.new(pocTagX, pocP, "POC: " + str.tostring(pocP, format.mintick), style = label.style_label_left, color = pocSolid, textcolor = tagTextInput, size = tagSz, text_formatting = text.format_bold))
bool tagsLeft = vaTagSideInput == "Left"
int leftEdge = alignInput == "Left" ? x0 - 1 : xe - maxW - 1
bool pointLeft = tagsLeft ? vaFlipInput : not vaFlipInput
int flipShift = vaFlipInput ? vaFlipGapInput : 0
int vaTagX = tagsLeft ? leftEdge - flipShift : xe + 2 + flipShift
string vaTagStyle = pointLeft ? label.style_label_left : label.style_label_right
p.labs.push(label.new(vaTagX, vahP, "VAH: " + str.tostring(vahP, format.mintick), style = vaTagStyle, color = vahSolid, textcolor = tagTextInput, size = tagSz, text_formatting = text.format_bold))
p.labs.push(label.new(vaTagX, valP, "VAL: " + str.tostring(valP, format.mintick), style = vaTagStyle, color = valSolid, textcolor = tagTextInput, size = tagSz, text_formatting = text.format_bold))
p
// ---------- Engine ----------
bool profileDone = false
if closeP
if loArr.size() >= 2
Prof fp = drawProfile(bar_index - 1, false)
profs.push(fp)
while profs.size() > keepInput
deleteProf(profs.shift())
prevPoc := fp.poc
prevVah := fp.vah
prevVal := fp.val
finished += 1
profileDone := true
if showNakedInput
line nl = line.new(bar_index - 1, fp.poc, bar_index, fp.poc, color = color.new(nakedCInput, 15), width = 1)
nakeds.push(Naked.new(nl, fp.poc, bar_index - 1, true))
while nakeds.size() > nakedKeepInput
Naked old = nakeds.shift()
old.ln.delete()
loArr.clear()
hiArr.clear()
wArr.clear()
upArr.clear()
// Frame edges of the current period (before this bar joins it): the signals trade these edges
float frameHi = na
float frameLo = na
if active and loArr.size() >= minFrameBarsInput
frameHi := hiArr.max()
frameLo := loArr.min()
if active
loArr.push(low)
hiArr.push(high)
wArr.push(hasVol ? nz(volume) : 1.0)
upArr.push(close >= open)
if loArr.size() > (modeEff == "Last N bars" ? barsInput : 5000)
loArr.shift()
hiArr.shift()
wArr.shift()
upArr.shift()
// Naked POC life cycle: extended until a confirmed bar trades through it.
bool nakedTouched = false
if nakeds.size() > 0
for nk in nakeds
if nk.open
if barstate.isconfirmed and bar_index > nk.born and high >= nk.price and low <= nk.price
nk.open := false
nakedTouched := true
nk.ln.set_x2(bar_index)
nk.ln.set_style(line.style_dotted)
nk.ln.set_color(color.new(nakedCInput, 70))
else
nk.ln.set_x2(bar_index)
// Live profile (redrawn on the last bar only)
if barstate.islast
if not na(liveP)
deleteProf(liveP)
liveP := loArr.size() >= 2 ? drawProfile(bar_index, true) : na
// ---------- Glass candles: translucent, brighter with a bigger body ----------
float bodyPower = atr > 0 ? math.min(1.0, math.abs(close - open) / atr) : 0.5
color glassBase = close >= open ? candleUpC : candleDnC
color shineBase = color.from_gradient(0.35, 0.0, 1.0, glassBase, #FFFFFF)
color glassCandle = glassBase
// Wick and border use the same color as the body, so no second color appears
color wickDirC = glassBase
// Opaque color for the native candle so no original red shows through
color solidCandle = color.new(glassBase, 0)
// Hide the native candles completely so no original red/green shows through the glass candles
// The native candle is painted with the same solid color, so its wick and border are no longer red
barcolor(showCandlesInput ? solidCandle : na, title = "Glass candles")
// Same color for body, wick and border, drawn on top of the native candle
plotcandle(open, high, low, close, "Blue-yellow candle layer", color = showCandlesInput ? solidCandle : na, wickcolor = showCandlesInput ? solidCandle : na, bordercolor = showCandlesInput ? solidCandle : na, editable = false, force_overlay = true)
// Solid wick lines: drawn above the chart's own wick so its original color cannot show
var array<line> wickLines = array.new<line>()
var line liveWick = na
if showCandlesInput and solidWickInput
if barstate.isconfirmed
wickLines.push(line.new(bar_index, high, bar_index, low, color = glassCandle, width = wickWidthInput))
if wickLines.size() > wickBarsInput
wickLines.shift().delete()
if barstate.islast and not barstate.isconfirmed
if na(liveWick)
liveWick := line.new(bar_index, high, bar_index, low, color = glassCandle, width = wickWidthInput)
else
liveWick.set_xy1(bar_index, high)
liveWick.set_xy2(bar_index, low)
liveWick.set_color(glassCandle)
// ---------- Dashboard ----------
dashPos = dashPosInput == "Top right" ? position.top_right : dashPosInput == "Bottom right" ? position.bottom_right : dashPosInput == "Top left" ? position.top_left : position.bottom_left
var table dash = table.new(dashPos, 2, 10, border_width = 1, border_color = color.new(#787B86, 85), frame_color = color.new(frameCInput, 50), frame_width = 1)
row(int r, string k, string v, color vc) =>
dash.cell(0, r, k, text_color = textCInput, bgcolor = color.new(#131722, 10), text_size = size.small, text_halign = text.align_left)
dash.cell(1, r, v, text_color = vc, bgcolor = color.new(#131722, 10), text_size = size.small, text_halign = text.align_right, text_font_family = font.family_monospace)
if showDashInput and barstate.islast
int openN = 0
for nk in nakeds
if nk.open
openN += 1
dash.cell(0, 0, "NEXUS", text_color = color.white, bgcolor = color.new(frameCInput, 40), text_size = size.small)
dash.cell(1, 0, "Volume Profile", text_color = color.white, bgcolor = color.new(frameCInput, 40), text_size = size.small)
row(1, "Period", modeEff, highCInput)
row(2, "Data", hasVol ? "Volume" : "TPO (no volume)", hasVol ? textCInput : pocCInput)
if not na(liveP)
string where = close > liveP.vah ? "Above value" : close < liveP.val ? "Below value" : "In value"
color whereC = close > liveP.vah ? buyCInput : close < liveP.val ? sellCInput : textCInput
float dPoc = atr > 0 ? (close - liveP.poc) / atr : 0.0
float buyPct = liveP.total > 0 ? liveP.upV * 100.0 / liveP.total : 50.0
row(3, "POC", str.tostring(liveP.poc, format.mintick), pocCInput)
row(4, "VAH / VAL", str.tostring(liveP.vah, format.mintick) + " / " + str.tostring(liveP.val, format.mintick), vaCInput)
row(5, "Price", where, whereC)
row(6, "From POC", (dPoc >= 0 ? "+" : "") + str.tostring(dPoc, "0.0") + " ATR", textCInput)
row(7, "Buy / sell (proxy)", str.tostring(buyPct, "#") + "% / " + str.tostring(100.0 - buyPct, "#") + "%", color.from_gradient(buyPct, 40.0, 60.0, sellCInput, buyCInput))
row(8, "Bars in profile", str.tostring(liveP.n), textCInput)
else
row(3, "POC", "-", textCInput)
row(4, "VAH / VAL", "-", textCInput)
row(5, "Price", "waiting for bars", textCInput)
row(6, "From POC", "-", textCInput)
row(7, "Buy / sell (proxy)", "-", textCInput)
row(8, "Bars in profile", "-", textCInput)
row(9, "Naked POC open", str.tostring(openN), nakedCInput)
// ---------- Alerts (previous finished profile levels, closed bars) ----------
bool xPocUp = ta.crossover(close, prevPoc)
bool xPocDn = ta.crossunder(close, prevPoc)
bool xVahUp = ta.crossover(close, prevVah)
bool xValDn = ta.crossunder(close, prevVal)
bool evPocUp = barstate.isconfirmed and xPocUp and not closeP
bool evPocDn = barstate.isconfirmed and xPocDn and not closeP
bool evVah = barstate.isconfirmed and xVahUp and not closeP
bool evVal = barstate.isconfirmed and xValDn and not closeP
alertcondition(evPocUp, "Close above previous POC", "Nexus VP: close above the previous POC on {{ticker}} {{interval}} at {{close}}")
alertcondition(evPocDn, "Close below previous POC", "Nexus VP: close below the previous POC on {{ticker}} {{interval}} at {{close}}")
alertcondition(evVah, "Break above previous VAH", "Nexus VP: price broke above the previous value area high on {{ticker}} {{interval}}")
alertcondition(evVal, "Break below previous VAL", "Nexus VP: price broke below the previous value area low on {{ticker}} {{interval}}")
alertcondition(nakedTouched, "Naked POC touched", "Nexus VP: a naked POC was touched on {{ticker}} {{interval}}")
alertcondition(profileDone, "New profile completed", "Nexus VP: a volume profile period finished on {{ticker}} {{interval}}")
// ---------- Buy / Sell triangles (confirmed bars, alternating) ----------
float tolPx = na(atr) ? 0.0 : atr * edgeTolInput
bool touchLo = not na(frameLo) and low <= frameLo + tolPx and high >= frameLo
bool touchHi = not na(frameHi) and high >= frameHi - tolPx and low <= frameHi
bool bullClose = close > open
bool bearClose = close < open
bool rawBuy = barstate.isconfirmed and touchLo and bullClose and not closeP
bool rawSell = barstate.isconfirmed and touchHi and bearClose and not closeP
var int lastSigDir = 0
var int lastSigBar = -100000
bool gapOk = bar_index - lastSigBar >= sigGapInput
bool buySig = rawBuy and lastSigDir != 1 and gapOk
bool sellSig = rawSell and lastSigDir != -1 and gapOk and not buySig
if buySig
lastSigDir := 1
lastSigBar := bar_index
if sellSig
lastSigDir := -1
lastSigBar := bar_index
if showSigInput and buySig
label.new(bar_index, low - atr * 0.3, "", style = label.style_triangleup, color = #1E9BFF, size = size.small, tooltip = "BUY: bullish close at the bottom edge of the frame " + str.tostring(frameLo, format.mintick))
if showSigInput and sellSig
label.new(bar_index, high + atr * 0.3, "", style = label.style_triangledown, color = #FFC21A, size = size.small, tooltip = "SELL: bearish close at the top edge of the frame " + str.tostring(frameHi, format.mintick))
alertcondition(buySig, "Buy signal", "Nexus VP: BUY (bounce from the bottom edge of the frame) on {{ticker}} {{interval}} at {{close}}")
alertcondition(sellSig, "Sell signal", "Nexus VP: SELL (rejection at the top edge of the frame) on {{ticker}} {{interval}} at {{close}}")