本页源码来自 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/
// © officialjackofalltrades
//@version=6
indicator("Key Levels Map [JOAT]", "Key Levels Map", overlay = true,
max_boxes_count = 500, max_lines_count = 500, max_labels_count = 500)
// ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════
// 0. SAFETY
// ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════
max_bars_back(time, 5000)
// Scale anchor: a script that only draws boxes / lines / labels can land on its own price scale on a customer's
// chart. One invisible plot pins it to the price scale. display.pane keeps it out of the status line and data window.
plot(close, "Scale anchor (invisible)", color = color.new(#000000, 100), display = display.pane, editable = false)
float atrK = ta.atr(14) // shared ATR for glow padding, lane gaps, distances and confluence
// ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════
// 1. THEME
// ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════
string G1 = "Theme"
string theme = input.string("JOAT Signature", "Theme", group = G1,
options = ["JOAT Signature", "Midnight Blue / Red", "Aurora Night", "Delta Cyan / Pink", "Paper & Ink", "Lime Ember", "Custom"],
tooltip = "Named presets. JOAT Signature is the brand pair. Paper & Ink is the clean black / white preset: direction is carried by position and line style, not colour. Custom uses the colour pickers below.")
int bright = input.int(3, "Brightness", minval = 1, maxval = 5, group = G1,
tooltip = "1 = faint, 3 = as designed, 5 = vivid. Scales every fill and glow transparency; solid lines and plates stay solid.")
string bgMode = input.string("Auto", "Chart background", options = ["Auto", "Dark", "Light"], group = G1,
tooltip = "Auto reads the luminance of the chart background and swaps every role so it stays readable on a white chart.")
color inBull = input.color(#5CF0D7, "Custom bull / bear", group = G1, inline = "c1")
color inBear = input.color(#B32AC3, "", group = G1, inline = "c1")
color inAcc = input.color(#FFFFFF, "Custom accent / neutral", group = G1, inline = "c2")
color inNeu = input.color(#787B86, "", group = G1, inline = "c2")
color inTxt = input.color(#D1D4DC, "Custom text / panel", group = G1, inline = "c3")
color inPanel = input.color(#0E1116, "", group = G1, inline = "c3")
color inGlow = input.color(#5CF0D7, "Custom glow", group = G1, inline = "c4")
// f_lum: relative luminance 0..1 of any colour (Rec. 601 weights). Used for light / dark awareness and plate ink.
f_lum(color c) =>
(0.299 * color.r(c) + 0.587 * color.g(c) + 0.114 * color.b(c)) / 255.0
bool isLight = bgMode == "Light" ? true : bgMode == "Dark" ? false : f_lum(chart.bg_color) > 0.5
bool isMono = theme == "Paper & Ink"
// Roles, resolved once. Defaults = JOAT Signature. Each preset overrides every role, with the white-chart swap.
color cBull = isLight ? #12B5A0 : #5CF0D7
color cBear = isLight ? #8E1FA0 : #B32AC3
color cAcc = isLight ? #131722 : #FFFFFF
color cNeu = #787B86
color cTxt = isLight ? #131722 : #D1D4DC
color cPanel = isLight ? #FFFFFF : #0E1116
color cGlow = isLight ? #12B5A0 : #5CF0D7
color cCandle = cAcc // colour for the "Mono" candle paint (white bodies on black, ink on white)
if theme == "Midnight Blue / Red"
cBull := #2962FF
cBear := #F23645
cAcc := isLight ? #131722 : #FFFFFF
cNeu := #787B86
cTxt := isLight ? #131722 : #D1D4DC
cPanel := isLight ? #FFFFFF : #0B0F13
cGlow := #2962FF
cCandle := cAcc
else if theme == "Aurora Night"
cBull := isLight ? #00A86B : #00E676
cBear := isLight ? #C2185B : #E040FB
cAcc := isLight ? #B59A00 : #FDD835
cNeu := #5C6BC0
cTxt := isLight ? #1A1F2E : #E6F1FF
cPanel := isLight ? #F4F6FB : #0A0E17
cGlow := isLight ? #0097A7 : #00BCD4 // the outer aurora hue (cyan); bear outer is #7C4DFF
cCandle := cNeu
else if theme == "Delta Cyan / Pink"
cBull := isLight ? #0097A7 : #00E5FF
cBear := isLight ? #D81B60 : #FF2E88
cAcc := isLight ? #B59A00 : #FFD600
cNeu := #6B7280
cTxt := isLight ? #111827 : #F8FAFC
cPanel := isLight ? #FFFFFF : #111827
cGlow := isLight ? #0097A7 : #00E5FF
cCandle := cNeu
else if theme == "Paper & Ink"
color ink = isLight ? #111827 : #F0F3FA
cBull := ink
cBear := ink // same ink; bear objects carry direction by DASHED style (kBearStyle)
cAcc := #2962FF // the one accent: "live / nearest"; #F23645 is reserved for "broken"
cNeu := #B2B5BE
cTxt := ink
cPanel := isLight ? #FFFFFF : #131722
cGlow := #2962FF
cCandle := ink
else if theme == "Lime Ember"
cBull := isLight ? #64DD17 : #B2FF59 // below-price liquidity
cBear := isLight ? #2962FF : #448AFF // above-price liquidity
cAcc := #FF9800 // ember: POC / peak row
cNeu := #787B86
cTxt := isLight ? #131722 : #E0E0E0
cPanel := isLight ? #FFFFFF : #161A25
cGlow := #FF9800
cCandle := cNeu
else if theme == "Custom"
cBull := inBull
cBear := inBear
cAcc := inAcc
cNeu := inNeu
cTxt := inTxt
cPanel := inPanel
cGlow := inGlow
cCandle := inAcc
color cBroken = #F23645 // grey-or-red for dead things; Paper & Ink "broken"
string kBearStyle = isMono ? line.style_dashed : line.style_solid // Paper & Ink: direction by style, not hue
int kPanelT = isLight ? 8 : 15 // panel alpha: 92 % on white, 85 % on dark
// f_t: brightness-aware transparency. Scales the OPACITY (100 - t) by 0.5x .. 1.5x so faint things stay faint
// and solid things stay solid; fills (t >= 40) get +4 on a white chart and are floored at 92 in Paper & Ink.
f_t(int t) =>
float op = 100.0 - t
float k = 1.0 + (bright - 3) * 0.25
float tt = 100.0 - op * k
if t >= 40
if isMono
tt := math.max(tt, 92.0)
if isLight
tt += 4.0
math.min(100, math.max(0, math.round(tt)))
// f_ink: black or white text for a solid plate of colour c, by luminance.
f_ink(color c) =>
f_lum(c) > 0.55 ? #0B0F13 : #FFFFFF
// f_grad: 3-stop gradient c1 (t = 0) -> c2 (t = 0.5) -> c3 (t = 1).
f_grad(color c1, color c2, color c3, float t) =>
float tt = math.min(1.0, math.max(0.0, nz(t, 0.5)))
tt < 0.5 ? color.from_gradient(tt, 0.0, 0.5, c1, c2) : color.from_gradient(tt, 0.5, 1.0, c2, c3)
// ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════
// 4a. LAYOUT — clamps (defined early because the glow and text helpers use them)
// ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════
// f_xo: a drawing anchored further back than ~5,000 bars kills the script on a LIVE bar (RE10143) and a Basic
// account only has 5,000 bars anyway. f_xr: nothing may be drawn more than 500 bars ahead.
f_xo(int b) =>
math.max(b, bar_index - 4990)
f_xr(int b) =>
math.min(b, bar_index + 490)
// ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════
// 2. GLOW
// ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════
// f_glowBox: N concentric boxes. Halo h (1..layers-1) is padded h * 0.05 ATR outward and fades toward 97;
// the last element of the returned array is the CORE box (fill baseT, 1-px border). Keep the array so the
// retirement helpers can delete all layers together.
f_glowBox(int x1, float top, int x2, float bot, color c, int layers, int baseT) =>
array<box> out = array.new<box>()
int xl = f_xo(math.min(x1, x2))
int xr = f_xr(math.max(x1, x2))
float hi = math.max(top, bot)
float lo = math.min(top, bot)
float pad = nz(atrK, (hi - lo) * 0.2) * 0.05
int n = math.max(1, layers)
if n > 1
for i = 1 to n - 1
int h = n - i // outermost first so the core draws on top
int tH = f_t(math.min(99, baseT + math.round(float(97 - baseT) * h / n)))
array.push(out, box.new(xl, hi + pad * h, xr, lo - pad * h,
border_color = color.new(c, 100), border_width = 1, bgcolor = color.new(c, tH)))
array.push(out, box.new(xl, hi, xr, lo,
border_color = color.new(c, f_t(math.max(0, baseT - 50))), border_width = 1, bgcolor = color.new(c, f_t(baseT))))
out
// f_glowLine: a solid core line of `width` with layers-1 wider, fainter halos beneath it. Last element = core.
f_glowLine(int x1, float y1, int x2, float y2, color c, int layers, int width) =>
array<line> out = array.new<line>()
int xl = f_xo(x1)
int xr = f_xr(x2)
int n = math.max(1, layers)
if n > 1
for i = 1 to n - 1
int h = n - i
int tH = f_t(math.min(99, 70 + math.round(27.0 * h / n)))
array.push(out, line.new(xl, y1, xr, y2, color = color.new(c, tH), width = math.max(1, width + 2 * h)))
array.push(out, line.new(xl, y1, xr, y2, color = color.new(c, f_t(0)), width = math.max(1, width)))
out
// ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════
// 3. TEXT
// ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════
// f_plate: label on a SOLID plate of colour c, text in f_ink(c). sty = label.style_*, sz = size.*
f_plate(int x, float y, string txt, color c, string sty, string sz) =>
label.new(f_xr(f_xo(x)), y, txt, xloc = xloc.bar_index, yloc = yloc.price, color = c, style = sty,
textcolor = f_ink(c), size = sz)
// f_tag: plateless text (transparent background, coloured text). Evolves f_tag of [JOAT] Fibonacci Vault.
// Left-aligned so a two-line tag reads as one block from the line end.
f_tag(int x, float y, string txt, color c, string sty, string sz) =>
label.new(f_xr(f_xo(x)), y, txt, xloc = xloc.bar_index, yloc = yloc.price, color = color.new(#000000, 100),
style = sty, textcolor = c, size = sz, textalign = text.align_left)
// f_grp: thousands separators on a string of digits: "26571" -> "26,571"
f_grp(string ip) =>
string g = ""
int n = str.length(ip)
if n > 0
for i = 0 to n - 1
g += str.substring(ip, i, i + 1)
int rem = n - 1 - i
if rem > 0 and rem % 3 == 0
g += ","
g
// f_px: price with thousands separators at mintick precision: 24,550.25 / 1.08432 / —
f_px(float p) =>
string out = "—"
if not na(p)
string s = str.tostring(math.abs(p), format.mintick)
array<string> parts = str.split(s, ".")
string fp = ""
if array.size(parts) > 1
fp := "." + array.get(parts, 1)
out := (p < 0 ? "-" : "") + f_grp(array.get(parts, 0)) + fp
out
// f_pts: an unsigned distance in price units, whole numbers from 100 up: 428 / 1,233 / 42.25
f_pts(float d) =>
float a = math.abs(d)
na(d) ? "—" : a >= 100 ? f_grp(str.tostring(math.round(a))) : f_px(a)
// f_wrap: joins the pieces of s (split on sep) into lines of at most maxLen characters. A break after " + " keeps
// the "+" at the end of the line; a break between words drops the space.
f_wrap(string s, string sep, int maxLen) =>
array<string> parts = str.split(s, sep)
string mark = str.trim(sep)
string brk = mark == "" ? "\n" : " " + mark + "\n"
string out = ""
string cur = ""
for p in parts
if cur == ""
cur := p
else if str.length(cur) + str.length(sep) + str.length(p) <= maxLen
cur += sep + p
else
out += cur + brk
cur := p
out + cur
// f_k: compact numbers: 1.2K 3.4M 2.1B (below 1,000: up to two decimals)
f_k(float v) =>
string out = "—"
if not na(v)
float a = math.abs(v)
string sgn = v < 0 ? "-" : ""
if a >= 1e9
out := sgn + str.tostring(a / 1e9, "#.#") + "B"
else if a >= 1e6
out := sgn + str.tostring(a / 1e6, "#.#") + "M"
else if a >= 1e3
out := sgn + str.tostring(a / 1e3, "#.#") + "K"
else
out := sgn + str.tostring(a, "#.##")
out
// ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════
// 4b. LAYOUT — label lane de-collision + object retirement
// ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════
// Lane register: every right-edge label asks f_lane for a y. The register is cleared at the start of each
// last-bar redraw (f_laneReset) so the slots are recomputed from scratch every tick.
var array<float> laneReg = array.new<float>()
var array<int> laneLn = array.new<int>() // text lines of each registered tag (a two-line tag is twice as tall)
f_laneReset() =>
array.clear(laneReg)
array.clear(laneLn)
// f_lane: returns the nearest free y to `y`, trying y, y - gap, y + gap, y - 2gap, y + 2gap ... (gap = ATR mult =
// one text line). Two tags clear each other when their centres are half their summed heights apart.
f_lane(float y, float gapAtrMult, int nLines) =>
float gap = math.max(nz(atrK) * gapAtrMult, syminfo.mintick * 2)
float out = y
for k = 0 to 40
float off = math.ceil(k / 2.0) * gap
float cand = k % 2 == 0 ? y + off : y - off
bool free = true
if array.size(laneReg) > 0
for r = 0 to array.size(laneReg) - 1
if math.abs(array.get(laneReg, r) - cand) < gap * (array.get(laneLn, r) + nLines) / 2.0 * 0.999
free := false
if free
out := cand
break
array.push(laneReg, out)
array.push(laneLn, nLines)
out
// Retirement: push every new object into one array per kind, then cap it. Oldest leaves first (array.shift).
string G3 = "Limits (free account)"
// Only lines leave history behind here (boxes and labels are the live set, rebuilt on the last bar), so the box and
// label caps of the kit are not exposed. maxval 460 leaves room for the ≤ 28 live lines inside the 500 budget.
int maxLines = input.int(60, "Max lines kept", minval = 4, maxval = 460, group = G3, tooltip = "Past periods' level lines are deleted oldest-first past this count. The live levels (at most 28 lines) are redrawn on the last bar, outside this cap.")
f_capBoxes(array<box> a, int maxN) =>
while array.size(a) > math.max(0, maxN)
box.delete(array.shift(a))
f_capLines(array<line> a, int maxN) =>
while array.size(a) > math.max(0, maxN)
line.delete(array.shift(a))
f_capLabels(array<label> a, int maxN) =>
while array.size(a) > math.max(0, maxN)
label.delete(array.shift(a))
// ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════
// 5. DASHBOARD
// ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════
string G2 = "Dashboard"
bool showDash = input.bool(true, "Show dashboard", group = G2)
string dashPos = input.string("Top Right", "Dashboard position", group = G2,
options = ["Top Left", "Top Center", "Top Right", "Middle Left", "Middle Center", "Middle Right", "Bottom Left", "Bottom Center", "Bottom Right"])
string dashSize = input.string("Small", "Dashboard size", options = ["Tiny", "Small", "Normal", "Large"], group = G2)
bool dashCompact = input.bool(false, "Compact dashboard", group = G2, tooltip = "Fewer rows for phones: header, one key row and the Read line.")
bool dashTint = input.bool(true, "Tinted value cells", group = G2, tooltip = "Value cells carry a faint tint of their own colour.")
f_pos(string s) =>
switch s
"Top Left" => position.top_left
"Top Center" => position.top_center
"Top Right" => position.top_right
"Middle Left" => position.middle_left
"Middle Center" => position.middle_center
"Middle Right" => position.middle_right
"Bottom Left" => position.bottom_left
"Bottom Center" => position.bottom_center
=> position.bottom_right
f_size(string s) =>
switch s
"Tiny" => size.tiny
"Small" => size.small
"Normal" => size.normal
"Large" => size.large
=> size.small
// f_dashNew: panel in cPanel at the theme alpha, 1-px neutral frame. Rows = header + data rows + Read line.
f_dashNew(string pos, int cols, int rows) =>
table.new(f_pos(pos), cols, rows, bgcolor = color.new(cPanel, kPanelT), frame_color = color.new(cNeu, 40),
frame_width = 1, border_color = color.new(cNeu, 78), border_width = 1)
int dashRows = dashCompact ? 3 : 10 // header + 8 data rows + Read (compact: header + nearest + Read)
var table dash = f_dashNew(dashPos, 2, dashRows)
var array<int> dCur = array.from(0) // row cursor (arrays are the only globals a function may mutate)
var array<int> dMerged = array.from(-1) // row already merged for the Read line
// f_dBegin: rewind; call once per last-bar redraw before f_dHead. Deviation from the kit: no table.clear. This
// dashboard writes the same rows on every tick (the row set only depends on the chart type and inputs, and a change
// of either reloads the script), so every cell is overwritten anyway, and not clearing keeps the Read row's merge
// intact whether or not table.clear drops merges.
f_dBegin() =>
array.set(dCur, 0, 0)
// f_dHead: title band (bold, glow tint) with symbol · timeframe on the right.
f_dHead(string title) =>
int r = array.get(dCur, 0)
if r < dashRows
table.cell(dash, 0, r, " " + title + " ", text_color = cTxt, text_halign = text.align_left, text_size = f_size(dashSize),
bgcolor = color.new(cGlow, isLight ? 80 : 70), text_formatting = text.format_bold)
table.cell(dash, 1, r, syminfo.ticker + " · " + timeframe.period + " ", text_color = cTxt, text_halign = text.align_right,
text_size = f_size(dashSize), bgcolor = color.new(cGlow, isLight ? 88 : 80))
array.set(dCur, 0, r + 1)
// f_dRow: name | value, value text in valueColor with an optional tint cell (evolves the 51-series f_row / f_pill).
f_dRow(string name, string value, color valueColor, string tip) =>
int r = array.get(dCur, 0)
if r < dashRows
table.cell(dash, 0, r, " " + name, text_color = color.new(cTxt, 25), text_halign = text.align_left,
text_size = f_size(dashSize), tooltip = tip)
table.cell(dash, 1, r, str.replace_all(value, "\n", " \n") + " ", text_color = valueColor, text_halign = text.align_right, text_size = f_size(dashSize),
bgcolor = dashTint ? color.new(valueColor, isLight ? 90 : 86) : color.new(cPanel, 100), tooltip = tip)
array.set(dCur, 0, r + 1)
// f_dRead: the one-line "Read" sentence, merged across both columns, italic. Always the last row.
f_dRead(string txt, string tip) =>
int r = array.get(dCur, 0)
if r < dashRows
if array.get(dMerged, 0) != r
table.merge_cells(dash, 0, r, 1, r)
array.set(dMerged, 0, r)
table.cell(dash, 0, r, " " + str.replace_all(txt, "\n", " \n ") + " ", text_color = cTxt, text_halign = text.align_left, text_size = f_size(dashSize),
text_formatting = text.format_italic, tooltip = tip)
array.set(dCur, 0, r + 1)
// ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════
// 6. CANDLES
// ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════
string G4 = "Candles"
string paintMode = input.string("Off", "Candle paint", options = ["Off", "Score", "Mono"], group = G4,
tooltip = "Off = chart candles. Score = premium / discount gradient by where the close sits in the prior-day range, in the same roles as the levels: at or above PDH = the high (bear) colour, at the 50 % = neutral, at or below PDL = the low (bull) colour. Prior week on daily / weekly charts, prior month on monthly. Mono = one colour so the levels carry all the colour.")
// f_candlePaint: na (Off), f_grad(cBear, cNeu, cBull, score) (Score) or cCandle (Mono). Feed it to barcolor().
f_candlePaint(string mode, float score) =>
color out = na
if mode == "Score"
out := f_grad(cBear, cNeu, cBull, score)
else if mode == "Mono"
out := cCandle
out
// ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════
// 7. KEY LEVELS — inputs
// ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════
string G7 = "Daily levels"
string tipD = "Prior-day levels are drawn from the first bar of the current exchange day to the right edge. Intraday charts only."
bool onPDH = input.bool(true, "PDH prior day high", group = G7, tooltip = tipD)
bool onPDL = input.bool(true, "PDL prior day low", group = G7, tooltip = tipD)
bool onPDC = input.bool(true, "PDC prior day close", group = G7, tooltip = tipD)
bool onDO = input.bool(true, "Daily open", group = G7, tooltip = "Open of the first bar of the exchange day (18:00 ET on CME futures, the session open on stocks).")
string G8 = "Weekly / monthly levels"
string tipW = "Drawn from the first bar of the current week / month (clamped to 4,990 bars back) to the right edge."
bool onPWH = input.bool(true, "PWH prior week high", group = G8, tooltip = tipW)
bool onPWL = input.bool(true, "PWL prior week low", group = G8, tooltip = tipW)
bool onWO = input.bool(true, "Weekly open", group = G8, tooltip = tipW)
bool onPMH = input.bool(true, "PMH prior month high", group = G8, tooltip = tipW)
bool onPML = input.bool(true, "PML prior month low", group = G8, tooltip = tipW)
bool onMO = input.bool(true, "Monthly open", group = G8, tooltip = tipW)
string G9 = "Intraday opens"
string openTZ = input.string("America/New_York", "Opens time zone", group = G9,
options = ["America/New_York", "America/Chicago", "America/Los_Angeles", "Europe/London", "Europe/Berlin", "Asia/Tokyo", "Asia/Hong_Kong", "Australia/Sydney", "UTC", "Exchange"],
tooltip = "The midnight, 08:30 and 09:30 opens are read on this clock. ICT defines them in New York time. Exchange = the symbol's own time zone.")
string tipO = "The open of the chart bar that contains this minute, so on a 1H chart the 08:30 open is the open of the 08:00 bar. Charts of 1 hour and below only. Each one stays until the next exchange day starts, then it is retired until it prints again."
bool onMid = input.bool(true, "Midnight open", group = G9, tooltip = tipO)
bool on830 = input.bool(true, "08:30 open", group = G9, tooltip = tipO)
bool on930 = input.bool(true, "09:30 open", group = G9, tooltip = tipO)
string G10 = "Developing day"
bool showDev = input.bool(true, "Day high / low rails", group = G10,
tooltip = "Today's developing high and low as thin dotted rails from the bar that made them, with a tag. They are not part of the confluence merge.")
string G11 = "Confluence & distance"
float confTol = input.float(0.15, "Confluence tolerance (ATR)", minval = 0.0, maxval = 2.0, step = 0.05, group = G11,
tooltip = "Levels closer together than this fraction of ATR(14) merge into one tag 'PDH + PWH' and that line gets a soft glow. 0 = never merge.")
float hideAtr = input.float(25.0, "Hide levels farther than (ATR)", minval = 1.0, maxval = 1000.0, step = 1.0, group = G11,
tooltip = "A monthly level 300 ATR away would squash a 1-minute chart into a flat line. Levels beyond this distance from the close are not drawn; the dashboard still lists them under 'Hidden far'.")
bool hideSwept = input.bool(false, "Hide swept levels", group = G11,
tooltip = "Off: a swept level stays, dimmed, with 'swept' on its tag. On: it disappears once price has traded through it.")
string histMode = input.string("Highs / lows", "Past periods' levels", options = ["Off", "Highs / lows", "All levels"], group = G11,
tooltip = "When a period ends its level line stays behind, faint and untagged, from where it started to where the period ended. Capped by 'Max lines kept'. A past line is skipped when its period's range (the level included) spans more than twice the hide distance, so scrolling back on a 1-minute chart never squashes the scale.")
string G12 = "Range bands"
bool showBand = input.bool(true, "Prior-day range band", group = G12,
tooltip = "PDH..PDL as a very faint band across today, stronger near the edges (highs tint at the top, lows tint at the bottom). Its size and the close's position are on the dashboard's 'Prior day range' row and in the PD 50 % tooltip. Drawn only when both edges are inside the hide distance.")
bool showMid = input.bool(true, "Prior-day 50 %", group = G12, tooltip = "The midpoint of the prior day as a dotted line tagged 'PD 50 %'.")
int bandT = input.int(90, "Band edge transparency", minval = 60, maxval = 99, group = G12,
tooltip = "Transparency of the strongest strip at each edge before Brightness. The inner strip and the body are fainter. Paper & Ink floors fills at 92.")
string G13 = "Display"
int rightExt = input.int(6, "Right extension (bars)", minval = 1, maxval = 60, group = G13,
tooltip = "Every live level reaches this many bars past the last candle, where its tag sits.")
string lblSize = input.string("Small", "Label size", options = ["Small", "Normal", "Large"], group = G13,
tooltip = "Size of the level tags. Small is the floor: every tag carries numbers and must stay readable. The secondary tags (day high / low rails, PD 50 %) are drawn one size smaller at Normal and Large, never below Small, and are told apart by their fainter colour.")
float laneGap = input.float(0.35, "Label lane gap (ATR)", minval = 0.1, maxval = 3.0, step = 0.05, group = G13,
tooltip = "Minimum vertical distance between right-edge tags. The gap also grows with the span of the drawn levels so tags never overlap on a compressed 1-minute scale.")
// ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════
// 8. KEY LEVELS — helpers
// ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════
string lblSz = f_size(lblSize)
string lblS2 = f_size(lblSize == "Large" ? "Normal" : "Small") // secondary tags: one size down, never below Small
// longest tag line (characters) before it wraps: 42 = "PDL 26,571.75 · −8.0 ATR · 428 pts · swept" on one line,
// about 200 px at Small, inside a ~35-bar right margin
int kTagMax = 42
// Level kinds: 0 = high (bear role), 1 = low (bull role), 2 = open (accent), 3 = close (neutral)
f_kindCol(int k) =>
k == 0 ? cBear : k == 1 ? cBull : k == 2 ? cAcc : cNeu
// Styles: highs carry kBearStyle (dashed in Paper & Ink, solid elsewhere), lows solid, opens dashed, close solid.
f_kindStyle(int k) =>
k == 0 ? kBearStyle : k == 2 ? line.style_dashed : line.style_solid
// f_atrAbs: |d| in ATR(14), one decimal.
f_atrAbs(float d) =>
na(atrK) or atrK <= 0 or na(d) ? "—" : str.tostring(math.abs(d) / atrK, "0.0")
// f_dist: "+0.8 ATR · 42.00 pts" / "−8.0 ATR · 428 pts" (signed by the side of the close; points in the symbol's
// price units, whole numbers from 100 up).
f_dist(float d) =>
na(d) ? "—" : (d >= 0 ? "+" : "−") + f_atrAbs(d) + " ATR · " + f_pts(d) + " pts"
// f_tagTxt: "PDL 26,571.75 · −8.0 ATR · 428 pts · swept". A tag longer than kTagMax characters (it would run off
// the right edge) wraps into name + price over the data, and a long confluence name wraps at its " + ".
f_tagTxt(string nm, float px, float d, bool sw) =>
string pxS = f_px(px)
string data = f_dist(d) + (sw ? " · swept" : "")
string one = nm + " " + pxS + " · " + data
string l1 = nm + " " + pxS
str.length(one) <= kTagMax ? one : str.length(l1) <= kTagMax ? l1 + "\n" + data :
f_wrap(nm, " + ", kTagMax) + "\n" + pxS + " · " + data
// f_pct: "72 %"
f_pct(float v) =>
na(v) ? "—" : str.tostring(math.round(v)) + " %"
// f_posTxt: where a close sits in a range, rng = "yesterday's" / "last week's" / "last month's":
// "at 72 % of last week's range (premium)" / "below last week's low · 0.63 of its range under"
f_posTxt(float pos, string rng) =>
na(pos) ? "—" : pos > 100 ? "above " + rng + " high · " + str.tostring((pos - 100.0) / 100.0, "0.00") + " of its range over" :
pos < 0 ? "below " + rng + " low · " + str.tostring(-pos / 100.0, "0.00") + " of its range under" :
"at " + f_pct(pos) + " of " + rng + " range (" + (pos > 50 ? "premium" : pos < 50 ? "discount" : "equilibrium") + ")"
// f_hit: does a bar that opens at minute t0 and spans `span` minutes contain minute m (wrapping midnight)?
f_hit(float t0, float span, float m) =>
(m >= t0 and m < t0 + span) or (m + 1440 >= t0 and m + 1440 < t0 + span)
// ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════
// 9. KEY LEVELS — data: three requests (D, W, M), [1] with lookahead_on = settled values, no repaint
// ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════
bool intra = timeframe.isintraday
int tfSec = timeframe.in_seconds()
// never request a timeframe LOWER than the chart: on a weekly chart the "D" call reads the chart's own timeframe
string tfD = tfSec > 86400 ? timeframe.period : "D"
string tfW = tfSec > timeframe.in_seconds("1W") ? timeframe.period : "W"
string tfM = tfSec > timeframe.in_seconds("1M") ? timeframe.period : "M"
[pdhS, pdlS, pdcS, dOpS, dAtrS] = request.security(syminfo.tickerid, tfD, [high[1], low[1], close[1], open, ta.atr(14)[1]], lookahead = barmerge.lookahead_on)
[pwhS, pwlS, wOpS] = request.security(syminfo.tickerid, tfW, [high[1], low[1], open], lookahead = barmerge.lookahead_on)
[pmhS, pmlS, mOpS] = request.security(syminfo.tickerid, tfM, [high[1], low[1], open], lookahead = barmerge.lookahead_on)
bool dShow = intra // daily levels: intraday charts only
bool wShow = tfSec <= timeframe.in_seconds("1W")
bool mShow = tfSec <= timeframe.in_seconds("1M")
// Period boundaries and the opens clock, from the chart's own bars
bool newDay = ta.change(time("D")) != 0
bool newWeek = ta.change(time("W")) != 0
bool newMonth = ta.change(time("M")) != 0
string tzUse = openTZ == "Exchange" ? syminfo.timezone : openTZ
float tfMin = tfSec / 60.0
float tod = hour(time, tzUse) * 60.0 + minute(time, tzUse)
bool opensTF = intra and tfSec <= 3600 // the intraday opens: 1H and below only
bool hitMid = opensTF and f_hit(tod, tfMin, 0.0)
bool hit830 = opensTF and f_hit(tod, tfMin, 510.0)
bool hit930 = opensTF and f_hit(tod, tfMin, 570.0)
var int dayStart = 0
if newDay
dayStart := bar_index
// Developing day high / low (var + realtime rollback = the live developing value, never a future one)
var float dHi = na
var float dLo = na
var int dHiBar = 0
var int dLoBar = 0
if newDay or na(dHi)
dHi := high
dLo := low
dHiBar := bar_index
dLoBar := bar_index
else
if high > dHi
dHi := high
dHiBar := bar_index
if low < dLo
dLo := low
dLoBar := bar_index
// ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════
// 10. KEY LEVELS — the level table (13 slots) and its roll
// ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════
// id 0 1 2 3 4 5 6 7 8 9 10 11 12
// PDH PDL PDC PWH PWL PMH PML DAILY OPEN WEEKLY OPEN MONTHLY OPEN MIDNIGHT OPEN 08:30 OPEN 09:30 OPEN
var array<string> lvName = array.from("PDH", "PDL", "PDC", "PWH", "PWL", "PMH", "PML", "DAILY OPEN", "WEEKLY OPEN", "MONTHLY OPEN", "MIDNIGHT OPEN", "08:30 OPEN", "09:30 OPEN")
var array<int> lvKind = array.from(0, 1, 3, 0, 1, 0, 1, 2, 2, 2, 2, 2, 2)
var array<int> lvWidth = array.from(2, 2, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1)
var array<float> lvPx = array.new<float>(13, na) // live price of each level
var array<int> lvStart = array.new<int>(13, 0) // bar the level went live (period start)
var array<bool> lvSwept = array.new<bool>(13, false)
var array<int> lvSwBar = array.new<int>(13, -1)
array<bool> lvOn = array.from(onPDH and dShow, onPDL and dShow, onPDC and dShow, onPWH and wShow, onPWL and wShow,
onPMH and mShow, onPML and mShow, onDO and dShow, onWO and wShow, onMO and mShow, onMid and opensTF, on830 and opensTF, on930 and opensTF)
// How ICT / SMC traders read each level (tag tooltips). Descriptions of a reading, never an instruction.
var array<string> lvRead = array.from(
"Prior day high: buy-side liquidity. ICT / SMC traders expect buy stops resting above it and watch whether price runs it and holds above, or runs it and comes back inside the range (a raid).",
"Prior day low: sell-side liquidity. ICT / SMC traders expect sell stops resting below it and watch whether price runs it and holds below, or runs it and comes back inside the range (a raid).",
"Prior day close: yesterday's settlement reference. Traders compare today's open with it (gap up / gap down) and note whether price comes back to it.",
"Prior week high: weekly buy-side liquidity, a higher-timeframe pool ICT traders call a draw on liquidity.",
"Prior week low: weekly sell-side liquidity, a higher-timeframe pool ICT traders call a draw on liquidity.",
"Prior month high: monthly buy-side liquidity, the largest pool above on this map.",
"Prior month low: monthly sell-side liquidity, the largest pool below on this map.",
"Daily open: the day's dividing line. Above it the day trades at a premium to where it opened, below it at a discount.",
"Weekly open: the week's dividing line. Above it the week trades at a premium to its open, below it at a discount.",
"Monthly open: the month's dividing line. Above it the month trades at a premium to its open, below it at a discount.",
"Midnight open: ICT's 'true day' open (00:00 New York). Many ICT traders measure intraday premium / discount from it instead of the exchange open.",
"08:30 open: the open at the 08:30 New York data releases, the start of the New York morning volatility in ICT's timing.",
"09:30 open: the US cash-equity open; the New York opening range forms around it.")
var array<line> histLines = array.new<line>() // past periods' levels (retired oldest-first against maxLines)
int kHistT = isMono ? 72 : f_t(68) // history lines: faint, but never floored away in Paper & Ink
// f_hist: the ended level leaves a faint untagged line over the bars it was live. Skipped when the period's range
// with the level included spans more than twice the hide distance (it would squash a 1-minute scale when scrolling
// back, the same reason live levels beyond the hide distance are not drawn).
f_hist(int i, float old, float rHi, float rLo) =>
int k = array.get(lvKind, i)
if not na(old) and histMode != "Off" and array.get(lvOn, i) and (histMode == "All levels" or k <= 1)
float hiS = na(rHi) ? old : math.max(rHi, old)
float loS = na(rLo) ? old : math.min(rLo, old)
bool fit = na(atrK) or atrK <= 0 or hiS - loS <= 2.0 * hideAtr * atrK
int x1 = f_xo(array.get(lvStart, i))
int x2 = bar_index - 1
if fit and x2 > x1
array.push(histLines, line.new(x1, old, x2, old, color = color.new(f_kindCol(k), kHistT), width = 1, style = f_kindStyle(k)))
true
// f_roll: on a period boundary the old level leaves a faint history line and the slot takes the new value.
// Outside a boundary a high / low / close follows the request silently (timing differences); opens never do.
// rHi / rLo = the range of the period that just ended (the new prior-period high / low).
f_roll(int i, float newPx, bool trig, float rHi, float rLo) =>
float old = array.get(lvPx, i)
int k = array.get(lvKind, i)
if trig and not na(newPx)
f_hist(i, old, rHi, rLo)
array.set(lvPx, i, newPx)
array.set(lvStart, i, bar_index)
array.set(lvSwept, i, false)
array.set(lvSwBar, i, -1)
else if not na(newPx)
if na(old) or (k != 2 and newPx != old)
array.set(lvPx, i, newPx)
true
array<float> nPx = array.from(pdhS, pdlS, pdcS, pwhS, pwlS, pmhS, pmlS,
newDay ? open : dOpS, newWeek ? open : wOpS, newMonth ? open : mOpS,
hitMid ? open : na, hit830 ? open : na, hit930 ? open : na)
array<bool> nTr = array.from(newDay, newDay, newDay, newWeek, newWeek, newMonth, newMonth,
newDay, newWeek, newMonth, hitMid, hit830, hit930)
// period of each slot: 0 = day, 1 = week, 2 = month (the intraday opens use the day that just ended)
var array<int> lvPer = array.from(0, 0, 0, 1, 1, 2, 2, 0, 1, 2, 0, 0, 0)
for i = 0 to 12
int per = array.get(lvPer, i)
f_roll(i, array.get(nPx, i), array.get(nTr, i), per == 0 ? pdhS : per == 1 ? pwhS : pmhS, per == 0 ? pdlS : per == 1 ? pwlS : pmlS)
// The midnight / 08:30 / 09:30 opens belong to one trading day: a new exchange day retires them until they print
// again (otherwise yesterday's 08:30 open would be tagged "08:30 OPEN" at 03:00 today).
if newDay
for i = 10 to 12
if not array.get(nTr, i) and not na(array.get(lvPx, i))
f_hist(i, array.get(lvPx, i), pdhS, pdlS)
array.set(lvPx, i, na)
array.set(lvSwept, i, false)
f_capLines(histLines, maxLines)
// Sweep: a confirmed bar trades through a high / low (the wick counts). Opens and the close are never "swept".
bool sweptNow = false
for i = 0 to 12
int k = array.get(lvKind, i)
float p = array.get(lvPx, i)
if barstate.isconfirmed and k <= 1 and not na(p) and not array.get(lvSwept, i)
if (k == 0 and high > p) or (k == 1 and low < p)
array.set(lvSwept, i, true)
array.set(lvSwBar, i, bar_index)
if array.get(lvOn, i)
sweptNow := true
float pdh = array.get(lvPx, 0)
float pdl = array.get(lvPx, 1)
float pwh = array.get(lvPx, 3)
float pwl = array.get(lvPx, 4)
float pmh = array.get(lvPx, 5)
float pml = array.get(lvPx, 6)
float pdR = not na(pdh) and not na(pdl) and pdh > pdl ? pdh - pdl : na
// above the weekly chart the "W" request reads the chart's own timeframe, so the prior week is not a week there
float pwR = wShow and not na(pwh) and not na(pwl) and pwh > pwl ? pwh - pwl : na
float pmR = not na(pmh) and not na(pml) and pmh > pml ? pmh - pml : na
float pdPos = na(pdR) ? na : (close - pdl) / pdR * 100.0
float pwPos = na(pwR) ? na : (close - pwl) / pwR * 100.0
float pmPos = na(pmR) ? na : (close - pml) / pmR * 100.0
// f_pdz: "premium" above the 50 %, "discount" below, "equilibrium" on it (ICT's names for the halves of a range)
f_pdz(float pos) =>
na(pos) ? "" : pos > 100 ? "above the high" : pos < 0 ? "below the low" : pos > 50 ? "premium" : pos < 50 ? "discount" : "equilibrium"
// ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════
// 11. KEY LEVELS — last-bar redraw: confluence, lines, glow, bands, tags, dashboard
// ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════
var array<line> liveLines = array.new<line>()
var array<label> liveLabels = array.new<label>()
var array<box> liveBoxes = array.new<box>()
// score 1 = at the low (bull role, discount), 0 = at the high (bear role, premium): same roles as the level lines
float rngPos = intra ? pdPos : wShow ? pwPos : pmPos
barcolor(f_candlePaint(paintMode, na(rngPos) ? na : 1.0 - rngPos / 100.0))
if barstate.islast
// the live set is rebuilt from scratch every tick
f_capLines(liveLines, 0)
f_capLabels(liveLabels, 0)
f_capBoxes(liveBoxes, 0)
f_laneReset()
int xR = f_xr(bar_index + rightExt)
float lim = na(atrK) or atrK <= 0 ? na : hideAtr * atrK
float tol = nz(atrK) * confTol
int dimLn = isMono ? 60 : f_t(55)
int dimTag = isMono ? 45 : f_t(45)
// ── candidates, sorted by price, merged into clusters within `tol` of the cluster's first level
array<float> cpx = array.new<float>()
array<int> cid = array.new<int>()
for i = 0 to 12
float p = array.get(lvPx, i)
if array.get(lvOn, i) and not na(p) and not (hideSwept and array.get(lvSwept, i))
array.push(cpx, p)
array.push(cid, i)
array<int> clOf = array.new<int>(13, -1)
int nCl = 0
float anchor = na
if array.size(cpx) > 0
array<int> ord = array.sort_indices(cpx, order.ascending)
for k = 0 to array.size(ord) - 1
int j = array.get(ord, k)
float p = array.get(cpx, j)
if na(anchor) or p - anchor > tol
anchor := p
nCl += 1
array.set(clOf, array.get(cid, j), nCl - 1)
array<float> clP = array.new<float>()
array<string> clNm = array.new<string>() // "PDH + PWH"
array<string> clTg = array.new<string>() // tag text
array<string> clTip = array.new<string>() // tag tooltip: every member
array<color> clCol = array.new<color>()
array<int> clN = array.new<int>()
array<bool> clAll = array.new<bool>() // every member swept
array<bool> clVis = array.new<bool>()
array<int> clXg = array.new<int>()
array<int> clW = array.new<int>()
array<string> clSty = array.new<string>()
if nCl > 0
for c = 0 to nCl - 1
array<string> nm = array.new<string>()
array<string> nmS = array.new<string>()
string tip = ""
float pp = na
color cc = cNeu
int ww = 1
int xg = 0
int nn = 0
int nSw = 0
string ss = line.style_solid
for i = 0 to 12
if array.get(clOf, i) == c
float p = array.get(lvPx, i)
int k = array.get(lvKind, i)
bool sw = array.get(lvSwept, i)
string n = array.get(lvName, i)
int sb = array.get(lvSwBar, i)
if nn == 0
pp := p
cc := f_kindCol(k)
ww := array.get(lvWidth, i)
ss := f_kindStyle(k)
nn += 1
nSw += sw ? 1 : 0
xg := math.max(xg, array.get(lvStart, i))
array.push(nm, n)
array.push(nmS, sw ? n + " (swept)" : n)
tip += n + " " + f_px(p) + " · " + f_dist(p - close) + (sw and sb >= 0 ? " · swept " + str.tostring(bar_index - sb) + " bars ago" : "") +
"\n" + array.get(lvRead, i) + "\n\n"
bool allSw = nSw == nn
string names = array.join(nm, " + ")
string tagNm = nSw > 0 and not allSw ? array.join(nmS, " + ") : names
array.push(clP, pp)
array.push(clNm, names)
// bars-ago lives in the tooltip only, so the tag stays inside the right margin
array.push(clTg, f_tagTxt(tagNm, pp, pp - close, allSw))
array.push(clTip, tip)
array.push(clCol, cc)
array.push(clN, nn)
array.push(clAll, allSw)
array.push(clVis, na(lim) or math.abs(pp - close) <= lim)
array.push(clXg, xg)
array.push(clW, ww)
array.push(clSty, ss)
// ── right-edge tags are collected first, then laid out nearest-to-price first through the lane register
array<float> tY = array.new<float>()
array<string> tTxt = array.new<string>()
array<string> tTip = array.new<string>()
array<color> tCol = array.new<color>()
array<string> tSz = array.new<string>() // main tags lblSz, secondary tags lblS2
// ── level lines (each from its own period start), glow on confluences
for i = 0 to 12
int c = array.get(clOf, i)
if c >= 0
if array.get(clVis, c)
float p = array.get(lvPx, i)
int k = array.get(lvKind, i)
bool sw = array.get(lvSwept, i)
color lc = f_kindCol(k)
array.push(liveLines, line.new(f_xo(array.get(lvStart, i)), p, xR, p, color = color.new(lc, sw ? dimLn : f_t(0)),
width = array.get(lvWidth, i), style = f_kindStyle(k)))
if nCl > 0
for c = 0 to nCl - 1
if array.get(clVis, c)
float pp = array.get(clP, c)
color cc = array.get(clCol, c)
bool all = array.get(clAll, c)
if array.get(clN, c) >= 2 and not all
array<line> g = f_glowLine(array.get(clXg, c), pp, xR, pp, cc, 2, array.get(clW, c))
line.set_style(array.last(g), array.get(clSty, c))
array.concat(liveLines, g)
array.push(tY, pp)
array.push(tTxt, array.get(clTg, c))
array.push(tTip, array.get(clTip, c))
array.push(tCol, all ? color.new(cc, dimTag) : cc)
array.push(tSz, lblSz)
// ── developing day high / low rails (intraday)
if showDev and intra and not na(dHi) and not na(dLo)
if na(lim) or math.abs(dHi - close) <= lim
array.push(liveLines, line.new(f_xo(dHiBar), dHi, xR, dHi, color = color.new(cBear, f_t(30)), width = 1, style = line.style_dotted))
array.push(tY, dHi)
array.push(tTxt, f_tagTxt("DAY HIGH", dHi, dHi - close, false))
array.push(tTip, "Today's developing high, made " + str.tostring(bar_index - dHiBar) + " bars ago. It moves with price, so it is never merged into a confluence. ICT / SMC traders read it as the buy-side liquidity today has built so far.")
array.push(tCol, color.new(cBear, f_t(25)))
array.push(tSz, lblS2)
if na(lim) or math.abs(dLo - close) <= lim
array.push(liveLines, line.new(f_xo(dLoBar), dLo, xR, dLo, color = color.new(cBull, f_t(30)), width = 1, style = line.style_dotted))
array.push(tY, dLo)
array.push(tTxt, f_tagTxt("DAY LOW", dLo, dLo - close, false))
array.push(tTip, "Today's developing low, made " + str.tostring(bar_index - dLoBar) + " bars ago. It moves with price, so it is never merged into a confluence. ICT / SMC traders read it as the sell-side liquidity today has built so far.")
array.push(tCol, color.new(cBull, f_t(25)))
array.push(tSz, lblS2)
// ── prior-day range band (stacked boxes, stronger at the edges) and its 50 %
if intra and not na(pdR)
bool bothIn = na(lim) or (math.abs(pdh - close) <= lim and math.abs(pdl - close) <= lim)
int xb = f_xo(dayStart)
if showBand and bothIn
array.push(liveBoxes, box.new(xb, pdh, xR, pdl, border_color = color.new(cNeu, 100), bgcolor = color.new(cNeu, f_t(math.min(99, bandT + 7)))))
array.push(liveBoxes, box.new(xb, pdh, xR, pdh - pdR * 0.30, border_color = color.new(cBear, 100), bgcolor = color.new(cBear, f_t(math.min(99, bandT + 5)))))
array.push(liveBoxes, box.new(xb, pdh, xR, pdh - pdR * 0.10, border_color = color.new(cBear, 100), bgcolor = color.new(cBear, f_t(bandT))))
array.push(liveBoxes, box.new(xb, pdl + pdR * 0.30, xR, pdl, border_color = color.new(cBull, 100), bgcolor = color.new(cBull, f_t(math.min(99, bandT + 5)))))
array.push(liveBoxes, box.new(xb, pdl + pdR * 0.10, xR, pdl, border_color = color.new(cBull, 100), bgcolor = color.new(cBull, f_t(bandT))))
// v1.2: no corner tag on the band. At the day start it ran into the right-edge tags on 15m / 1H and under the
// dashboard; the range size and the close position are on the "Prior day range" row and the PD 50 % tooltip.
float mid = (pdh + pdl) / 2.0
if showMid and (na(lim) or math.abs(mid - close) <= lim)
array.push(liveLines, line.new(xb, mid, xR, mid, color = color.new(cNeu, f_t(20)), width = 1, style = line.style_dotted))
array.push(tY, mid)
array.push(tTxt, f_tagTxt("PD 50 %", mid, mid - close, false))
array.push(tTip, "Midpoint of the prior day's range: equilibrium in ICT terms. Above it price trades in the prior day's premium, below it in its discount.\n\nPrior day " +
f_px(pdl) + " – " + f_px(pdh) + ": range " + f_pts(pdR) + " pts · " + f_atrAbs(pdR) + " ATR. The close is " + f_posTxt(pdPos, "yesterday's") + ".")
array.push(tCol, cNeu)
array.push(tSz, lblS2)
// ── lane layout: the gap is the input or 1/40 of the drawn span, whichever is larger (1-minute safety)
if array.size(tY) > 0
float yMax = math.max(array.max(tY), close)
float yMin = math.min(array.min(tY), close)
float gm = na(atrK) or atrK <= 0 ? laneGap : math.max(laneGap, (yMax - yMin) / atrK / 40.0)
array<float> key = array.new<float>()
for j = 0 to array.size(tY) - 1
array.push(key, math.abs(array.get(tY, j) - close))
array<int> ordT = array.sort_indices(key, order.ascending)
for k = 0 to array.size(ordT) - 1
int j = array.get(ordT, k)
float y = f_lane(array.get(tY, j), gm, array.size(str.split(array.get(tTxt, j), "\n")))
label lb = f_tag(xR, y, array.get(tTxt, j), array.get(tCol, j), label.style_label_left, array.get(tSz, j))
label.set_tooltip(lb, array.get(tTip, j))
array.push(liveLabels, lb)
// ── dashboard
if showDash
// nearest DRAWN cluster above / below the close: every number on these rows is also on a chart tag. Levels
// beyond the hide distance are only listed under "Hidden far" (they are not on the chart).
int iUp = -1
int iDn = -1
float dUp = na
float dDn = na
int nConf = 0
string confList = ""
int nFar = 0
string farList = ""
string noneTxt = "none within " + str.tostring(hideAtr, "#") + " ATR"
if nCl > 0
for c = 0 to nCl - 1
float d = array.get(clP, c) - close
if array.get(clVis, c)
if d > 0
if na(dUp) or d < dUp
dUp := d
iUp := c
else
if na(dDn) or -d < dDn
dDn := -d
iDn := c
if array.get(clN, c) >= 2
nConf += 1
confList += array.get(clNm, c) + " " + f_px(array.get(clP, c)) + " · " + f_dist(d) + "\n"
else
nFar += 1
farList += array.get(clNm, c) + " " + f_px(array.get(clP, c)) + " · " + f_dist(d) + "\n"
// the nearest rows print the cluster's own tag text: the same numbers, wrapped the same way
string upTxt = iUp < 0 ? noneTxt : array.get(clTg, iUp)
string dnTxt = iDn < 0 ? noneTxt : array.get(clTg, iDn)
color upCol = iUp < 0 ? cNeu : array.get(clCol, iUp)
color dnCol = iDn < 0 ? cNeu : array.get(clCol, iDn)
string upTip = (iUp < 0 ? "" : array.get(clTip, iUp)) + "The closest drawn level or confluence ABOVE the close: name, price, distance in ATR(14) and in points (the same numbers as its tag). In ICT / SMC terms the nearest unswept high overhead is the nearest buy-side liquidity, the first draw on that side; an open here is a premium / discount reference rather than liquidity."
string dnTip = (iDn < 0 ? "" : array.get(clTip, iDn)) + "The closest drawn level or confluence AT OR BELOW the close: name, price, distance in ATR(14) and in points (the same numbers as its tag). In ICT / SMC terms the nearest unswept low underneath is the nearest sell-side liquidity, the first draw on that side; an open here is a premium / discount reference rather than liquidity."
// swept today (intraday) / swept in the live period (daily and above)
int nSwT = 0
string swList = ""
for i = 0 to 12
if array.get(lvOn, i) and array.get(lvSwept, i) and (not intra or array.get(lvSwBar, i) >= dayStart)
nSwT += 1
swList += array.get(lvName, i) + " " + f_px(array.get(lvPx, i)) + " · swept " + str.tostring(bar_index - array.get(lvSwBar, i)) + " bars ago\n"
// prior day: range, close position, today vs prior day
string pdTxt = na(pdR) ? "—" : f_pts(pdR) + " pts · " + f_atrAbs(pdR) + " ATR · " +
(pdPos > 100 ? "close over the high" : pdPos < 0 ? "close under the low" : "close " + f_pct(pdPos) + " " + f_pdz(pdPos))
string pdTip = (na(pdR) ? "Prior day not available yet." : "Prior day " + f_px(pdl) + " – " + f_px(pdh) + ". Range = " +
(na(dAtrS) or dAtrS <= 0 ? "—" : str.tostring(pdR / dAtrS, "0.0")) + "× the 14-day daily ATR. The close is " + f_posTxt(pdPos, "yesterday's") +
". Close position: 0 % = at PDL, 100 % = at PDH.") +
"\n\nICT / SMC traders split the prior day at its 50 % (equilibrium, the dotted 'PD 50 %' line): above it price is in yesterday's premium, below it in yesterday's discount. On the chart: the band across today and the PD 50 % tag."
bool tookH = not na(pdh) and dHi > pdh
bool tookL = not na(pdl) and dLo < pdl
string tvTxt = na(pdR) ? "—" : tookH and tookL ? "outside day" : tookH ? "took PDH" : tookL ? "took PDL" : "inside so far"
color tvCol = tookH and tookL ? cAcc : tookH ? cBear : tookL ? cBull : cNeu
// the higher frame: the prior week (the prior month on a monthly chart)
bool useW = wShow
float hfR = useW ? pwR : pmR
float hfPos = useW ? pwPos : pmPos
string hfNm = useW ? "week" : "month"
string hfRng = useW ? "last week's" : "last month's"
string wkTxt = na(hfR) ? "—" : f_posTxt(hfPos, hfRng)
string wkTip = (na(hfR) ? "Prior " + hfNm + " not available yet." : "Prior " + hfNm + " " + f_px(useW ? pwl : pml) + " – " + f_px(useW ? pwh : pmh) +
": range " + f_pts(hfR) + " pts · " + f_atrAbs(hfR) + " ATR. Inside the range the row gives the close's position (0 % = at the low, 100 % = at the high); outside it, how far beyond in units of that range (0.63 = 63 % of the range past the edge).") +
"\n\nThe higher-timeframe frame ICT traders put the daily levels in: above the " + hfNm + "'s 50 % is its premium, below is its discount. On the chart: the " + (useW ? "PWH / PWL" : "PMH / PML") + " lines and tags."
// the Read: numbers only, never a direction call
string rd = ""
int iN = na(dUp) and na(dDn) ? -1 : na(dDn) ? iUp : na(dUp) ? iDn : dUp <= dDn ? iUp : iDn
if iN >= 0
float dn = array.get(clP, iN) - close
rd := f_atrAbs(dn) + " ATR " + (dn > 0 ? "under " : "over ") + array.get(clNm, iN)
if intra
if not na(pdPos)
rd += (rd == "" ? "" : "; ") + "close " + f_posTxt(pdPos, "yesterday's")
bool swH = array.get(lvSwept, 0)
bool swL = array.get(lvSwept, 1)
if not na(pdR)
rd += "; " + (not swH and not swL ? "PDH and PDL untouched" : swH and swL ? "PDH and PDL both swept" : swH ? "PDH swept, PDL untouched" : "PDL swept, PDH untouched")
else if not na(hfPos)
rd += (rd == "" ? "" : "; ") + "close " + f_posTxt(hfPos, hfRng)
if rd == ""
rd := "waiting for the first completed period"
rd := f_wrap(rd, " ", 60) // keeps the table narrow: the Read wraps at ~60 characters
string rdTip = "One line written only from the numbers above: the nearest drawn level and its distance, where the close sits in yesterday's range (premium / discount), and which side of yesterday's liquidity has been swept. It never says which way price will go."
f_dBegin()
f_dHead("KEY LEVELS")
if dashCompact
f_dRow(iN < 0 ? "Nearest" : iN == iUp ? "Nearest above" : "Nearest below", iN < 0 ? noneTxt : iN == iUp ? upTxt : dnTxt,
iN < 0 ? cNeu : array.get(clCol, iN), iN < 0 ? "No level is drawn within the hide distance." : iN == iUp ? upTip : dnTip)
else
if not intra
f_dRow("Chart", "daily+ · weekly / monthly only", cNeu, "Prior-day levels, the intraday opens, the day rails and the prior-day band need an intraday chart. Weekly and monthly levels are drawn here. ICT / SMC traders use these higher-timeframe highs and lows as the liquidity the lower timeframes are read against.")
f_dRow("Nearest above", upTxt, upCol, upTip)
f_dRow("Nearest below", dnTxt, dnCol, dnTip)
if intra
f_dRow("Prior day range", pdTxt, cTxt, pdTip)
f_dRow("Today vs prior day", tvTxt, tvCol, "From today's developing high / low, the live bar included: took PDH = traded above it, took PDL = traded below it, both = outside day, neither = inside day so far. The 'swept' tag on the chart waits for the bar to close.\n\nICT / SMC traders call a run above PDH a buy-side liquidity grab and a run below PDL a sell-side grab, and then watch whether price holds beyond the level or returns inside the range. This row only reports which side has been traded through. On the chart: the DAY HIGH / DAY LOW rails and the PDH / PDL tags.")
f_dRow(useW ? "Week" : "Month", wkTxt, cTxt, wkTip)
f_dRow(intra ? "Swept today" : "Swept (live)", str.tostring(nSwT) + (nSwT > 0 and hideSwept ? " (hidden)" : ""), nSwT > 0 ? cAcc : cNeu,
(nSwT > 0 ? swList + "\n" : "No level has been traded through yet.\n\n") + "A sweep = a closed bar traded through the level (the wick counts). ICT / SMC traders treat a swept high or low as liquidity already taken; the unswept levels are the liquidity still resting. On the chart: dimmed lines, ' · swept' at the end of the tag (bars ago in the tag tooltip)" + (hideSwept ? " (hidden now: 'Hide swept levels' is on)." : "."))
f_dRow("Confluences", str.tostring(nConf), nConf > 0 ? cGlow : cNeu,
(nConf > 0 ? confList + "\n" : "No two drawn levels closer than " + str.tostring(confTol, "0.00") + " ATR.\n\n") + "Two or more levels within " + str.tostring(confTol, "0.00") + " ATR of each other share one tag 'PDH + PWH' and a glowing line. SMC traders read stacked levels as a larger pool of resting orders than either level alone.")
f_dRow("Hidden far", nFar > 0 ? str.tostring(nFar) + " beyond " + str.tostring(hideAtr, "#") + " ATR" : "none", cNeu,
(nFar > 0 ? farList + "\n" : "Every enabled level is within the hide distance and drawn.\n\n") + "Levels farther than " + str.tostring(hideAtr, "#") + " ATR from the close are not drawn, so a monthly level does not squash a 1-minute chart into a flat line. They still count as higher-timeframe liquidity; raise 'Hide levels farther than (ATR)' to draw them.")
f_dRead(rd, rdTip)
alertcondition(sweptNow, "Key level swept", "Key Levels Map [JOAT]: a prior high / low was traded through on {{ticker}} {{interval}}")