本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// ─────────────────────────────────────────────────────────────────
// ███████╗██████╗ ██████╗ ██╗ █████╗ ██████╗
// ██╔════╝██╔══██╗██╔═══██╗██║ ██╔══██╗██╔══██╗
// █████╗ ██║ ██║██║ ██║██║ ███████║██████╔╝
// ██╔══╝ ██║ ██║██║ ██║██║ ██╔══██║██╔══██╗
// ███████╗██████╔╝╚██████╔╝███████╗██║ ██║██████╔╝
// ╚══════╝╚═════╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝╚═════╝
// ─────────────────────────────────────────────────────────────────
// ███╗ ███╗ █████╗ ██████╗ ██╗ ██╗███████╗████████╗███████╗
// ████╗ ████║██╔══██╗██╔══██╗██║ ██╔╝██╔════╝╚══██╔══╝██╔════╝
// ██╔████╔██║███████║██████╔╝█████╔╝ █████╗ ██║ ███████╗
// ██║╚██╔╝██║██╔══██║██╔══██╗██╔═██╗ ██╔══╝ ██║ ╚════██║
// ██║ ╚═╝ ██║██║ ██║██║ ██║██║ ██╗███████╗ ██║ ███████║
// ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝ ╚═╝ ╚══════╝
// ─────────────────────────────────────────────────────────────────
// © Edolab Markets
//@version=6
indicator("Edo S/R Zones", overlay = true, behind_chart = false, max_boxes_count = 200, max_labels_count = 200, max_lines_count = 50, max_bars_back = 500)
// What changes when you scroll or zoom (read before judging the drawing):
// the panel corner and the zone labels follow the visible part of the chart, so the panel can move to another corner
// when the chosen one would cover the latest candles, the zones or their labels, and a label can move off its zone
// (dotted connector) to stay on screen or to uncover a marker. Zones, touches, scores, states and alerts never read
// the visible range: they only use confirmed pivots and closed bars.
// New zones, tests, breaks, retests, rejections, scores and every alert are decided on the close of the candle
// and never move afterwards; on the live candle only the right end of the zones follows the last bar.
// ================== CONSTANTS ==================
// Layout only. Nothing in the zones, the scores, the states or the alerts reads these values
const float SIDE_SHARE = 0.35 // part of the visible chart, at each side, that the panel can cover
const float LOGO_PCT = 9.0 // bottom-left: empty row under the panel, in % of the pane height, so the TradingView logo does not cover its last row
const float ICON_PCT = 6.0 // bottom-right: the same for the round TradingView button in that corner
const float LEGEND_PCT = 4.0 // top-left: empty row above the panel, in % of the pane height, so the TradingView legend does not cover its first rows
const int MARGIN_BARS_LABEL = 8 // empty bars TradingView keeps to the right of the last candle by default (about 10): a label anchored further right is not drawn
const int PANE_W_PX = 1400 // assumed pane width in pixels, to tell which bars a label covers (a narrower pane covers more)
const int SNAP_ROWS = 24 // price rows of the volume profile used by the snap
const float NODE_K = 1.3 // a high-volume node holds at least this many times the average row
const int MAX_ROLE = 3 // role changes counted by the score penalty
// ================== SETTINGS — ZONES ==================
pivotLen = input.int(10, "Pivot Length", minval = 3, maxval = 50, group = "Zones", tooltip = "Bars on each side needed to confirm a swing high / low. A pivot is only used once it is confirmed, so zones never repaint.")
lifetime = input.int(750, "Zone Lifetime (bars)", minval = 50, maxval = 3000, group = "Zones", tooltip = "A zone that price has not touched for this many bars is retired. Keeps the chart on levels that still matter instead of levels from years ago.")
tolMult = input.float(1.0, "Cluster Tolerance (x ATR)", minval = 0.2, maxval = 3.0, step = 0.1, group = "Zones", tooltip = "Pivots closer than this distance (in ATR 200 units) are merged into the same zone. Higher = fewer, wider zones.")
minTouches = input.int(2, "Min Touches to Show", minval = 1, maxval = 5, group = "Zones", tooltip = "A zone is drawn only once this many pivots / tests have hit it. 1 shows every confirmed swing.")
maxZones = input.int(8, "Max Zones", minval = 2, maxval = 20, group = "Zones", tooltip = "Zones kept on the chart. When exceeded, broken zones go first, then the zone price has ignored for longest.")
showBroken = input.bool(true, "Keep Broken Zones", group = "Zones", tooltip = "Broken zones stay on the chart faded and dashed as context until their lifetime runs out. Turn off to remove them on the break.")
extendR = input.int(12, "Extend Zones (bars)", minval = 0, maxval = 100, group = "Zones", tooltip = "How far the live zones are projected to the right of the last bar. The labels end at most 8 bars to the right of the last bar, inside the default right margin of TradingView, so they stay on screen.")
snapR = input.float(1.0, "Volume Node Snap (x ATR)", minval = 0.0, maxval = 3.0, step = 0.1, group = "Zones", tooltip = "When a pivot is confirmed, the volume of the last Volume Profile Bars closed candles is spread over the prices within this distance on the inner side of the wick (below a swing high, above a swing low). A new zone then runs from the wick to the nearest high-volume node there, so its thickness follows where volume really traded (between 0.25 and 1 ATR). At a support the buying volume (green candles) counts double; at a resistance the selling volume. Without a node, or with 0, the zone runs from the wick to the candle body.")
profLen = input.int(100, "Volume Profile Bars", minval = 20, maxval = 300, group = "Zones", tooltip = "Closed candles before the confirmation used by the volume snap. Only candles that had already closed are used, so the zone never changes afterwards.")
flipPen = input.int(8, "Role Change Penalty (points)", minval = 0, maxval = 30, group = "Zones", tooltip = "Points taken off the score for each time the zone was broken: every break flips its role (support becomes resistance and the other way round). Up to 3 breaks are counted. 0 = no penalty.")
hvMult = input.float(1.2, "High Volume (x 50-bar average)", minval = 1.0, maxval = 3.0, step = 0.1, group = "Zones", tooltip = "A break or a retest counts as on volume when the volume of its candle is at least this many times the 50-bar average volume.")
// ================== SETTINGS — SIGNALS ==================
rejN = input.int(2, "Rejection Signals (nearest zones)", minval = 0, maxval = 5, group = "Signals", tooltip = "A triangle marks a rejection when a candle enters a zone, closes back on the side it came from and leaves a wick into the zone of at least half its range. Only the zones nearest to the close count, so the far zones do not add markers. 0 = off. The Tested alerts still cover every zone.")
showRetest = input.bool(true, "Show Retests After a Break", group = "Signals", tooltip = "A diamond marks the first time price comes back into a broken zone and closes again on the side it broke to. Coloured and larger when the candle traded high volume; small and grey on low volume.")
markGap = input.int(3, "Min Bars Between Markers", minval = 1, maxval = 50, group = "Signals", tooltip = "A rejection triangle or a retest diamond is skipped when another marker was drawn less than this many bars before, so a zone tested on several candles in a row does not fill the chart. The panel and the alerts keep every event. 1 = every marker.")
// ================== SETTINGS — STYLE ==================
resCol = input.color(#e53935, "Resistance", inline = "c1", group = "Style")
supCol = input.color(#4caf50, "Support", inline = "c1", group = "Style")
zoneOpac = input.int(80, "Zone Opacity %", minval = 0, maxval = 95, step = 5, group = "Style", tooltip = "Transparency of the zone fill: higher = lighter fill, so the wicks inside the zone stay visible. Default: 80%. Broken zones are drawn 20 points lighter and the Light theme adds 5 more.")
showLabels = input.bool(true, "Show Zone Labels", group = "Style", tooltip = "Two-line label at the right end of each zone, growing to the left: role and state, then score (0-100) and touches. A zone beyond the visible candles keeps its label inside the chart with an arrow towards it (▲ above, ▼ below), only the nearest one on each side. When there are more labels than fit in the visible height, the zones farthest from the price lose their label first.")
showPrices = input.bool(true, "Show Zone Prices", group = "Style", tooltip = "Adds the price range (bottom - top) of each live zone to its label, so the zones that reach the right edge show their prices.")
brokenLbl = input.int(2, "Labels on Broken Zones", minval = 0, maxval = 20, group = "Style", tooltip = "Only the most recently broken zones keep their label, so several broken zones do not pile text over the candles. The other broken zones stay drawn, faded and dashed, without text. 0 = no labels on broken zones.")
labelSize = input.string("Medium", "Label Size", options = ["Small", "Medium", "Large"], group = "Style")
themeMode = input.string("Dark", "Theme Mode", options = ["Dark", "Light"], group = "Style", tooltip = "Match your TradingView background theme.")
// ================== SETTINGS — PANEL ==================
showPanel = input.bool(true, "Show Panel", group = "Panel")
panelDetail = input.string("Full", "Panel Detail", options = ["Full", "Compact"], group = "Panel", tooltip = "Full: zone counts, nearest resistance and support with score, last event. Compact: only the nearest resistance and support with their distance and the last event.")
panelPos = input.string("Top Right", "Panel Position", options = ["Top Right", "Top Left", "Bottom Right", "Bottom Left"], group = "Panel")
panelAvoid = input.bool(true, "Keep Panel Off the Zones", group = "Panel", tooltip = "The panel stays in the chosen corner while it leaves the latest candles, the zones and their labels uncovered. Otherwise it moves to the first other corner with room (same side first) or, if none has room, to the one that covers the least (zone labels and the latest candles count most). It moves back when there is room again. Off = the panel always stays in the chosen corner.")
panelSize = input.string("Medium", "Panel Size", options = ["Small", "Medium"], group = "Panel")
// Labels end here: inside the default right margin, never further than the zones
lblOff = math.min(extendR, MARGIN_BARS_LABEL)
// ================== THEME ==================
isDark = themeMode == "Dark"
textCol = isDark ? #ffffff : #131722
headerBg = isDark ? #2a2e39 : #d1d4dc
subHeaderBg = isDark ? #363a45 : #e0e3eb
cellBg = isDark ? #1e222d : #f0f3fa
cellTxt = isDark ? #d1d4dc : #363a45
numTxt = isDark ? #b2b5be : #555a67
hiddenCol = color.new(color.gray, 100) // fully transparent, for zones below the touch threshold
lblSizeTxt = labelSize == "Small" ? size.small : labelSize == "Large" ? size.large : size.normal
panSizeTxt = panelSize == "Small" ? size.tiny : size.small
// ================== TYPES ==================
// One S/R zone built from clustered pivots.
// state: 0 = Active (fresh, not yet tested), 1 = Tested (held at least once), 2 = Broken (closed through).
type Zone
box bx
label lb
float top
float bottom
int touches // confirmed pivots + successful tests
int createdBar
int lastTouchBar // last bar where a pivot, a test or the break hit the zone
float volSum // volume of the pivot candles that built the zone
int pivotCount
int state
int side // last closed-bar side of price vs the zone: 1 above, -1 below, 0 inside
int score
int breaks = 0 // times the zone was broken: each break flips its role
int brkBar = -1 // bar of the last break
bool brkVol = false // the last break closed on high volume
bool retested = false // the first retest after the last break was already seen
int testBar = -1 // bar of the last successful test
var zones = array.new<Zone>()
// ================== CALCULATIONS ==================
atrRef = ta.atr(200)
tolerance = atrRef * tolMult
minThick = atrRef * 0.25
volRef = ta.sma(volume, 50)
hasVol = not na(volume) and volRef > 0
ph = ta.pivothigh(pivotLen, pivotLen)
pl = ta.pivotlow(pivotLen, pivotLen)
// Pivot candle data at the confirmation offset
pivBar = bar_index - pivotLen
pivVol = nz(volume[pivotLen])
phWick = high[pivotLen]
phBody = math.max(open[pivotLen], close[pivotLen])
plWick = low[pivotLen]
plBody = math.min(open[pivotLen], close[pivotLen])
// Closed candles for the volume snap, oldest first. They are stored after the zones are built, so a pivot
// confirmed on this candle only reads the candles before it
var bufH = array.new_float()
var bufL = array.new_float()
var bufV = array.new_float()
var bufD = array.new_int()
// ================== HELPERS ==================
// Score 0-100: touches (50) + time held (25) + relative volume of the pivot candles (25).
// Time held is measured against half the lifetime, so a zone does not need to be ancient to earn it.
// Without volume data (cash indices) the volume block is redistributed to touches + time.
// Each break (role change) takes Role Change Penalty points off, up to 3 breaks.
scoreZone(Zone z) =>
touchPts = math.min(z.touches, 6) / 6.0 * 50.0
agePts = math.min((bar_index - z.createdBar) / (lifetime * 0.5), 1.0) * 25.0
avgPivVol = z.pivotCount > 0 ? z.volSum / z.pivotCount : 0.0
volRatio = hasVol ? math.min(avgPivVol / volRef, 2.0) / 2.0 : na
volPts = not na(volRatio) ? volRatio * 25.0 : na
raw = not na(volPts) ? touchPts + agePts + volPts : (touchPts + agePts) / 75.0 * 100.0
pen = flipPen * math.min(z.breaks, MAX_ROLE)
int(math.round(math.max(math.min(raw, 100.0) - pen, 0.0)))
// -1 = support (zone below price), 1 = resistance (zone above price).
// While price trades inside the zone it keeps the role of the side it came from: a zone
// approached from below is still a resistance under test until a close above breaks it.
roleOf(Zone z) =>
close > z.top ? -1 : close < z.bottom ? 1 : z.side == 0 ? 0 : -z.side
roleColor(int role) =>
role == 1 ? resCol : role == -1 ? supCol : color.gray
// Active = never tested; Reclaimed = respected again after a break; Tested = held at least once; Broken
stateText(Zone z) =>
z.state == 0 ? (z.breaks > 0 ? "Reclaimed" : "Active") : z.state == 1 ? "Tested" : z.brkVol ? "Broken on volume" : "Broken"
evText(int c) =>
c == 1 ? "Resistance broken" : c == 2 ? "Support broken" : c == 3 ? "Retest up on volume" : c == 4 ? "Retest up" : c == 5 ? "Retest down on volume" : c == 6 ? "Retest down" : c == 7 ? "Support rejection" : c == 8 ? "Resistance rejection" : c == 9 ? "Support tested" : c == 10 ? "Resistance tested" : c == 11 ? "Zone reactivated" : c == 12 ? "New zone" : "None yet"
evColor(int c) =>
c == 1 or c == 3 or c == 4 or c == 7 or c == 9 ? supCol : c == 2 or c == 5 or c == 6 or c == 8 or c == 10 ? resCol : textCol
touchesText(int n) =>
str.tostring(n) + (n == 1 ? " touch" : " touches")
// Full zone text, two lines: role · state / score · touches. It is the label of a live zone and the tooltip of every label
zoneText(Zone z, int role) =>
roleTxt = role == 1 ? "Resistance" : role == -1 ? "Support" : "Zone"
priceTxt = showPrices and z.state != 2 ? " · " + str.tostring(z.bottom, format.mintick) + " – " + str.tostring(z.top, format.mintick) : ""
roleTxt + " · " + stateText(z) + priceTxt + "\nScore " + str.tostring(z.score) + " · " + touchesText(z.touches) + (z.breaks > 0 ? " · " + str.tostring(z.breaks) + (z.breaks == 1 ? " role change" : " role changes") : "")
removeZone(int i) =>
z = zones.get(i)
box.delete(z.bx)
label.delete(z.lb)
zones.remove(i)
paintZone(Zone z) =>
role = roleOf(z)
base = roleColor(role)
broken = z.state == 2
fillOp = math.min((broken ? zoneOpac + 20 : zoneOpac) + (isDark ? 0 : 5), 95)
lineOp = broken ? 60 : 0
box.set_bgcolor(z.bx, color.new(base, fillOp))
box.set_border_color(z.bx, color.new(base, lineOp))
box.set_border_style(z.bx, broken ? line.style_dashed : line.style_solid)
// Every label ends lblOff bars right of the last bar (inside the default right margin) and grows to the left; the last bar stacks them (LABEL LAYOUT).
// A broken zone gets a one-line label (role · state · score); the full text is in the tooltip
fullTxt = zoneText(z, role)
roleTxt = role == 1 ? "Resistance" : role == -1 ? "Support" : "Zone"
label.set_xy(z.lb, bar_index + lblOff, (z.top + z.bottom) / 2)
label.set_text(z.lb, showLabels ? (broken ? roleTxt + " · " + stateText(z) + " · " + str.tostring(z.score) : fullTxt) : "")
label.set_tooltip(z.lb, fullTxt)
label.set_color(z.lb, showLabels ? color.new(base, broken ? 25 : 15) : hiddenCol)
label.set_textcolor(z.lb, textCol)
label.set_size(z.lb, lblSizeTxt)
hideZone(Zone z) =>
box.set_bgcolor(z.bx, hiddenCol)
box.set_border_color(z.bx, hiddenCol)
label.set_text(z.lb, "")
label.set_color(z.lb, hiddenCol)
// Inner edge of a new zone at the nearest high-volume node within the snap distance, or na without one.
// Profile: the stored closed candles spread over SNAP_ROWS rows on the inner side of the wick, the volume of each
// candle shared by the rows its range covers; at a resistance the selling candles count double, at a support the
// buying ones. A node is a row that is a local peak and holds at least NODE_K times the average row; the nearest
// to the wick wins
volumeNode(float wick, bool isHigh) =>
float edge = na
int n = bufH.size()
float rng = snapR * atrRef
if n > 0 and rng > 0
float lo = isHigh ? wick - rng : wick
float hi = lo + rng
float rowH = rng / SNAP_ROWS
array<float> sc = array.new_float(SNAP_ROWS, 0.0)
for k = 0 to n - 1
float h = bufH.get(k)
float l = bufL.get(k)
float v = bufV.get(k)
if v > 0 and h >= lo and l <= hi
int d = bufD.get(k)
float w = d == 0 ? 0.75 : (d == 1) == isHigh ? 0.5 : 1.0
int r0 = math.max(0, math.min(SNAP_ROWS - 1, int(math.floor((math.max(l, lo) - lo) / rowH))))
int r1 = math.max(0, math.min(SNAP_ROWS - 1, int(math.floor((math.min(h, hi) - lo) / rowH))))
float br = h - l
if br <= 0
sc.set(r0, sc.get(r0) + v * w)
else
for r = r0 to r1
float rb = lo + r * rowH
float ov = math.min(h, rb + rowH) - math.max(l, rb)
if ov > 0
sc.set(r, sc.get(r) + v * w * ov / br)
float avg = sc.sum() / SNAP_ROWS
if avg > 0
for j = 0 to SNAP_ROWS - 1
int r = isHigh ? SNAP_ROWS - 1 - j : j
float s = sc.get(r)
float sl = r > 0 ? sc.get(r - 1) : 0.0
float su = r < SNAP_ROWS - 1 ? sc.get(r + 1) : 0.0
if na(edge) and s >= NODE_K * avg and s >= sl and s >= su
edge := isHigh ? lo + r * rowH : lo + (r + 1) * rowH
edge
// Returns 0 = reinforced a live zone, 1 = new zone, 2 = reactivated a broken zone
addPivotToZones(float wick, float body, bool isHigh) =>
// Candidate zone: wick-to-body of the pivot candle, clamped between 0.25 and 1 ATR
thick = math.max(math.min(math.abs(wick - body), tolerance), minThick)
// Volume snap: from the wick to the nearest high-volume node on the inner side, same limits
if snapR > 0 and hasVol
float nodeEdge = volumeNode(wick, isHigh)
if not na(nodeEdge)
thick := math.max(math.min(math.abs(wick - nodeEdge), tolerance), minThick)
cTop = isHigh ? wick : wick + thick
cBot = isHigh ? wick - thick : wick
// 1) reinforce an existing zone if the pivot is within tolerance of its centre or the
// candidate overlaps / nearly touches it (half a tolerance): zones never overlap.
// Live zones are searched first; a broken zone is only a fallback, and hitting it
// reactivates the level (classic support/resistance flip).
int found = -1
float bestDist = na
bool foundBroken = false
if zones.size() > 0
for stage = 0 to 1
if found < 0
for i = 0 to zones.size() - 1
z = zones.get(i)
if (stage == 0 and z.state != 2) or (stage == 1 and z.state == 2)
mid = (z.top + z.bottom) / 2
dist = math.abs(wick - mid)
overlaps = cTop >= z.bottom - tolerance * 0.5 and cBot <= z.top + tolerance * 0.5
if (dist <= tolerance or overlaps) and (na(bestDist) or dist < bestDist)
bestDist := dist
found := i
foundBroken := stage == 1
if found >= 0
z = zones.get(found)
newTop = math.max(z.top, wick)
newBot = math.min(z.bottom, wick)
// grow the zone only while it stays under 2 ATR thick; otherwise just count the touch
if newTop - newBot <= tolerance * 2
z.top := newTop
z.bottom := newBot
box.set_top(z.bx, z.top)
box.set_bottom(z.bx, z.bottom)
z.touches := z.touches + 1
z.pivotCount := z.pivotCount + 1
z.volSum := z.volSum + pivVol
z.lastTouchBar := pivBar
if foundBroken
// the level is respected again from the other side: back to Active with the new role
z.state := 0
z.side := close > z.top ? 1 : close < z.bottom ? -1 : 0
foundBroken ? 2 : 0
else
// 2) new zone
bx = box.new(pivBar, cTop, bar_index + extendR, cBot, border_width = 1, text = "")
lb = label.new(bar_index + lblOff, (cTop + cBot) / 2, "", style = label.style_label_right, textcolor = textCol, color = hiddenCol, size = lblSizeTxt)
z = Zone.new(bx, lb, cTop, cBot, 1, pivBar, pivBar, pivVol, 1, 0, 0, 0)
z.side := close > cTop ? 1 : close < cBot ? -1 : 0
zones.push(z)
1
// ================== ZONE CREATION ==================
// Pivots are only used once ATR 200 exists, so no zone is ever built with an undefined width.
// A pivot is only read on a closed candle: on the live candle the pivot functions see a high or a low that can
// still change, so a zone (and its alert) could appear and vanish within the same candle
newZone = false
reactivated = false
if barstate.isconfirmed and not na(ph) and not na(atrRef)
r = addPivotToZones(phWick, phBody, true)
newZone := newZone or r == 1
reactivated := reactivated or r == 2
if barstate.isconfirmed and not na(pl) and not na(atrRef)
r = addPivotToZones(plWick, plBody, false)
newZone := newZone or r == 1
reactivated := reactivated or r == 2
// Store the closed candle for the next snaps (after the zones of this candle are built)
if barstate.isconfirmed
bufH.push(high)
bufL.push(low)
bufV.push(nz(volume))
bufD.push(close > open ? 1 : close < open ? -1 : 0)
while bufH.size() > profLen
bufH.shift()
bufL.shift()
bufV.shift()
bufD.shift()
// ================== ZONE STATE UPDATE (closed bars only) ==================
testedRes = false
testedSup = false
brokenRes = false
brokenSup = false
retestUpVol = false // broken resistance retested from above and held, on high volume
retestUpLow = false
retestDnVol = false // broken support retested from below and held, on high volume
retestDnLow = false
if barstate.isconfirmed and zones.size() > 0
int lastIdx = zones.size() - 1 // fixed before the loop: a zone removed inside it must not change the range
for i = lastIdx to 0
z = zones.get(i)
if z.state != 2
touched = high >= z.bottom and low <= z.top
sideNow = close > z.top ? 1 : close < z.bottom ? -1 : 0
crossedUp = z.side == -1 and sideNow == 1
crossedDown = z.side == 1 and sideNow == -1
if crossedUp or crossedDown
z.state := 2
z.lastTouchBar := bar_index
z.breaks := z.breaks + 1
z.brkBar := bar_index
z.brkVol := hasVol and volume >= volRef * hvMult
z.retested := false
brokenRes := brokenRes or crossedUp
brokenSup := brokenSup or crossedDown
box.set_right(z.bx, bar_index)
if not showBroken
removeZone(i)
else if touched and sideNow != 0 and sideNow == z.side
// price entered the zone and closed back on the same side: a successful test
z.state := 1
z.touches := z.touches + 1
z.lastTouchBar := bar_index
z.testBar := bar_index
testedRes := testedRes or sideNow == -1
testedSup := testedSup or sideNow == 1
else if touched
z.lastTouchBar := bar_index
if sideNow != 0
z.side := sideNow
else if not z.retested and bar_index > z.brkBar
// Broken zone: the first time price comes back into it and closes outside. Closing on the side it broke to
// is a retest of the new role; closing back on the old side ends the watch without a signal
sideNow = close > z.top ? 1 : close < z.bottom ? -1 : 0
if high >= z.bottom and low <= z.top and sideNow != 0
z.retested := true
if sideNow == z.side and z.touches >= minTouches
hv = hasVol and volume >= volRef * hvMult
retestUpVol := retestUpVol or (sideNow == 1 and hv)
retestUpLow := retestUpLow or (sideNow == 1 and not hv)
retestDnVol := retestDnVol or (sideNow == -1 and hv)
retestDnLow := retestDnLow or (sideNow == -1 and not hv)
// ================== REJECTIONS (closed bars only) ==================
// A successful test is a rejection signal only on the zones nearest to the close (distance 0 inside a zone) and
// only when the candle leaves a long wick into the zone: at least half of its range
rejSup = false
rejRes = false
candleRng = high - low
longLow = candleRng > 0 and math.min(open, close) - low >= 0.5 * candleRng
longHigh = candleRng > 0 and high - math.max(open, close) >= 0.5 * candleRng
if barstate.isconfirmed and rejN > 0 and zones.size() > 0
array<float> dz = array.new_float()
array<int> iz = array.new_int()
for i = 0 to zones.size() - 1
z = zones.get(i)
if z.state != 2 and z.touches >= minTouches
dz.push(close > z.top ? close - z.top : close < z.bottom ? z.bottom - close : 0.0)
iz.push(i)
if iz.size() > 0
array<int> ordD = dz.sort_indices(order.ascending)
for k = 0 to math.min(rejN, iz.size()) - 1
z = zones.get(iz.get(ordD.get(k)))
if z.testBar == bar_index
rejSup := rejSup or (z.side == 1 and longLow)
rejRes := rejRes or (z.side == -1 and longHigh)
// ================== LAST EVENT (closed bars only, for the panel) ==================
// Code of the most important event of the candle: 1 resistance broken, 2 support broken, 3 retest up on volume,
// 4 retest up, 5 retest down on volume, 6 retest down, 7 support rejection, 8 resistance rejection, 9 support tested,
// 10 resistance tested, 11 zone reactivated, 12 new zone
var int lastEvC = 0
var int lastEvB = na
if barstate.isconfirmed
int ec = brokenRes ? 1 : brokenSup ? 2 : retestUpVol ? 3 : retestUpLow ? 4 : retestDnVol ? 5 : retestDnLow ? 6 : rejSup ? 7 : rejRes ? 8 : testedSup ? 9 : testedRes ? 10 : reactivated ? 11 : newZone ? 12 : 0
if ec != 0
lastEvC := ec
lastEvB := bar_index
// ================== RETIRE, SCORE, DRAW ==================
// Retire zones price has ignored for longer than the lifetime (broken ones included), on closed candles
if barstate.isconfirmed and zones.size() > 0
int lastIdx = zones.size() - 1
for i = lastIdx to 0
if bar_index - zones.get(i).lastTouchBar > lifetime
removeZone(i)
if zones.size() > 0
for i = 0 to zones.size() - 1
z = zones.get(i)
// The score is updated on closed candles only, so it does not move with the volume of the live candle
if barstate.isconfirmed
z.score := scoreZone(z)
if z.state != 2
box.set_right(z.bx, bar_index + extendR)
if z.touches >= minTouches
paintZone(z)
else
hideZone(z)
// Prune: broken zones first (oldest), then the live zone price has ignored for longest.
// Never by score, so a fresh zone is not evicted by old strong ones.
while zones.size() > maxZones
int victim = -1
for i = 0 to zones.size() - 1
if zones.get(i).state == 2
victim := i
break
if victim < 0
int oldest = bar_index + 1
for i = 0 to zones.size() - 1
t = zones.get(i).lastTouchBar
if t < oldest
oldest := t
victim := i
removeZone(victim)
// ================== LABELS ON BROKEN ZONES (display only) ==================
// Only the most recently broken zones keep their text; the others stay drawn without a label
if barstate.islast and zones.size() > 0
array<int> bKey = array.new_int()
array<int> bIdx = array.new_int()
for i = 0 to zones.size() - 1
z = zones.get(i)
if z.state == 2 and z.touches >= minTouches
bKey.push(z.lastTouchBar)
bIdx.push(i)
if bIdx.size() > brokenLbl
array<int> ord = bKey.sort_indices(order.descending)
for k = brokenLbl to ord.size() - 1
z = zones.get(bIdx.get(ord.get(k)))
label.set_text(z.lb, "")
label.set_color(z.lb, hiddenCol)
// ================== VISIBLE RANGE (display only) ==================
// Price span of the visible candles and of their left and right parts, where the panel can sit.
// Used only to choose the panel corner; nothing in the zones, the scores or the alerts reads it
int visL = chart.left_visible_bar_time
int visR = chart.right_visible_bar_time
bool inVis = not na(visL) and not na(visR) and time >= visL and time <= visR
float sideW = inVis ? (visR - visL) * SIDE_SHARE : na
bool inRgt = inVis and time >= visR - sideW
bool inLft = inVis and time <= visL + sideW
var float visHi = na
var float visLo = na
var float rgtHi = na
var float rgtLo = na
var float lftHi = na
var float lftLo = na
var int visLB = na // first visible bar
var int visRB = na // last visible bar
var int lftEB = na // last bar of the left part
var int rgtSB = na // first bar of the right part
if inVis
visHi := na(visHi) ? high : math.max(visHi, high)
visLo := na(visLo) ? low : math.min(visLo, low)
visLB := na(visLB) ? bar_index : visLB
visRB := bar_index
if inRgt
rgtHi := na(rgtHi) ? high : math.max(rgtHi, high)
rgtLo := na(rgtLo) ? low : math.min(rgtLo, low)
rgtSB := na(rgtSB) ? bar_index : rgtSB
if inLft
lftHi := na(lftHi) ? high : math.max(lftHi, high)
lftLo := na(lftLo) ? low : math.min(lftLo, low)
lftEB := bar_index
// ================== MARKERS (display only) ==================
// Display only: a marker is skipped when another one was drawn less than Min Bars Between Markers before.
// The events, the panel and the alerts keep every rejection and retest. Decided before the label layout, which keeps
// the labels off the markers; the plotshape calls stay at the end
var int lastMkB = na
bool mkOk = na(lastMkB) or bar_index - lastMkB >= markGap
bool mRejS = mkOk and rejSup
bool mRejR = mkOk and rejRes
bool mRuv = mkOk and showRetest and retestUpVol
bool mRul = mkOk and showRetest and retestUpLow
bool mRdv = mkOk and showRetest and retestDnVol
bool mRdl = mkOk and showRetest and retestDnLow
if mRejS or mRejR or mRuv or mRul or mRdv or mRdl
lastMkB := bar_index
// ================== LABEL LAYOUT (display only, last bar) ==================
// All labels end at the right edge and grow to the left. They are stacked from the top so two labels are never closer
// than one ATR 200 or one label height, and kept inside the visible candles (the part of the pane the autoscale always
// shows); a label moved off its zone, and every broken zone, is joined to its label by a dotted connector from the end of the zone
var lblLinks = array.new<line>()
if barstate.islast
while lblLinks.size() > 0
line.delete(lblLinks.pop())
if showLabels and zones.size() > 0
float vSpan = not na(visHi) and not na(visLo) and visHi > visLo ? visHi - visLo : na
float lblHt = na(vSpan) ? 0.0 : vSpan * (labelSize == "Small" ? 0.08 : labelSize == "Large" ? 0.14 : 0.11)
float sep = math.max(nz(atrRef), lblHt * 1.15)
float farM = nz(vSpan) * 0.1 // about the autoscale margin past the visible candles
// A zone beyond the visible candles (past that margin) is off screen: only the nearest one on each side keeps its
// label, pinned inside with an arrow towards the zone; the others lose the text (the panel and the alerts keep them)
int upI = -1
int dnI = -1
if not na(vSpan)
for i = 0 to zones.size() - 1
z = zones.get(i)
if label.get_text(z.lb) != ""
if z.bottom > visHi + farM and (upI < 0 or z.bottom < zones.get(upI).bottom)
upI := i
if z.top < visLo - farM and (dnI < 0 or z.top > zones.get(dnI).top)
dnI := i
array<float> ys = array.new_float()
array<int> ix = array.new_int()
array<float> ds = array.new_float() // distance of the zone to the close (0 inside)
for i = 0 to zones.size() - 1
z = zones.get(i)
string tx = label.get_text(z.lb)
if tx != ""
bool up = not na(vSpan) and z.bottom > visHi + farM
bool dn = not na(vSpan) and z.top < visLo - farM
if (up and i != upI) or (dn and i != dnI)
label.set_text(z.lb, "")
label.set_color(z.lb, hiddenCol)
else
if up or dn
label.set_text(z.lb, (up ? "▲ " : "▼ ") + tx)
ys.push((z.top + z.bottom) / 2)
ix.push(i)
ds.push(close > z.top ? close - z.top : close < z.bottom ? z.bottom - close : 0.0)
// Never more labels than fit between the top and the bottom of the visible candles, one label height apart, with
// the bottom kept clear of the round TradingView button: the zones farthest from the close lose the text first.
// The gap between labels shrinks down to one label height before any label is dropped
float loB = na(vSpan) ? na : visLo + vSpan * ICON_PCT / 100 + lblHt / 2
float hiB = na(vSpan) ? na : visHi - lblHt / 2
if not na(vSpan) and ix.size() > 1
int nFit = math.max(1, int(math.floor((hiB - loB) / (lblHt * 1.05))) + 1)
if ix.size() > nFit
array<int> ordD = ds.sort_indices(order.descending)
array<bool> drop = array.new_bool(ix.size(), false)
for k = 0 to ix.size() - nFit - 1
drop.set(ordD.get(k), true)
for k = ix.size() - 1 to 0
if drop.get(k)
z = zones.get(ix.get(k))
label.set_text(z.lb, "")
label.set_color(z.lb, hiddenCol)
ys.remove(k)
ix.remove(k)
if ix.size() > 1
sep := math.max(math.min(sep, (hiB - loB) / (ix.size() - 1)), lblHt * 1.05)
if ix.size() > 0
array<int> ordY = ys.sort_indices(order.descending)
int nL = ordY.size()
int xe = bar_index + lblOff
// Pass 1, from the top: each label at its zone (never above the visible candles), or one gap under the label above it
array<float> yN = array.new_float(nL, 0.0)
float prevY = na
for k = 0 to nL - 1
float y0 = ys.get(ordY.get(k))
float y = na(prevY) ? (na(vSpan) ? y0 : math.min(y0, hiB)) : math.min(y0, prevY - sep)
yN.set(k, y)
prevY := y
// Pass 2, from the bottom: a stack pushed under the visible prices (or onto the TradingView button) is lifted back, keeping the gaps
if not na(vSpan)
float nextY = na
for k = nL - 1 to 0
float y = na(nextY) ? math.max(yN.get(k), loB) : math.max(yN.get(k), nextY + sep)
yN.set(k, y)
nextY := y
// Pass 3: a label is moved off the rejection triangles and retest diamonds drawn on the bars its text covers
// (width from the text and the visible bars): past the marker, away from the candle, or to the candle side
// when the pane has no room left there; the labels next to it are pushed along so the gaps hold
if not na(vSpan) and not na(visR) and visR >= time
float mkH = vSpan * 0.06
float hh = lblHt / 2
float capT = visHi + farM - hh
float capB = loB
int nVB = bar_index - nz(visLB, bar_index) + 1 + MARGIN_BARS_LABEL + 2
float chPx = labelSize == "Small" ? 7.0 : labelSize == "Large" ? 10.5 : 8.5
for k = 0 to nL - 1
z = zones.get(ix.get(ordY.get(k)))
int nCh = 0
for s in str.split(label.get_text(z.lb), "\n")
nCh := math.max(nCh, str.length(s))
int back = math.min(int(math.ceil(nVB * (nCh * chPx + 24) / PANE_W_PX)) - lblOff, 300, bar_index)
float y = yN.get(k)
if back >= 0
for b = 0 to back
if mRejR[b] or mRdv[b] or mRdl[b]
float mLo = high[b]
if y + hh > mLo and y - hh < mLo + mkH
y := mLo + mkH + hh <= capT ? mLo + mkH + hh : mLo - hh
if mRejS[b] or mRuv[b] or mRul[b]
float mHi = low[b]
if y + hh > mHi - mkH and y - hh < mHi
y := mHi - mkH - hh >= capB ? mHi - mkH - hh : mHi + hh
if y != yN.get(k)
yN.set(k, y)
if k > 0
for j = k - 1 to 0
yN.set(j, math.max(yN.get(j), yN.get(j + 1) + sep))
if k < nL - 1
for j = k + 1 to nL - 1
yN.set(j, math.min(yN.get(j), yN.get(j - 1) - sep))
// Pass 4: the moves of pass 3 can push a label past the bottom (or the top): the stack is put back between the
// bottom limit and the top of the visible candles plus their margin, keeping the gaps. It always fits, because
// the number of labels and the gap were sized for the visible candles above
if not na(vSpan)
float topL = visHi + farM - lblHt / 2
float nx = na
for k = nL - 1 to 0
yN.set(k, na(nx) ? math.max(yN.get(k), loB) : math.max(yN.get(k), nx + sep))
nx := yN.get(k)
float pv = na
for k = 0 to nL - 1
yN.set(k, na(pv) ? math.min(yN.get(k), topL) : math.min(yN.get(k), pv - sep))
pv := yN.get(k)
for k = 0 to nL - 1
int q = ordY.get(k)
float y0 = ys.get(q)
float y = yN.get(k)
z = zones.get(ix.get(q))
label.set_xy(z.lb, xe, y)
int xz = math.min(box.get_right(z.bx), xe) // a live zone runs past the label: its connector is vertical
// connector when the label left its zone (by more than 1 % of an ATR) or the zone ends before the right edge
if math.abs(y - y0) > nz(atrRef) * 0.01 or xz < xe
lblLinks.push(line.new(xz, y0, xe, y, color = color.new(z.state == 2 ? color.gray : roleColor(roleOf(z)), 40), style = line.style_dotted, width = 1))
// ================== PANEL ==================
if showPanel
panelPosTV = switch panelPos
"Top Right" => position.top_right
"Top Left" => position.top_left
"Bottom Right" => position.bottom_right
"Bottom Left" => position.bottom_left
=> position.top_right
var table panel = table.new(panelPosTV, 4, 10, frame_color = isDark ? #363a45 : #b2b5be, frame_width = 1, border_color = isDark ? #434651 : #c8cbda, border_width = 1)
if barstate.islast
table.clear(panel, 0, 0, 3, 9)
activeCount = 0
testedCount = 0
brokenCount = 0
Zone nearR = na
Zone nearS = na
if zones.size() > 0
for i = 0 to zones.size() - 1
z = zones.get(i)
if z.touches < minTouches
continue
if z.state == 0
activeCount += 1
else if z.state == 1
testedCount += 1
else
brokenCount += 1
if z.state != 2
role = roleOf(z)
if role == 1 and (na(nearR) or z.bottom < nearR.bottom)
nearR := z
if role == -1 and (na(nearS) or z.top > nearS.top)
nearS := z
rPrice = not na(nearR) ? str.tostring(nearR.bottom, format.mintick) + " – " + str.tostring(nearR.top, format.mintick) : "—"
sPrice = not na(nearS) ? str.tostring(nearS.bottom, format.mintick) + " – " + str.tostring(nearS.top, format.mintick) : "—"
rDist = na(nearR) or close == 0 ? "—" : close >= nearR.bottom ? "inside" : "+" + str.tostring((nearR.bottom - close) / close * 100, "#.##") + "% away"
sDist = na(nearS) or close == 0 ? "—" : close <= nearS.top ? "inside" : "-" + str.tostring((close - nearS.top) / close * 100, "#.##") + "% away"
rScore = not na(nearR) ? "Score " + str.tostring(nearR.score) + " · " + touchesText(nearR.touches) + " · " + stateText(nearR) : "—"
sScore = not na(nearS) ? "Score " + str.tostring(nearS.score) + " · " + touchesText(nearS.touches) + " · " + stateText(nearS) : "—"
evRow = lastEvC == 0 ? "None yet" : evText(lastEvC) + " · " + (lastEvB == bar_index ? "this bar" : str.tostring(bar_index - lastEvB) + (bar_index - lastEvB == 1 ? " bar ago" : " bars ago"))
bool full = panelDetail == "Full"
int nRows = full ? 9 : 5 // title + body + footer; one more row is kept for the spacer, so the table never passes 10 rows
// Keep the panel off the drawing. Each corner gets a cost for what the panel would cover there: a zone label, or the
// last 5 candles with their markers, 100 points each; the candles of that side up to 20; each zone up to 5.
// The script cannot read the price scale, so the cost is added over two estimates of it: autoscale on the visible
// candles (TradingView default margins, 10 % top and 8 % bottom) and a scale that also fits the zones drawn in the
// visible part. The panel stays in the chosen corner while it covers almost nothing (cost <= 1); otherwise it goes
// to the first other corner that does (same side first) or, if none does, to the cheapest one.
// Right corners: the latest candles, the live zones (they reach the right edge) and the labels (final positions).
// Left corners: the oldest visible candles and the zones drawn there
string pos = panelPosTV
if panelAvoid and not na(visHi) and visHi > visLo and not na(rgtHi) and not na(lftHi)
bool lastIn = visR >= time
float recHi = high
float recLo = low
if bar_index >= 4
for b = 1 to 4
recHi := math.max(recHi, high[b])
recLo := math.min(recLo, low[b])
float zHi = visHi
float zLo = visLo
if zones.size() > 0
for i = 0 to zones.size() - 1
z = zones.get(i)
if z.touches >= minTouches and box.get_left(z.bx) <= nz(visRB, bar_index) and box.get_right(z.bx) >= nz(visLB, 0)
zHi := math.max(zHi, z.top)
zLo := math.min(zLo, z.bottom)
float rowP = panelSize == "Small" ? 0.028 : 0.035
float lblP = labelSize == "Small" ? 0.06 : labelSize == "Large" ? 0.11 : 0.08 // two-line label, part of the pane
array<float> cost = array.new_float(4, 0.0)
for w = 0 to 1
float hiW = w == 0 ? visHi : zHi
float loW = w == 0 ? visLo : zLo
float spW = (hiW - loW) / 0.82
hiW += spW * 0.10
loW -= spW * 0.08
// Corners: 0 top right, 1 bottom right, 2 top left, 3 bottom left. The band of the panel includes its
// empty row (legend above it at the top left, logo or round button under it at the bottom)
for cn = 0 to 3
bool topC = cn % 2 == 0
bool rgtC = cn < 2
float ext = ((nRows + 1) * rowP + (cn == 1 ? ICON_PCT : cn == 2 ? LEGEND_PCT : cn == 3 ? LOGO_PCT : 0.0) / 100) * spW
float bT = topC ? hiW : loW + ext
float bB = topC ? hiW - ext : loW
float c = 20.0 * math.max(math.min(bT, rgtC ? rgtHi : lftHi) - math.max(bB, rgtC ? rgtLo : lftLo), 0.0) / ext
if rgtC and lastIn and bB < recHi + spW * 0.05 and bT > recLo - spW * 0.05
c += 100.0
if zones.size() > 0
for i = 0 to zones.size() - 1
z = zones.get(i)
if z.touches < minTouches
continue
string tx = label.get_text(z.lb)
if rgtC and lastIn and showLabels and tx != ""
float lh = lblP * spW * (str.contains(tx, "\n") ? 0.5 : 0.3) // half the label height
float ly = label.get_y(z.lb)
if bB < ly + lh and bT > ly - lh
c += 100.0
int xl = box.get_left(z.bx)
int xr = z.state == 2 ? box.get_right(z.bx) : bar_index
bool onSide = rgtC ? (z.state != 2 and lastIn) or (z.state == 2 and not na(rgtSB) and xr >= rgtSB) : not na(lftEB) and xl <= lftEB and xr >= nz(visLB, xl)
if onSide
c += 5.0 * math.max(math.min(bT, z.top) - math.max(bB, z.bottom), 0.0) / ext
cost.set(cn, cost.get(cn) + c)
int pi = panelPos == "Top Right" ? 0 : panelPos == "Bottom Right" ? 1 : panelPos == "Top Left" ? 2 : 3
// Corners tried in order: the chosen one, the other one on the same side, then the other side
array<int> tryOrd = array.from(pi, pi % 2 == 0 ? pi + 1 : pi - 1, (pi + 2) % 4, pi % 2 == 0 ? (pi + 3) % 4 : (pi + 1) % 4)
int cs = -1
for k = 0 to 3
if cs < 0 and cost.get(tryOrd.get(k)) <= 1.0
cs := tryOrd.get(k)
if cs < 0
cs := pi
for k = 1 to 3
if cost.get(tryOrd.get(k)) < cost.get(cs)
cs := tryOrd.get(k)
pos := cs == 0 ? position.top_right : cs == 1 ? position.bottom_right : cs == 2 ? position.top_left : position.bottom_left
// Rows: top left = empty row 0 under the TradingView legend, then the panel from row 1; other corners = the panel
// from row 0, plus an empty row under it in the bottom corners (Full: 9 rows + spacer = 10; Compact: 5 + spacer)
bool atTopLeft = pos == position.top_left
bool atBottom = pos == position.bottom_left or pos == position.bottom_right
int r0 = atTopLeft ? 1 : 0
int rFoot = r0 + nRows - 1
if atTopLeft
table.cell(panel, 0, 0, "", height = LEGEND_PCT)
table.merge_cells(panel, 0, 0, 3, 0)
table.cell(panel, 0, r0, "EDO S/R ZONES", text_color = textCol, bgcolor = headerBg, text_size = panSizeTxt)
table.merge_cells(panel, 0, r0, 3, r0)
if full
table.cell(panel, 0, r0 + 1, "Active", text_color = cellTxt, bgcolor = cellBg, text_size = panSizeTxt)
table.cell(panel, 1, r0 + 1, str.tostring(activeCount), text_color = textCol, bgcolor = cellBg, text_size = panSizeTxt)
table.cell(panel, 2, r0 + 1, "Tested", text_color = cellTxt, bgcolor = cellBg, text_size = panSizeTxt)
table.cell(panel, 3, r0 + 1, str.tostring(testedCount), text_color = #f5a623, bgcolor = cellBg, text_size = panSizeTxt)
table.cell(panel, 0, r0 + 2, "Broken", text_color = cellTxt, bgcolor = cellBg, text_size = panSizeTxt)
table.cell(panel, 1, r0 + 2, str.tostring(brokenCount), text_color = #e53935, bgcolor = cellBg, text_size = panSizeTxt)
table.cell(panel, 2, r0 + 2, "Zones", text_color = cellTxt, bgcolor = cellBg, text_size = panSizeTxt)
table.cell(panel, 3, r0 + 2, str.tostring(activeCount + testedCount + brokenCount), text_color = textCol, bgcolor = cellBg, text_size = panSizeTxt)
table.cell(panel, 0, r0 + 3, "NEAREST RESISTANCE", text_color = color.new(resCol, 0), bgcolor = subHeaderBg, text_size = panSizeTxt)
table.merge_cells(panel, 0, r0 + 3, 3, r0 + 3)
table.cell(panel, 0, r0 + 4, rPrice, text_color = color.new(resCol, 0), bgcolor = cellBg, text_size = panSizeTxt)
table.merge_cells(panel, 0, r0 + 4, 1, r0 + 4)
table.cell(panel, 2, r0 + 4, rDist, text_color = numTxt, bgcolor = cellBg, text_size = panSizeTxt)
table.cell(panel, 3, r0 + 4, rScore, text_color = textCol, bgcolor = cellBg, text_size = panSizeTxt)
table.cell(panel, 0, r0 + 5, "NEAREST SUPPORT", text_color = color.new(supCol, 0), bgcolor = subHeaderBg, text_size = panSizeTxt)
table.merge_cells(panel, 0, r0 + 5, 3, r0 + 5)
table.cell(panel, 0, r0 + 6, sPrice, text_color = color.new(supCol, 0), bgcolor = cellBg, text_size = panSizeTxt)
table.merge_cells(panel, 0, r0 + 6, 1, r0 + 6)
table.cell(panel, 2, r0 + 6, sDist, text_color = numTxt, bgcolor = cellBg, text_size = panSizeTxt)
table.cell(panel, 3, r0 + 6, sScore, text_color = textCol, bgcolor = cellBg, text_size = panSizeTxt)
table.cell(panel, 0, r0 + 7, "Last event", text_color = cellTxt, bgcolor = cellBg, text_size = panSizeTxt)
table.cell(panel, 1, r0 + 7, evRow, text_color = evColor(lastEvC), bgcolor = cellBg, text_size = panSizeTxt)
table.merge_cells(panel, 1, r0 + 7, 3, r0 + 7)
table.cell(panel, 0, rFoot, "Score 0-100 = touches + time held + volume − role changes", text_color = numTxt, bgcolor = subHeaderBg, text_size = panSizeTxt)
table.merge_cells(panel, 0, rFoot, 3, rFoot)
else
table.cell(panel, 0, r0 + 1, "Resistance", text_color = cellTxt, bgcolor = cellBg, text_size = panSizeTxt)
table.cell(panel, 1, r0 + 1, rPrice + (na(nearR) ? "" : " · " + rDist), text_color = color.new(resCol, 0), bgcolor = cellBg, text_size = panSizeTxt)
table.merge_cells(panel, 1, r0 + 1, 3, r0 + 1)
table.cell(panel, 0, r0 + 2, "Support", text_color = cellTxt, bgcolor = cellBg, text_size = panSizeTxt)
table.cell(panel, 1, r0 + 2, sPrice + (na(nearS) ? "" : " · " + sDist), text_color = color.new(supCol, 0), bgcolor = cellBg, text_size = panSizeTxt)
table.merge_cells(panel, 1, r0 + 2, 3, r0 + 2)
table.cell(panel, 0, r0 + 3, "Last event", text_color = cellTxt, bgcolor = cellBg, text_size = panSizeTxt)
table.cell(panel, 1, r0 + 3, evRow, text_color = evColor(lastEvC), bgcolor = cellBg, text_size = panSizeTxt)
table.merge_cells(panel, 1, r0 + 3, 3, r0 + 3)
table.cell(panel, 0, rFoot, "Closed bars · context, not a signal", text_color = numTxt, bgcolor = subHeaderBg, text_size = panSizeTxt)
table.merge_cells(panel, 0, rFoot, 3, rFoot)
if atBottom and rFoot < 9
table.cell(panel, 0, rFoot + 1, "", height = pos == position.bottom_left ? LOGO_PCT : ICON_PCT)
table.merge_cells(panel, 0, rFoot + 1, 3, rFoot + 1)
// With an empty row the outer frame is hidden so it does not draw a box around the legend, the logo or the button
table.set_frame_width(panel, atBottom or atTopLeft ? 0 : 1)
table.set_position(panel, pos)
// ================== MARKERS ==================
plotshape(mRejS, "Support rejection", shape.triangleup, location.belowbar, supCol, size = size.tiny)
plotshape(mRejR, "Resistance rejection", shape.triangledown, location.abovebar, resCol, size = size.tiny)
plotshape(mRuv, "Retest up · high volume", shape.diamond, location.belowbar, supCol, size = size.small)
plotshape(mRul, "Retest up · low volume", shape.diamond, location.belowbar, color.new(color.gray, 20), size = size.tiny)
plotshape(mRdv, "Retest down · high volume", shape.diamond, location.abovebar, resCol, size = size.small)
plotshape(mRdl, "Retest down · low volume", shape.diamond, location.abovebar, color.new(color.gray, 20), size = size.tiny)
// ================== ALERTS ==================
alertcondition(newZone, "New zone", "Edo S/R Zones — New support/resistance zone confirmed on {{ticker}}")
alertcondition(reactivated, "Zone reactivated", "Edo S/R Zones — Broken zone reactivated from the other side on {{ticker}}")
alertcondition(testedRes, "Resistance tested", "Edo S/R Zones — Resistance zone tested and held on {{ticker}}")
alertcondition(testedSup, "Support tested", "Edo S/R Zones — Support zone tested and held on {{ticker}}")
alertcondition(brokenRes, "Resistance broken", "Edo S/R Zones — Resistance zone broken on {{ticker}}")
alertcondition(brokenSup, "Support broken", "Edo S/R Zones — Support zone broken on {{ticker}}")
alertcondition(rejSup, "Support rejection", "Edo S/R Zones — Price rejected one of the nearest support zones on {{ticker}}")
alertcondition(rejRes, "Resistance rejection", "Edo S/R Zones — Price rejected one of the nearest resistance zones on {{ticker}}")
alertcondition(retestUpVol or retestDnVol, "Retest after break · high volume", "Edo S/R Zones — A broken zone was retested from its new side on high volume on {{ticker}}")
alertcondition(retestUpLow or retestDnLow, "Retest after break · low volume", "Edo S/R Zones — A broken zone was retested from its new side on low volume on {{ticker}}")