本页源码来自 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/
// © Nambou_Signals
//@version=6
indicator("Nambou Order Block Radar", "OB Radar", overlay = true, max_boxes_count = 500, max_lines_count = 500, max_labels_count = 500, max_bars_back = 1000)
gO = "Order blocks"
len = input.int(5, "Swing size: bars on each side of a swing", minval = 2, maxval = 50, group = gO, tooltip = "A block is found when a bar closes beyond the last swing high or low. Bigger numbers give bigger swings and fewer, stronger blocks.")
zoneIn = input.string("Full candle", "A block covers the", options = ["Full candle", "Body"], group = gO, tooltip = "Full candle: from the block candle's high to its low. Body: from its open to its close.")
maxN = input.int(4, "Max open blocks tracked per side", minval = 1, maxval = 30, group = gO, tooltip = "A new block replaces any older block on the same side that it overlaps.")
keepFull = input.bool(false, "Keep a block after it is fully mitigated", group = gO, tooltip = "Off removes a block once price reaches its far edge. On keeps it as a faint outline until a bar closes beyond it.")
gH = "Higher-timeframe blocks"
htfIn = input.string("Auto", "Also track blocks from", options = ["Auto", "Off", "1H", "4H", "Daily", "Weekly"], group = gH, tooltip = "Auto picks the next timeframe up: 1H on charts below one hour, 4H on 1H to 3H, Daily on 4H to 12H, Weekly on Daily. A block is added when its higher-timeframe bar has closed, so it never repaints.")
maxH = input.int(2, "Max higher-timeframe blocks tracked per side", minval = 1, maxval = 20, group = gH)
gD = "Display"
styleIn = input.string("Levels", "Draw each block as", options = ["Levels", "Zones"], group = gD, tooltip = "Levels: a solid line at the edge price meets first and a dotted line at the far edge. Zones: a filled box whose bright part shrinks as price trades into it.")
maxAtr = input.float(8.0, "Draw blocks within this many ATR of the price", minval = 0.0, maxval = 100.0, step = 0.5, group = gD, tooltip = "Blocks further away stay in the table but are not drawn, so they don't squash the chart. 0 draws them all.")
extBars = input.int(25, "Zones run this many bars past the last bar", minval = 1, maxval = 200, group = gD, tooltip = "Higher-timeframe zones run 24 bars further, so their text sits beyond the others.")
showAxis = input.bool(true, "Show the levels on the price scale", group = gD, tooltip = "The solid edge of the nearest blocks (up to 4 on each side) gets a coloured label on the price scale.")
showText = input.bool(true, "Write the block and how far it is mitigated inside each zone", group = gD)
showMid = input.bool(true, "Show the middle of each block", group = gD, tooltip = "A dashed line halfway through the block, often called the mean threshold.")
showMarks = input.bool(true, "Mark the first time each block holds", group = gD, tooltip = "A block holds when price trades into it and the bar closes back out on the side it came from. Only the first hold is marked; the table counts them all.")
showTable = input.bool(true, "Show the block table", group = gD)
rowsN = input.int(6, "Table: blocks listed on each side of the price", minval = 1, maxval = 30, group = gD)
showBroken = input.bool(false, "Keep broken blocks on the chart", group = gD, tooltip = "On leaves a grey outline where a block broke.")
showGone = input.bool(false, "List broken blocks in the table", group = gD)
tablePosIn = input.string("Auto", "Table position", options = ["Auto", "Top center", "Bottom center", "Top right", "Bottom right", "Bottom left", "Top left"], group = gD, tooltip = "Auto looks at the right and middle of the visible chart and puts the table at the top or the bottom where the candles leave the most room.")
txtSizeIn = input.string("Small", "Text size", options = ["Tiny", "Small", "Normal"], group = gD)
cBull = input.color(#00E5A0, "Bullish blocks", group = gD)
cBear = input.color(#FF3D71, "Bearish blocks", group = gD)
cGone = input.color(#787B86, "Broken blocks", group = gD)
cTxt = input.color(#D1D4DC, "Neutral text", group = gD)
gA = "Alerts"
aNew = input.bool(false, "Alert when a new block forms", group = gA)
aEnter = input.bool(true, "Alert when price first trades into a block", group = gA)
aHold = input.bool(true, "Alert the first time a block holds", group = gA)
aBreak = input.bool(true, "Alert when a bar closes beyond a block", group = gA)
isLv = styleIn == "Levels"
txtSize = txtSizeIn == "Tiny" ? size.tiny : txtSizeIn == "Normal" ? size.normal : size.small
bigSize = txtSizeIn == "Tiny" ? size.small : txtSizeIn == "Normal" ? size.large : size.normal
type Block
float top
float bot
float reach
box bx
box gh
line mid
int x1
bool bull
bool gap
int born
int st = 0
int ev = 0
int holds = 0
bool inside = false
int touch = -2
bool heldVisit = false
string tf = ""
line nearLn = na
line farLn = na
var array<Block> bulls = array.new<Block>()
var array<Block> bears = array.new<Block>()
var array<Block> hBulls = array.new<Block>()
var array<Block> hBears = array.new<Block>()
var array<Block> gone = array.new<Block>()
blocks() =>
var float h = na
var int hb = na
var bool hd = true
var float l = na
var int lb = na
var bool ld = true
var float bT = na
var float bB = na
var int bX = na
var bool bG = false
var float sT = na
var float sB = na
var int sX = na
var bool sG = false
float p1 = ta.pivothigh(high, len, len)
float p2 = ta.pivotlow(low, len, len)
if not na(p1)
h := p1
hb := bar_index - len
hd := false
if not na(p2)
l := p2
lb := bar_index - len
ld := false
if not hd and close > h
hd := true
int n = math.max(1, math.min(bar_index - hb, 300))
int bi = 1
float lo = low[1]
for k = 1 to n
if low[k] < lo
lo := low[k]
bi := k
bT := zoneIn == "Body" ? math.max(open[bi], close[bi]) : high[bi]
bB := zoneIn == "Body" ? math.min(open[bi], close[bi]) : low[bi]
bX := time[bi]
bG := false
if bi >= 2
for k = math.max(0, bi - 4) to bi - 2
if low[k] > high[k + 2]
bG := true
if not ld and close < l
ld := true
int n = math.max(1, math.min(bar_index - lb, 300))
int bi = 1
float hi = high[1]
for k = 1 to n
if high[k] > hi
hi := high[k]
bi := k
sT := zoneIn == "Body" ? math.max(open[bi], close[bi]) : high[bi]
sB := zoneIn == "Body" ? math.min(open[bi], close[bi]) : low[bi]
sX := time[bi]
sG := false
if bi >= 2
for k = math.max(0, bi - 4) to bi - 2
if high[k] < low[k + 2]
sG := true
[bT, bB, bX, bG, sT, sB, sX, sG]
closedBlocks() =>
[bT, bB, bX, bG, sT, sB, sX, sG] = blocks()
[bT[1], bB[1], bX[1], bG[1], sT[1], sB[1], sX[1], sG[1]]
tfSec = timeframe.in_seconds()
autoTf = tfSec < 3600 ? "60" : tfSec < 14400 ? "240" : tfSec < 86400 ? "D" : tfSec < 604800 ? "W" : ""
htf = htfIn == "Auto" ? autoTf : htfIn == "1H" ? "60" : htfIn == "4H" ? "240" : htfIn == "Daily" ? "D" : htfIn == "Weekly" ? "W" : ""
useH = htf != "" and timeframe.in_seconds(htf == "" ? timeframe.period : htf) > tfSec
reqTf = useH ? htf : timeframe.period
htfTag = reqTf == "60" ? "1H" : reqTf == "240" ? "4H" : reqTf == "D" ? "Daily" : reqTf == "W" ? "Weekly" : reqTf
[cbT, cbB, cbX, cbG, csT, csB, csX, csG] = blocks()
[hbT, hbB, hbX, hbG, hsT, hsB, hsX, hsG] = request.security(syminfo.tickerid, reqTf, closedBlocks(), lookahead = barmerge.lookahead_on)
atr = ta.atr(14)
col(Block b) => b.bull ? cBull : cBear
zoneText(Block b) => str.tostring(b.bot, format.mintick) + " to " + str.tostring(b.top, format.mintick)
kind(Block b) => (b.bull ? "bullish " : "bearish ") + (b.tf != "" ? b.tf + " " : "") + "order block"
mitPct(Block b) =>
float hgt = b.top - b.bot
hgt <= 0 ? 0.0 : b.bull ? (b.top - math.max(b.reach, b.bot)) / hgt * 100.0 : (math.min(b.reach, b.top) - b.bot) / hgt * 100.0
paint(Block b) =>
color c = col(b)
if isLv
box.set_top(b.bx, b.top)
box.set_bottom(b.bx, b.bot)
else if b.st == 2
box.set_top(b.bx, b.top)
box.set_bottom(b.bx, b.bot)
box.set_bgcolor(b.bx, color.new(c, 92))
box.set_border_color(b.bx, color.new(c, 50))
box.set_border_style(b.bx, line.style_dashed)
box.set_bgcolor(b.gh, color.new(c, 100))
box.set_border_color(b.gh, color.new(c, 100))
else
float edge = b.bull ? math.max(b.reach, b.bot) : math.min(b.reach, b.top)
box.set_top(b.bx, b.bull ? edge : b.top)
box.set_bottom(b.bx, b.bull ? b.bot : edge)
box.set_top(b.gh, b.bull ? b.top : edge)
box.set_bottom(b.gh, b.bull ? edge : b.bot)
box.set_bgcolor(b.gh, color.new(c, b.st == 1 ? 90 : 100))
box.set_border_color(b.gh, color.new(c, b.st == 1 ? 65 : 100))
retire(Block b) =>
line.delete(b.nearLn)
line.delete(b.farLn)
box.set_right(b.bx, time)
box.set_top(b.bx, b.top)
box.set_bottom(b.bx, b.bot)
box.set_text(b.bx, "")
box.set_bgcolor(b.bx, color.new(cGone, 90))
box.set_border_color(b.bx, color.new(cGone, 60))
box.set_border_style(b.bx, line.style_dotted)
box.set_border_width(b.bx, 1)
if not showBroken
box.delete(b.bx)
box.delete(b.gh)
if not na(b.mid)
line.delete(b.mid)
gone.push(b)
while gone.size() > maxN * 2
Block old = gone.shift()
box.delete(old.bx)
drop(Block b) =>
line.delete(b.nearLn)
line.delete(b.farLn)
box.delete(b.bx)
box.delete(b.gh)
if not na(b.mid)
line.delete(b.mid)
add(array<Block> a, bool bull, float top, float bot, int x0, bool gap, string tf) =>
color c = bull ? cBull : cBear
bool hi = tf != ""
box b = box.new(x0, top, time, bot, border_color = color.new(c, isLv ? 100 : gap ? 0 : 25), border_width = hi or gap ? 2 : 1, bgcolor = color.new(c, isLv ? 100 : 72), text_halign = text.align_right, text_valign = text.align_center, text_size = txtSize, xloc = xloc.bar_time)
box gb = box.new(x0, top, time, top, border_color = color.new(c, 100), bgcolor = color.new(c, 100), xloc = xloc.bar_time)
float m = (top + bot) / 2.0
line ln = showMid and not isLv ? line.new(x0, m, time, m, color = color.new(c, 40), style = line.style_dashed, width = 1, xloc = xloc.bar_time) : na
Block blk = Block.new(top, bot, bull ? top : bot, b, gb, ln, x0, bull, gap, bar_index)
blk.tf := tf
if isLv
float ny = bull ? top : bot
float fy = bull ? bot : top
blk.nearLn := line.new(x0, ny, time, ny, color = c, width = gap ? 3 : 2, style = line.style_solid, xloc = xloc.bar_time)
blk.farLn := line.new(x0, fy, time, fy, color = color.new(c, 30), width = 1, style = line.style_dotted, xloc = xloc.bar_time)
int j = 0
while j < a.size()
Block o = a.get(j)
if o.bot <= top and o.top >= bot
drop(o)
a.remove(j)
else
j += 1
a.push(blk)
while a.size() > (hi ? maxH : maxN)
drop(a.shift())
if aNew
alert("OB Radar: " + syminfo.ticker + " formed a " + kind(blk) + (gap ? " with a fair value gap" : "") + ", " + zoneText(blk), alert.freq_once_per_bar_close)
scan(array<Block> a) =>
bool held = false
int i = 0
while i < a.size()
Block b = a.get(i)
bool removed = false
if b.born < bar_index
bool reached = b.bull ? low <= b.top : high >= b.bot
if reached
b.reach := b.bull ? math.min(b.reach, low) : math.max(b.reach, high)
if bar_index - b.touch > 1
b.heldVisit := false
b.touch := bar_index
if not b.inside
b.inside := true
if aEnter
alert("OB Radar: " + syminfo.ticker + " traded into the " + kind(b) + " at " + zoneText(b), alert.freq_once_per_bar_close)
bool broke = b.bull ? close < b.bot : close > b.top
if broke
b.st := 3
b.ev := bar_index
retire(b)
a.remove(i)
removed := true
if aBreak
alert("OB Radar: " + syminfo.ticker + " closed beyond the " + kind(b) + " at " + zoneText(b), alert.freq_once_per_bar_close)
else
bool full = b.bull ? low <= b.bot : high >= b.top
if full and b.st < 2
b.st := 2
b.ev := bar_index
else if b.st == 0
b.st := 1
b.ev := bar_index
bool closedOut = b.bull ? close > b.top : close < b.bot
if closedOut and not b.heldVisit
b.heldVisit := true
b.holds += 1
if b.holds == 1
held := true
if aHold
alert("OB Radar: " + syminfo.ticker + " traded into the " + kind(b) + " at " + zoneText(b) + " and closed back out of it", alert.freq_once_per_bar_close)
if b.st == 2 and not keepFull
drop(b)
a.remove(i)
removed := true
else
paint(b)
if not removed
i += 1
held
bool bullHeld = false
bool bearHeld = false
if barstate.isconfirmed
bool b1 = scan(bulls)
bool b2 = scan(hBulls)
bool s1 = scan(bears)
bool s2 = scan(hBears)
bullHeld := b1 or b2
bearHeld := s1 or s2
if not na(cbX) and cbX != cbX[1]
add(bulls, true, cbT, cbB, cbX, cbG, "")
if not na(csX) and csX != csX[1]
add(bears, false, csT, csB, csX, csG, "")
if useH and not na(hbX) and hbX != hbX[1]
add(hBulls, true, hbT, hbB, hbX, hbG, htfTag)
if useH and not na(hsX) and hsX != hsX[1]
add(hBears, false, hsT, hsB, hsX, hsG, htfTag)
farOf(Block b) => maxAtr > 0 and math.abs((b.top + b.bot) / 2.0 - close) > maxAtr * nz(atr)
array<float> axB = array.new_float()
array<float> axS = array.new_float()
for b in bulls
if not farOf(b)
axB.push(b.top)
for b in hBulls
if not farOf(b)
axB.push(b.top)
for b in bears
if not farOf(b)
axS.push(b.bot)
for b in hBears
if not farOf(b)
axS.push(b.bot)
axB.sort(order.descending)
axS.sort(order.ascending)
axVal(array<float> a, array<float> o, int k) => a.size() > k ? a.get(k) : close * 1000.0
axCol(array<float> a, color c, color oc) => c
axDisp = showAxis ? display.price_scale : display.none
plot(axVal(axB, axS, 0), "Bullish block 1", color = axCol(axB, cBull, cBear), display = axDisp)
plot(axVal(axB, axS, 1), "Bullish block 2", color = axCol(axB, cBull, cBear), display = axDisp)
plot(axVal(axB, axS, 2), "Bullish block 3", color = axCol(axB, cBull, cBear), display = axDisp)
plot(axVal(axB, axS, 3), "Bullish block 4", color = axCol(axB, cBull, cBear), display = axDisp)
plot(axVal(axS, axB, 0), "Bearish block 1", color = axCol(axS, cBear, cBull), display = axDisp)
plot(axVal(axS, axB, 1), "Bearish block 2", color = axCol(axS, cBear, cBull), display = axDisp)
plot(axVal(axS, axB, 2), "Bearish block 3", color = axCol(axS, cBear, cBull), display = axDisp)
plot(axVal(axS, axB, 3), "Bearish block 4", color = axCol(axS, cBear, cBull), display = axDisp)
if showMarks
if bullHeld
label.new(bar_index, low, "", yloc = yloc.belowbar, style = label.style_triangleup, color = cBull, size = size.tiny)
if bearHeld
label.new(bar_index, high, "", yloc = yloc.abovebar, style = label.style_triangledown, color = cBear, size = size.tiny)
times(int n) => n == 1 ? "once" : n == 2 ? "twice" : str.tostring(n) + " times"
ago(int b) => b <= 0 ? "on this bar" : b == 1 ? "1 bar ago" : str.tostring(b) + " bars ago"
meter(float pct) =>
int n = int(math.round(math.max(0.0, math.min(100.0, pct)) / 10.0))
string s = ""
for k = 1 to 10
s += k <= n ? "▰" : "▱"
s
stateText(Block b) =>
string h = b.holds > 0 ? ", held " + times(b.holds) : ""
b.st == 0 ? meter(0) + " untouched" : b.st == 1 ? meter(mitPct(b)) + " " + str.tostring(math.round(mitPct(b))) + "%" + h : b.st == 2 ? meter(100) + " fully mitigated" + h : "broken " + ago(bar_index - b.ev)
zoneTag(Block b) =>
(b.bull ? "Bullish " : "Bearish ") + (b.tf != "" ? b.tf + " " : "") + "OB" + (b.gap ? " + FVG" : "") + " " + (b.st == 0 ? "untouched" : b.st == 2 ? "fully mitigated" : str.tostring(math.round(mitPct(b))) + "% mitigated")
distText(Block b) =>
close > b.top ? str.tostring((b.top - close) / close * 100.0, "0.00") + "%" : close < b.bot ? "+" + str.tostring((b.bot - close) / close * 100.0, "0.00") + "%" : "inside"
stretch(array<Block> a) =>
int back = math.min(bar_index, 200)
for b in a
int right = time + (extBars + (b.tf != "" ? 24 : 0)) * tfSec * 1000
int left = math.max(b.x1, time[back])
box.set_left(b.bx, left)
box.set_left(b.gh, left)
box.set_right(b.bx, right)
box.set_right(b.gh, right)
if not na(b.mid)
line.set_x1(b.mid, left)
line.set_x2(b.mid, right)
bool far = maxAtr > 0 and math.abs((b.top + b.bot) / 2.0 - close) > maxAtr * nz(atr)
if far
box.set_bgcolor(b.bx, color.new(col(b), 100))
box.set_border_color(b.bx, color.new(col(b), 100))
box.set_top(b.bx, close)
box.set_bottom(b.bx, close)
box.set_top(b.gh, close)
box.set_bottom(b.gh, close)
box.set_bgcolor(b.gh, color.new(col(b), 100))
box.set_border_color(b.gh, color.new(col(b), 100))
if not na(b.mid)
line.set_y1(b.mid, close)
line.set_y2(b.mid, close)
line.set_color(b.mid, color.new(col(b), 100))
else
if not isLv
box.set_bgcolor(b.bx, color.new(col(b), 72))
box.set_border_color(b.bx, color.new(col(b), b.gap ? 0 : 25))
paint(b)
if not na(b.mid)
line.set_y1(b.mid, (b.top + b.bot) / 2.0)
line.set_y2(b.mid, (b.top + b.bot) / 2.0)
line.set_color(b.mid, color.new(col(b), 40))
if isLv
line.set_x1(b.nearLn, left)
line.set_x2(b.nearLn, right)
line.set_x1(b.farLn, left)
line.set_x2(b.farLn, right)
float ny = far ? close : b.bull ? b.top : b.bot
float fy = far ? close : b.bull ? b.bot : b.top
line.set_y1(b.nearLn, ny)
line.set_y2(b.nearLn, ny)
line.set_y1(b.farLn, fy)
line.set_y2(b.farLn, fy)
line.set_color(b.nearLn, color.new(col(b), far ? 100 : 0))
line.set_color(b.farLn, color.new(col(b), far ? 100 : 30))
box.set_text(b.bx, showText and not far ? zoneTag(b) : "")
box.set_text_color(b.bx, isLv ? col(b) : #FFFFFF)
box.set_text_size(b.bx, txtSize)
box.set_text_halign(b.bx, text.align_right)
box.set_text_valign(b.bx, isLv ? (b.bull ? text.align_top : text.align_bottom) : text.align_center)
tPos = switch tablePosIn
"Top center" => position.top_center
"Bottom center" => position.bottom_center
"Top right" => position.top_right
"Bottom right" => position.bottom_right
"Bottom left" => position.bottom_left
"Top left" => position.top_left
=> position.top_right
tblBg = color.new(#131722, 8)
var table ladder = table.new(tPos, 4, 100, border_width = 0, frame_width = 0)
cell(int c, int r, string v, color tc) =>
table.cell(ladder, c, r, v, text_color = tc, text_halign = c == 0 or c == 3 ? text.align_right : text.align_left, text_size = txtSize, bgcolor = tblBg)
priceRow(int r) =>
cell(0, r, str.tostring(close, format.mintick), #FFFFFF)
cell(1, r, "◀ price now", #FFFFFF)
cell(2, r, "", cTxt)
cell(3, r, "", cTxt)
if barstate.islast
stretch(bulls)
stretch(bears)
stretch(hBulls)
stretch(hBears)
table.clear(ladder, 0, 0, 3, 99)
float vHi = high
float vLo = low
int vj = 0
while vj < 999 and time[vj] >= chart.left_visible_bar_time
vHi := math.max(vHi, high[vj])
vLo := math.min(vLo, low[vj])
vj += 1
bool atTop = tablePosIn == "Top center" or tablePosIn == "Top left" or tablePosIn == "Top right"
if tablePosIn == "Auto"
float span = math.max(vHi - vLo, syminfo.mintick)
float best = -1.0
string pick = position.top_center
for part = 0 to 2
int a = int(vj * part / 3.0)
int b = math.max(a, math.min(999, int(vj * (part + 1) / 3.0) - 1))
float sHi = high[a]
float sLo = low[a]
for j = a to b
sHi := math.max(sHi, high[j])
sLo := math.min(sLo, low[j])
float bonus = part == 1 ? 0.03 : 0.0
float up = (vHi - sHi) / span + bonus
float dn = (sLo - vLo) / span + bonus
if up > best and part < 2
best := up
pick := part == 0 ? position.top_right : position.top_center
if dn > best
best := dn
pick := part == 0 ? position.bottom_right : part == 1 ? position.bottom_center : position.bottom_left
atTop := pick == position.top_center or pick == position.top_right
table.set_position(ladder, pick)
rows = array.new<Block>()
for b in bulls
rows.push(b)
for b in bears
rows.push(b)
for b in hBulls
rows.push(b)
for b in hBears
rows.push(b)
if showGone
for b in gone
rows.push(b)
int n = rows.size()
if showTable
int off = atTop ? 2 : 0
if off > 0
for k = 0 to off - 1
table.cell(ladder, 0, k, " ", text_size = txtSize)
table.merge_cells(ladder, 0, k, 3, k)
int nb = 0
int ns = 0
for b in rows
if b.st != 3
if b.bull
nb += 1
else
ns += 1
table.cell(ladder, 0, off, "◆ NAMBOU ORDER BLOCK RADAR", text_color = #FFFFFF, text_halign = text.align_left, text_size = bigSize, bgcolor = tblBg)
table.merge_cells(ladder, 0, off, 3, off)
table.cell(ladder, 0, off + 1, "▲ " + str.tostring(nb) + " bullish ▼ " + str.tostring(ns) + " bearish blocks live", text_color = nb > ns ? cBull : ns > nb ? cBear : cTxt, text_halign = text.align_left, text_size = txtSize, bgcolor = tblBg)
table.merge_cells(ladder, 0, off + 1, 3, off + 1)
cell(0, off + 2, "Zone", color.new(cTxt, 40))
cell(1, off + 2, "Block", color.new(cTxt, 40))
cell(2, off + 2, "Mitigated", color.new(cTxt, 40))
cell(3, off + 2, "Distance", color.new(cTxt, 40))
int r = off + 3
bool priceDone = false
if n > 0
mids = array.new_float()
for b in rows
mids.push((b.top + b.bot) / 2.0)
idx = array.sort_indices(mids, order.descending)
int above = 0
for k = 0 to n - 1
if mids.get(k) > close
above += 1
for k = 0 to n - 1
Block b = rows.get(idx.get(k))
bool up = mids.get(idx.get(k)) > close
int rank = up ? above - k : k - above + 1
if rank > rowsN
continue
if not priceDone and mids.get(idx.get(k)) <= close
priceRow(r)
priceDone := true
r += 1
color c = b.st == 3 ? cGone : col(b)
cell(0, r, zoneText(b), c)
table.cell(ladder, 1, r, (b.bull ? "▲ Bullish" : "▼ Bearish") + (b.tf != "" ? " " + b.tf : "") + (b.gap ? " + FVG" : ""), text_color = b.st == 3 ? cGone : #0B0E1A, text_halign = text.align_left, text_size = txtSize, bgcolor = b.st == 3 ? tblBg : color.new(c, b.gap ? 0 : 20))
cell(2, r, stateText(b), c)
cell(3, r, distText(b), c)
r += 1
if not priceDone
priceRow(r)
r += 1
table.cell(ladder, 0, r, "+ FVG: the move away from the block left a fair value gap · ▲ ▼ first hold", text_color = color.new(cTxt, 30), text_halign = text.align_left, text_size = txtSize, bgcolor = tblBg)
table.merge_cells(ladder, 0, r, 3, r)
if not atTop
table.cell(ladder, 0, r + 1, " ", text_size = txtSize)
table.merge_cells(ladder, 0, r + 1, 3, r + 1)
table.cell(ladder, 0, r + 2, " ", text_size = txtSize)
table.merge_cells(ladder, 0, r + 2, 3, r + 2)