本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
// HOV Discount Zones
// Buy the pullback in a bullish structure, sell the bounce in a bearish one.
// 1. Real swing high: a high with 5 candles after it and no higher high. When price CLOSES above it (break of
// structure), the real swing low is the lowest low between that high and the break. The next real high
// completes the move. Highs made before the old high breaks are internal and ignored.
// 2. Fib from swing high (0) to swing low (1):
// Institutional Buy Zone = 0.618 - 0.786
// Smart Money Zone = 0.786 - 0.826
// A zone stays until price closes below the swing low (1). Sell zones are the mirror image.
// 3. BX (B-Xtrender) on the Monthly and Weekly in the corner table. BUY = price in a buy zone and the chart's BX
// turns up. Stop under the swing low (1), target the swing high (0).
// 4. Weekly and Daily zones also show on lower charts (8H, 4H, 1H...). TRIGGER = a weekly buy zone was touched and
// held (no trade under 0.826), then the chart closes above its last swing high for the first time, above the
// daily 50-day average (the tested plan). It only fires when the structure breaks on its own and the swing high
// is still 5%+ away; nothing is forced.
// 5. No clutter (default): only the buy zone closest to price (the one price is in, else the nearest below) and the
// nearest sell zone above are drawn. Every zone is still tracked for the signals and alerts.
// Research tool, not investment advice.
indicator("HOV Discount Zones", overlay=true, max_boxes_count=200, max_labels_count=200, max_lines_count=100, max_bars_back=1000)
// ---------- Inputs ----------
gS = "Swings"
confirmN = input.int(5, "Candles to confirm a swing", minval=1, group=gS)
maxZones = input.int(3, "Active zones kept per side (3 tested best; 1 = only the current fib)", minval=1, maxval=10, group=gS)
showSell = input.bool(true, "Show sell zones", group=gS)
showSwing = input.bool(true, "Label swing high / low of the latest move", group=gS)
closestOnly = input.bool(true, "Only the zone closest to price (no clutter)", group=gS, tooltip="Draws one buy zone (the one price is in, else the nearest below) and one sell zone (the nearest above). All zones are still tracked for the signals and alerts.")
gF = "Fib levels"
fInst = input.float(0.618, "Institutional zone top", step=0.001, group=gF)
fSplit = input.float(0.786, "Institutional / Smart Money line", step=0.001, group=gF)
fSmz = input.float(0.826, "Smart Money zone bottom", step=0.001, group=gF)
gH = "Higher-timeframe zones"
showW = input.bool(true, "Show Weekly zones on lower timeframes", group=gH)
showD = input.bool(false, "Show Daily zones on intraday charts (8H, 4H, 1H...)", group=gH)
gT = "TRIGGER (weekly zone + structure break)"
showTrig = input.bool(true, "Show TRIGGER", group=gT)
trigBars = input.int(40, "Weekly zone touched within this many bars", minval=1, group=gT)
trigPiv = input.int(5, "Swing high: candles each side", minval=1, group=gT)
gB = "BX and signals"
showDash = input.bool(true, "Show BX table", group=gB)
recentN = input.int(3, "BUY: BX turns up within this many bars of touching a zone", minval=0, group=gB)
showPlan = input.bool(true, "Draw stop / target for the latest BUY", group=gB)
// ---------- Theme (matches the HOV charts) ----------
// ---------- Theme: quiet fills, hairline edges, small dark text ----------
gC = "Style"
cBuy = input.color(#4A6FA5, "Buy zone", group=gC)
cBuySm = input.color(#6E62A8, "Buy smart money", group=gC)
cSell = input.color(#A85D5D, "Sell zone", group=gC)
cSellSm = input.color(#8E5670, "Sell smart money", group=gC)
fillT = input.int(86, "Fill transparency (higher = lighter)", minval=50, maxval=98, group=gC)
cText = input.color(#2C2C2E, "Label text", group=gC)
txtSize = input.string("Small", "Label size", options=["Tiny", "Small", "Normal"], group=gC)
colInst = color.new(cBuy, fillT)
colSmz = color.new(cBuySm, fillT - 6)
colInstS = color.new(cSell, fillT)
colSmzS = color.new(cSellSm, fillT - 6)
colBuyTxt = color.new(cText, 10)
colSellTx = color.new(cText, 10)
colBull = #3E7E5E
colBear = #9E4F4A
colGold = #8C6D2F
colMuted = color.new(cText, 40)
noBorder = color.new(color.black, 100)
lblSize = txtSize == "Tiny" ? size.tiny : txtSize == "Normal" ? size.normal : size.small
// ---------- Zone storage: lo / hi of the move, three fib prices, left edge time ----------
var float[] bLo = array.new_float()
var float[] bHi = array.new_float()
var float[] bTop = array.new_float()
var float[] bMid = array.new_float()
var float[] bBot = array.new_float()
var int[] bL = array.new_int()
var float[] sLo = array.new_float()
var float[] sHi = array.new_float()
var float[] sTop = array.new_float()
var float[] sMid = array.new_float()
var float[] sBot = array.new_float()
var int[] sL = array.new_int()
dropFirst(float[] a1, float[] a2, float[] a3, float[] a4, float[] a5, int[] a6, int k) =>
array.remove(a1, k)
array.remove(a2, k)
array.remove(a3, k)
array.remove(a4, k)
array.remove(a5, k)
array.remove(a6, k)
k
// ---------- Bullish structure ----------
var int sh = na // bar of the last real swing high
var float shHi = na
var float upLow = na // swing low of the move in progress (set at the break)
var int upLowT = na
var int cand = 0
var float candHi = high
var int lastLowBar = na
var int lastHighBar = na
seekUp = na(sh) or not na(upLow)
if seekUp
if high > candHi
cand := bar_index
candHi := high
else if bar_index - cand >= confirmN
if not na(upLow) and candHi > upLow
r = candHi - upLow
array.push(bLo, upLow)
array.push(bHi, candHi)
array.push(bTop, candHi - fInst * r)
array.push(bMid, candHi - fSplit * r)
array.push(bBot, candHi - fSmz * r)
array.push(bL, upLowT)
if array.size(bLo) > maxZones
dropFirst(bLo, bHi, bTop, bMid, bBot, bL, 0)
lastHighBar := cand
sh := cand
shHi := candHi
upLow := na
else if close > shHi
span = math.min(bar_index - sh, 990)
lo = low
loT = time
hiMax = high
hiIdx = bar_index
for k = 0 to span
if low[k] < lo
lo := low[k]
loT := time[k]
lastLowBar := bar_index - k
if k < span and high[k] > hiMax
hiMax := high[k]
hiIdx := bar_index - k
upLow := lo
upLowT := loT
cand := hiIdx
candHi := hiMax
// ---------- Bearish structure (mirror) ----------
var int sl = na
var float slLo = na
var float dnHigh = na
var int dnHighT = na
var int candL = 0
var float candLo = low
seekDn = na(sl) or not na(dnHigh)
if seekDn
if low < candLo
candL := bar_index
candLo := low
else if bar_index - candL >= confirmN
if not na(dnHigh) and dnHigh > candLo
r = dnHigh - candLo
array.push(sLo, candLo)
array.push(sHi, dnHigh)
array.push(sBot, candLo + fInst * r)
array.push(sMid, candLo + fSplit * r)
array.push(sTop, candLo + fSmz * r)
array.push(sL, dnHighT)
if array.size(sLo) > maxZones
dropFirst(sLo, sHi, sTop, sMid, sBot, sL, 0)
sl := candL
slLo := candLo
dnHigh := na
else if close < slLo
span = math.min(bar_index - sl, 990)
hi = high
hiT = time
loMin = low
loIdx = bar_index
for k = 0 to span
if high[k] > hi
hi := high[k]
hiT := time[k]
if k < span and low[k] < loMin
loMin := low[k]
loIdx := bar_index - k
dnHigh := hi
dnHighT := hiT
candL := loIdx
candLo := loMin
// ---------- Higher-timeframe zones: the same rules, latest active buy and sell zone as plain numbers ----------
// (request.security can't carry the arrays, so it keeps only the newest zone on each side.)
htfZone(int n) =>
var int hSh = na
var float hShHi = na
var float hUpLow = na
var float hUpLowT = na
var int hCand = 0
var float hCandHi = na
var float zLo = na
var float zHi = na
var float zT = na
var int hSl = na
var float hSlLo = na
var float hDnHigh = na
var float hDnHighT = na
var int hCandL = 0
var float hCandLo = na
var float yLo = na
var float yHi = na
var float yT = na
if na(hCandHi)
hCandHi := high
hCandLo := low
if na(hSh) or not na(hUpLow)
if high > hCandHi
hCand := bar_index
hCandHi := high
else if bar_index - hCand >= n
if not na(hUpLow) and hCandHi > hUpLow
zLo := hUpLow
zHi := hCandHi
zT := hUpLowT
hSh := hCand
hShHi := hCandHi
hUpLow := na
else if close > hShHi
span = math.min(bar_index - hSh, 400)
lo = low
loT = time
hiMax = high
hiIdx = bar_index
for k = 0 to span
if low[k] < lo
lo := low[k]
loT := time[k]
if k < span and high[k] > hiMax
hiMax := high[k]
hiIdx := bar_index - k
hUpLow := lo
hUpLowT := loT
hCand := hiIdx
hCandHi := hiMax
if na(hSl) or not na(hDnHigh)
if low < hCandLo
hCandL := bar_index
hCandLo := low
else if bar_index - hCandL >= n
if not na(hDnHigh) and hDnHigh > hCandLo
yLo := hCandLo
yHi := hDnHigh
yT := hDnHighT
hSl := hCandL
hSlLo := hCandLo
hDnHigh := na
else if close < hSlLo
span = math.min(bar_index - hSl, 400)
hi = high
hiT = time
loMin = low
loIdx = bar_index
for k = 0 to span
if high[k] > hi
hi := high[k]
hiT := time[k]
if k < span and low[k] < loMin
loMin := low[k]
loIdx := bar_index - k
hDnHigh := hi
hDnHighT := hiT
hCandL := loIdx
hCandLo := loMin
if not na(zLo) and close < zLo
zLo := na
zHi := na
if not na(yHi) and close > yHi
yLo := na
yHi := na
[zLo, zHi, zT, yLo, yHi, yT]
chartSec = timeframe.in_seconds()
useW = showW and chartSec < timeframe.in_seconds("W")
useD = showD and chartSec < timeframe.in_seconds("D")
[wLo, wHi, wT, wsLo, wsHi, wsT] = request.security(syminfo.tickerid, "W", htfZone(confirmN), lookahead=barmerge.lookahead_off)
[dLo, dHi, dT, dsLo, dsHi, dsT] = request.security(syminfo.tickerid, "D", htfZone(confirmN), lookahead=barmerge.lookahead_off)
// ---------- Retire zones: close past the move's origin ----------
if array.size(bLo) > 0
for k = array.size(bLo) - 1 to 0
if close < array.get(bLo, k)
dropFirst(bLo, bHi, bTop, bMid, bBot, bL, k)
if array.size(sLo) > 0
for k = array.size(sLo) - 1 to 0
if close > array.get(sHi, k)
dropFirst(sLo, sHi, sTop, sMid, sBot, sL, k)
// ---------- In a zone? ----------
inBuy = false
zStop = float(na)
zTarget = float(na)
if array.size(bLo) > 0
for k = 0 to array.size(bLo) - 1
if low <= array.get(bTop, k) and close >= array.get(bLo, k)
inBuy := true
zStop := array.get(bLo, k)
zTarget := array.get(bHi, k)
inSell = false
if array.size(sLo) > 0
for k = 0 to array.size(sLo) - 1
if high >= array.get(sBot, k) and close <= array.get(sHi, k)
inSell := true
// Weekly / daily zones count too on lower timeframes
wTop = wHi - fInst * (wHi - wLo)
dTop = dHi - fInst * (dHi - dLo)
inW = useW and not na(wLo) and low <= wTop and close >= wLo
inD = useD and not na(dLo) and low <= dTop and close >= dLo
if not inBuy and inW
zStop := wLo
zTarget := wHi
else if not inBuy and inD
zStop := dLo
zTarget := dHi
inBuy := inBuy or inW or inD
inSell := inSell or (useW and not na(wsHi) and high >= wsLo + fInst * (wsHi - wsLo) and close <= wsHi) or (useD and not na(dsHi) and high >= dsLo + fInst * (dsHi - dsLo) and close <= dsHi)
var int lastTouch = na
var float touchStop = na
var float touchTarget = na
if inBuy
lastTouch := bar_index
touchStop := zStop
touchTarget := zTarget
// ---------- TRIGGER: weekly buy zone touched, then the chart closes above its last swing high ----------
// Tested on daily bars (= 8H on a regular-hours chart), 2,819 stocks 2022-2026, 1,029 trades, with the zone-held and
// 50-day filters: 77% reached the swing high before a weekly close below the swing low (74% in 2022-24, 80% in
// 2025-26, 67-80% every year), vs ~50% for any day held as long. Avg win +15%, avg loss -26%: the stop is far, so the
// win rate is what carries it.
var int lastWTouch = na
var float wStop = na
var float wTarget = na
var bool firedForTouch = false
var float lowSinceTouch = na
var float wFloor = na // the 0.826 line: the zone must hold above it
if inW or (chartSec >= timeframe.in_seconds("W") and inBuy)
if na(lastWTouch) or bar_index - lastWTouch > trigBars
lastWTouch := bar_index // a new visit to the zone: one TRIGGER allowed again
firedForTouch := false
lowSinceTouch := low
wStop := inW ? wLo : zStop
wTarget := inW ? wHi : zTarget
wFloor := wTarget - fSmz * (wTarget - wStop)
if not na(lastWTouch)
lowSinceTouch := math.min(nz(lowSinceTouch, low), low)
// Filters that held in 2022-24 and again in 2025-26 (2,819 stocks: 77% together vs 69% without): the zone held, and the
// break closes above the daily 50-day average
dSma50 = request.security(syminfo.tickerid, "D", ta.sma(close, 50), lookahead=barmerge.lookahead_off)
zoneHeld = not na(lowSinceTouch) and lowSinceTouch >= wFloor
ph = ta.pivothigh(high, trigPiv, trigPiv)
var float swingHi = na
var bool armed = false
if not na(ph)
swingHi := ph
armed := true
breakUp = armed and close > swingHi
if breakUp
armed := false
trigger = showTrig and breakUp and not na(lastWTouch) and bar_index - lastWTouch <= trigBars and close > wStop and wTarget >= close * 1.05 and not firedForTouch and zoneHeld and close > dSma50
if trigger
firedForTouch := true
plotshape(trigger, "TRIGGER: weekly zone + structure break", shape.labelup, location.belowbar, color.new(#3E7E5E, 10), text="Trigger", textcolor=color.white, size=size.tiny)
// ---------- BX ----------
bxCalc() =>
v = ta.rsi(ta.ema(close, 5) - ta.ema(close, 20), 15) - 50
[v, v - v[1]]
[bx, bxCh] = bxCalc()
[mBx, mBxCh] = request.security(syminfo.tickerid, "M", bxCalc(), lookahead=barmerge.lookahead_off)
[wBx, wBxCh] = request.security(syminfo.tickerid, "W", bxCalc(), lookahead=barmerge.lookahead_off)
bxTurnUp = bx > bx[1] and bx[1] <= bx[2]
buySig = bxTurnUp and not na(lastTouch) and bar_index - lastTouch <= recentN and close > touchStop
plotshape(buySig, "BUY: zone + BX turn", shape.triangleup, location.belowbar, color.new(colGold, 20), size=size.tiny)
// ---------- Drawing ----------
var box[] drawn = array.new_box()
var line[] plan = array.new_line()
var label[] planL = array.new_label()
var float pStop = na
var float pTarget = na
var int pBar = na
if buySig
pStop := touchStop
pTarget := touchTarget
pBar := bar_index
zoneBox(int left, float top, float bottom, color bg, string txt, color tc) =>
box.new(left, top, time, bottom, xloc=xloc.bar_time, extend=extend.right, bgcolor=bg, border_color=color.new(bg, math.max(color.t(bg) - 30, 0)), border_width=1, text=txt, text_color=tc, text_size=lblSize, text_halign=text.align_right, text_valign=text.align_top)
// Draw each zone once: higher timeframes first, then this chart's; a zone that overlaps one already drawn is skipped
var float[] usedTop = array.new_float()
var float[] usedBot = array.new_float()
taken(float top, float bot) =>
hit = false
if array.size(usedTop) > 0
for k = 0 to array.size(usedTop) - 1
ot = array.get(usedTop, k)
ob = array.get(usedBot, k)
overlap = math.min(top, ot) - math.max(bot, ob)
if overlap > 0.5 * math.min(top - bot, ot - ob)
hit := true
hit
// how far price is from a zone (0 = inside it)
zDist(float hi, float lo) => close > hi ? close - hi : close < lo ? lo - close : 0.0
drawZone(int left, float iTop, float iBot, float sTop, float sBot, bool buy, string tf) =>
hi = math.max(iTop, iBot, sTop, sBot)
lo = math.min(iTop, iBot, sTop, sBot)
if not taken(hi, lo)
array.push(usedTop, hi)
array.push(usedBot, lo)
array.push(drawn, zoneBox(left, iTop, iBot, buy ? colInst : colInstS, tf + (buy ? "Buy zone" : "Sell zone"), buy ? colBuyTxt : colSellTx))
array.push(drawn, zoneBox(left, sTop, sBot, buy ? colSmz : colSmzS, "Smart money", buy ? colBuyTxt : colSellTx))
0
if barstate.islast
for bx0 in drawn
box.delete(bx0)
array.clear(drawn)
array.clear(usedTop)
array.clear(usedBot)
// Pick the buy and sell zone closest to price (codes: 100 = weekly, 101 = daily, k = this chart's zone k).
// Higher timeframes are checked first, so a weekly zone wins a tie.
int bestBuy = -99
float bestBuyD = na
int bestSell = -99
float bestSellD = na
for j = 0 to 1
showTf = j == 0 ? useW : useD
bLo0 = j == 0 ? wLo : dLo
bHi0 = j == 0 ? wHi : dHi
bT0 = j == 0 ? wT : dT
sLo0 = j == 0 ? wsLo : dsLo
sHi0 = j == 0 ? wsHi : dsHi
sT0 = j == 0 ? wsT : dsT
if showTf and not na(bLo0) and not na(bT0)
r = bHi0 - bLo0
d = zDist(bHi0 - fInst * r, bHi0 - fSmz * r)
if na(bestBuyD) or d < bestBuyD
bestBuyD := d
bestBuy := 100 + j
if showTf and showSell and not na(sHi0) and not na(sT0)
r = sHi0 - sLo0
d = zDist(sLo0 + fSmz * r, sLo0 + fInst * r)
if na(bestSellD) or d < bestSellD
bestSellD := d
bestSell := 100 + j
if array.size(bLo) > 0
for k = array.size(bLo) - 1 to 0
d = zDist(array.get(bTop, k), array.get(bBot, k))
if na(bestBuyD) or d < bestBuyD
bestBuyD := d
bestBuy := k
if showSell and array.size(sLo) > 0
for k = array.size(sLo) - 1 to 0
d = zDist(array.get(sTop, k), array.get(sBot, k))
if na(bestSellD) or d < bestSellD
bestSellD := d
bestSell := k
for j = 0 to 1
showTf = j == 0 ? useW : useD
nm = j == 0 ? "Weekly " : "Daily "
bLo0 = j == 0 ? wLo : dLo
bHi0 = j == 0 ? wHi : dHi
bT0 = j == 0 ? wT : dT
sLo0 = j == 0 ? wsLo : dsLo
sHi0 = j == 0 ? wsHi : dsHi
sT0 = j == 0 ? wsT : dsT
if showTf and not na(bLo0) and not na(bT0) and (not closestOnly or bestBuy == 100 + j)
r = bHi0 - bLo0
drawZone(int(bT0), bHi0 - fInst * r, bHi0 - fSplit * r, bHi0 - fSplit * r, bHi0 - fSmz * r, true, nm)
if showTf and showSell and not na(sHi0) and not na(sT0) and (not closestOnly or bestSell == 100 + j)
r = sHi0 - sLo0
drawZone(int(sT0), sLo0 + fSplit * r, sLo0 + fInst * r, sLo0 + fSmz * r, sLo0 + fSplit * r, false, nm)
if array.size(bLo) > 0
for k = array.size(bLo) - 1 to 0
if not closestOnly or bestBuy == k
drawZone(array.get(bL, k), array.get(bTop, k), array.get(bMid, k), array.get(bMid, k), array.get(bBot, k), true, "")
if showSell and array.size(sLo) > 0
for k = array.size(sLo) - 1 to 0
if not closestOnly or bestSell == k
drawZone(array.get(sL, k), array.get(sMid, k), array.get(sBot, k), array.get(sTop, k), array.get(sMid, k), false, "")
for ln in plan
line.delete(ln)
array.clear(plan)
for lb in planL
label.delete(lb)
array.clear(planL)
if showPlan and not na(pBar)
array.push(plan, line.new(pBar, pStop, bar_index + 8, pStop, color=color.new(colBear, 30), style=line.style_dotted, width=1))
array.push(plan, line.new(pBar, pTarget, bar_index + 8, pTarget, color=color.new(colBull, 30), style=line.style_dotted, width=1))
array.push(planL, label.new(bar_index + 8, pStop, "Stop " + str.tostring(pStop, format.mintick), style=label.style_label_left, color=noBorder, textcolor=colBear, size=lblSize))
array.push(planL, label.new(bar_index + 8, pTarget, "Target " + str.tostring(pTarget, format.mintick), style=label.style_label_left, color=noBorder, textcolor=colBull, size=lblSize))
// swing high / low of the zone on show (closest-only), else of the latest move
float swHi = na
float swLo = na
if closestOnly and bestBuy >= 100
swHi := bestBuy == 100 ? wHi : dHi
swLo := bestBuy == 100 ? wLo : dLo
else if closestOnly and bestBuy >= 0
swHi := array.get(bHi, bestBuy)
swLo := array.get(bLo, bestBuy)
else if array.size(bLo) > 0
swHi := array.get(bHi, array.size(bLo) - 1)
swLo := array.get(bLo, array.size(bLo) - 1)
if showSwing and not na(swHi)
array.push(planL, label.new(bar_index, swHi, "Swing high " + str.tostring(swHi, format.mintick), style=label.style_label_left, color=noBorder, textcolor=colMuted, size=size.tiny))
array.push(planL, label.new(bar_index, swLo, "Swing low " + str.tostring(swLo, format.mintick), style=label.style_label_left, color=noBorder, textcolor=colMuted, size=size.tiny))
// ---------- One box, top right: weekly structure, ATR extension, sector / industry ----------
// (BX is still calculated for the gold BUY arrows; it just isn't shown in the box)
bxTxt(float v, float ch) =>
na(v) ? "n/a" : str.tostring(v, "#.#") + (ch >= 0 ? " rising" : " falling")
bxCol(float v, float ch) =>
na(v) ? colMuted : v >= 0 ? (ch >= 0 ? colBull : color.new(colBull, 35)) : (ch >= 0 ? color.new(colBear, 35) : colBear)
// weeks in a row closing below (+) or above (-) the weekly 21 EMA
emaRun() =>
e = ta.ema(close, 21)
var int run = 0
run := close < e ? math.max(run, 0) + 1 : math.min(run, 0) - 1
run
[wE21, wS50, wAtr11, wRun] = request.security(syminfo.tickerid, "W", [ta.ema(close, 21), ta.sma(close, 50), ta.atr(11), emaRun()], lookahead=barmerge.lookahead_off)
cHead = color.new(#9AA3AD, 0)
cRedBox = color.new(#E06666, 0)
cGrnBox = color.new(#6AAE7B, 0)
cRedSft = color.new(#E6A9A9, 0)
cGrnSft = color.new(#A9D6B4, 0)
cYelSft = color.new(#E9E3A6, 0)
cNone = color.new(#FFFFFF, 100)
var table dash = table.new(position.top_right, 2, 9, bgcolor=color.new(#FFFFFF, 30), frame_width=0, border_width=1, border_color=color.new(#FFFFFF, 100))
maTxt(float ma) => na(ma) ? "n/a" : str.tostring(ma, format.mintick) + " " + str.tostring((close / ma - 1) * 100, "#.##") + "%"
dashRow(int r, string k, string v, color bg, color tc) =>
table.cell(dash, 0, r, k, text_color=cText, text_size=size.small, text_halign=text.align_center)
table.cell(dash, 1, r, v, bgcolor=bg, text_color=tc, text_size=size.small, text_halign=text.align_center)
dashHead(int r, string k, string v, color tc) =>
table.cell(dash, 0, r, k, bgcolor=cHead, text_color=color.new(cText, 20), text_size=size.small, text_halign=text.align_left)
table.cell(dash, 1, r, v, bgcolor=cHead, text_color=tc, text_size=size.small, text_halign=text.align_center)
if showDash and barstate.islast
below = close < wE21
dashHead(0, "Weekly Structure", syminfo.ticker, #E3B341)
dashRow(1, wRun > 0 ? "Weeks Below" : "Weeks Above", str.tostring(math.abs(wRun)), wRun > 0 ? cRedBox : cGrnBox, color.white)
dashRow(2, "21 EMA", maTxt(wE21), close < wE21 ? cRedSft : cGrnSft, cText)
dashRow(3, "50 SMA", maTxt(wS50), close < wS50 ? cRedSft : cGrnSft, cText)
dashHead(4, "ATR Ext", "", cText)
dashRow(5, "21 EMA", na(wAtr11) ? "n/a" : str.tostring(math.abs(close - wE21) / wAtr11, "#.##") + "x " + (below ? "below" : "above"), cYelSft, cText)
dashRow(6, "ATR(11)", na(wAtr11) ? "n/a" : str.tostring(wAtr11 / close * 100, "#.##") + "%", cNone, cText)
dashRow(7, "Sector", syminfo.sector, cNone, cText)
dashRow(8, "Industry", syminfo.industry, cNone, cText)
// ---------- Alerts ----------
alertcondition(inBuy and not inBuy[1], "Entered a buy zone", "{{ticker}} {{interval}}: price entered an Institutional / Smart Money buy zone")
alertcondition(buySig, "BUY: zone + BX turn up", "{{ticker}} {{interval}}: BX turned up inside a buy zone, close {{close}}")
alertcondition(inSell and not inSell[1], "Entered a sell zone", "{{ticker}} {{interval}}: price entered a sell zone")
alertcondition(trigger, "TRIGGER: weekly zone + structure break", "{{ticker}} {{interval}}: closed above its last swing high after touching a weekly buy zone, close {{close}}")