STRYK: WICK LIQUIDITY

Es-Sniper · study · 770 行 · 点赞 33 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

// =============================================================================
// STRYK: WICK LIQUIDITY v1.4 (STRYK:WL) — ES / MES futures (any symbol), America/Chicago
// v1.4: pro design + full customization — 3-column status card (dot · key · value) with header, frame, borders and
//       every table colour as a setting; target line width, broken-cluster line style, wick-mark size and cluster-zone
//       border are settings; research row and status dots get master switches. No calculation changes.
// v1.3.1: placebo test of the break ladder added to the wording — broken wick clusters run further than plain highs /
//       lows (T1 73 % vs 66 %, T2 ≈ 52 % vs 44 %, both halves); the return and the retest are no different.
// v1.3: review fixes — two clocks (cluster-timeframe candles for every window, chart bars only for drawing), wick
//       origin and time taken from the measured candle (no deep time[] lookups), finished-cycle drawings kept to a set
//       number, open cycles never silently dropped (counted as censored), T1–T4 sorted, sample sizes and pending cycles
//       in the table, wording says 'historical frequency', not an entry signal.
// Research note (data through Nov 13 2026; 5-minute bars, last 60 days, 9 futures, two halves): price came back to a swept wick level within one
// hour 92 % of the time. From the return, trading the level either way (±0.5 ATR, race from the next candle) was
// about a coin flip and negative after costs. The sweep is a location, not an entry.
// No repaint: every wick, cluster, sweep and follow-up is decided on a confirmed (closed) candle.
// =============================================================================
//@version=6
indicator("STRYK: WICK LIQUIDITY", shorttitle = "STRYK:WL", overlay = true, max_boxes_count = 500, max_lines_count = 500, max_labels_count = 500)
 
// ─────────────────────────────── types ───────────────────────────────
type Lv
    float px
    float lo
    int   side
    int   cnt
    int   b0
    int   st = 0
    int   sb
    int   rb
    float a
    int   res = 0
    int   t0
    int   tS
    int   tR
    box   bx
    line  ln
    label lb
    bool  br = false
    int   bc
    int   bcC
    int   sbC
    int   rbC
 
type St
    int n   = 0
    int rt  = 0
    int bk  = 0
    int on  = 0
    int nC  = 0
    int rtC = 0
    int bkC = 0
    int onC = 0
    Lv  lv
    int nt  = 0
    int ntC = 0
 
// v1.2 break engine: one cycle per broken cluster (lv = the cluster, dir = 1 broke up / -1 broke down)
type Rn
    int   id
    float lv
    int   dir
    int   cnt
    int   b0
    int   t0
    float a
    float mx = 0
    int   hit = 0
    int   st = 1
    int   tRet
    bool  ret = false
    array<int>   rk
    line  ln
    array<line>  tl
    array<label> tg
    label rl
    int   b0C
 
type Ts
    int nB  = 0
    int nB0 = 0
    int nid = 0
    array<int> nR
    array<int> nT
    int nCen = 0
 
type Fc
    Rn  r
    int fid = -1
 
// ─────────────────────────────── A · master switch ───────────────────────────────
GA = "A · MASTER SWITCH"
wkOn = input.bool(true, "Large wick marks", group = GA,
     tooltip = "LARGE WICK MARKS (default on): a tiny triangle above a candle with a large upper wick and below a candle with a large lower wick. A wick is large when it is at least 'Large wick' × ATR long and at least 'Wick ≥ body' × the candle body (section B). Marked only after the candle closes. Off = no marks; wicks are still detected for clusters and levels.")
clOn = input.bool(true, "Cluster zones", group = GA,
     tooltip = "CLUSTER ZONES (default on): when two or more large wick tips land within the cluster tolerance of each other inside the cluster window, they form a short-term liquidity pool. Drawn as a shaded zone (the spread of the wick tips) with a solid line at the outermost tip and a ×n tag (how many wicks). Off = clusters are not drawn or signalled.")
sgOn = input.bool(true, "Single large-wick levels", group = GA,
     tooltip = "SINGLE LEVELS (default on): one very large wick (at least 'Single-wick level' × ATR, section B) also becomes a level on its own — a dotted line at its tip. If more wicks join it later it turns into a cluster. Off = only clusters become levels.")
swOn = input.bool(true, "Sweep signals", group = GA,
     tooltip = "SWEEP SIGNALS (default on): ⚑ when price takes a cluster, ✕ when it takes a single level — above the candle for a level above, below for a level below. Hover the mark for the level, wick count and time. 'Taken' follows the Sweep setting in section C (trade through by default). The level then stops extending and turns to the swept colour. Off = no marks; sweeps are still tracked for the table and alerts.")
rtOn = input.bool(true, "Return marks", group = GA,
     tooltip = "RETURN MARKS (default on): ↺ on the first candle that trades back to a swept level within the return window (section C). Historically about 92 % — but plain highs / lows came back about as often, so this is not a wick-specific edge. Hover for the time and what followed. Off = no marks; returns are still counted in the table.")
tgOn = input.bool(true, "Level tags (×n)", group = GA,
     tooltip = "LEVEL TAGS (default on): a small tag at the start of each level — ×n for a cluster of n wicks, ×1 for a single level. Hover for the price, zone and time it formed. Off = no tags.")
kpOn = input.bool(true, "Keep swept levels on the chart", group = GA,
     tooltip = "KEEP SWEPT LEVELS (default on): a swept level stays on the chart, stopped at the sweep candle and drawn in the swept colour, so the history is visible. Off = a level is deleted once its follow-up is finished.")
ssOn = input.bool(false, "Reset at the 17:00 CT open", group = GA,
     tooltip = "SESSION RESET (default off): at the 17:00 CT Globex open every untouched level and stored wick is cleared, so each session starts clean. Off = levels live until they are swept or expire (section B).")
tbOn = input.bool(true, "Table", group = GA,
     tooltip = "TABLE (default on): nearest untouched level above and below, the last sweep and its follow-up, and the tally on the loaded chart (returned %, back through first %, onward first %). Layout and position in section F.")
alOn = input.bool(true, "Alerts (alert() messages)", group = GA,
     tooltip = "ALERTS (default on): one alert() message per candle close when a cluster or level is swept, with the side, price and wick count. Create the alert with 'Any alert() function call'. The two alertconditions ('WL · Sweep above' / 'WL · Sweep below') work either way. Off = no alert() messages.")
 
// ─────────────────────────────── B · detection ───────────────────────────────
GB = "B · Wick + cluster detection"
atrLen = input.int(14, "ATR length", minval = 1, maxval = 200, group = GB,
     tooltip = "ATR LENGTH (default 14): every size in this indicator is measured in ATR of the chart timeframe, using the previous closed candle's ATR so a candle never measures itself. 14 is the standard; longer = steadier sizes.")
kW = input.float(0.35, "Large wick ≥ (× ATR)", minval = 0.05, maxval = 5, step = 0.05, group = GB,
     tooltip = "LARGE WICK (default 0.35 × ATR): the smallest wick that counts. This is the size used in testing. Lower = more wicks and more clusters (noisier); higher = only big rejections.")
kB = input.float(1.0, "Wick ≥ body ×", minval = 0, maxval = 10, step = 0.1, group = GB,
     tooltip = "WICK VS BODY (default 1.0): the wick must also be at least this many times the candle body, so a big candle with a modest wick is not counted. 0 = ignore the body.")
kS = input.float(0.6, "Single-wick level ≥ (× ATR)", minval = 0.1, maxval = 5, step = 0.05, group = GB,
     tooltip = "SINGLE-WICK LEVEL (default 0.6 × ATR): a wick at least this long becomes a level on its own, without a cluster. Untested setting — a starting value. Higher = fewer single levels.")
tolK = input.float(0.15, "Cluster tolerance (× ATR)", minval = 0.01, maxval = 2, step = 0.01, group = GB,
     tooltip = "CLUSTER TOLERANCE (default 0.15 × ATR): wick tips within this distance of each other belong to the same pool. 0.15 was used in testing. Wider = bigger, fewer pools.")
winN = input.int(36, "Cluster window (bars)", minval = 2, maxval = 500, group = GB,
     tooltip = "CLUSTER WINDOW (default 36 bars = 3 hours on 5 minutes): how far back a new wick looks for others to cluster with. Older wicks are forgotten.")
minC = input.int(2, "Wicks needed for a cluster", minval = 2, maxval = 10, group = GB,
     tooltip = "WICKS PER CLUSTER (default 2): how many large wick tips make a cluster. 2 was tested. 3+ = fewer, stronger-looking pools (untested).")
expN = input.int(288, "Level expires after (bars)", minval = 10, maxval = 5000, group = GB,
     tooltip = "EXPIRY (default 288 bars = 1 day on 5 minutes): an untouched level older than this is removed. Raise it to keep older pools.")
maxN = input.int(15, "Max untouched levels per side", minval = 1, maxval = 60, group = GB,
     tooltip = "LEVEL CAP (default 15 per side): when more untouched levels exist on one side, the oldest is removed first. Keeps the chart readable and the script fast.")
 
// ─────────────────────────────── C · sweep + follow-up ───────────────────────────────
GC = "C · Sweep + follow-up"
swMd = input.string("Trade through", "Sweep =", options = ["Trade through", "Close through"], group = GC,
     tooltip = "SWEEP (default Trade through): Trade through = a candle trades at least 'buffer' ticks past the level (the tested rule). Close through = a candle must close past it (fewer, later signals, untested).")
bufT = input.int(1, "Sweep buffer (ticks)", minval = 0, maxval = 50, group = GC,
     tooltip = "SWEEP BUFFER (default 1 tick): how far past the level price must go to count. 1 tick was tested. More = fewer marginal sweeps.")
rtN = input.int(12, "Return window (bars)", minval = 1, maxval = 200, group = GC,
     tooltip = "RETURN WINDOW (default 12 bars = 1 hour on 5 minutes): after a sweep, the indicator watches this long for price to trade back to the level (↺). Tested: about 92 % returned within 1 hour.")
mvK = input.float(0.5, "Follow-up distance (× ATR)", minval = 0.1, maxval = 5, step = 0.05, group = GC,
     tooltip = "FOLLOW-UP (default 0.5 × ATR): after the return, which comes first — 0.5 ATR back through the level (the sweep failed) or 0.5 ATR onward past it (the sweep continued)? The race starts on the candle after the return; a candle that reaches both sides counts as 'neither'. Tested this way on 9 futures: a trade at the level with this stop and target won 45–47 % — no edge either way.")
hzN = input.int(48, "Follow-up max bars", minval = 1, maxval = 500, group = GC,
     tooltip = "FOLLOW-UP LIMIT (default 48 bars = 4 hours on 5 minutes): if neither side is reached in this many bars after the return, the follow-up ends as 'neither'.")
 
// ─────────────────────────────── D · visuals: wicks + levels ───────────────────────────────
GD = "D · Visuals: wicks + levels"
cWU = input.color(#ff2bd6, "Upper wick mark", group = GD, inline = "d1",
     tooltip = "WICK MARK COLOURS (defaults magenta above / cyan below): colour of the tiny triangle on a large upper wick (above the candle) and on a large lower wick (below). Shape and size can also be changed in the Style tab.")
cWD = input.color(#00e5ff, "lower", group = GD, inline = "d1",
     tooltip = "Colour of the tiny triangle under a candle with a large lower wick (default cyan).")
cLU = input.color(#ff2bd6, "Level above", group = GD, inline = "d2",
     tooltip = "LEVEL COLOURS (defaults magenta above / cyan below): colour of untouched clusters and levels built from upper wicks (above price) and from lower wicks (below price).")
cLD = input.color(#00e5ff, "below", group = GD, inline = "d2",
     tooltip = "Colour of untouched clusters and levels built from lower wicks (default cyan).")
cSw = input.color(#787b86, "Swept level", group = GD, inline = "d3",
     tooltip = "SWEPT COLOUR (default grey): a level turns this colour and stops extending at the sweep candle.")
swSt = input.string("Dashed", "style", options = ["Solid", "Dashed", "Dotted"], group = GD, inline = "d3",
     tooltip = "Line style of a swept level (default Dashed).")
zTr = input.int(85, "Cluster zone transparency", minval = 0, maxval = 100, group = GD,
     tooltip = "ZONE TRANSPARENCY (default 85): how see-through the shaded cluster zone is. 100 = no shading, line only.")
lwC = input.int(2, "Cluster line width", minval = 1, maxval = 6, group = GD, inline = "d4",
     tooltip = "CLUSTER LINE (default width 2, Solid): the line at the outermost wick tip of a cluster.")
stC = input.string("Solid", "style", options = ["Solid", "Dashed", "Dotted"], group = GD, inline = "d4",
     tooltip = "Line style of an untouched cluster (default Solid).")
lwS = input.int(1, "Single level width", minval = 1, maxval = 6, group = GD, inline = "d5",
     tooltip = "SINGLE LEVEL LINE (default width 1, Dotted): the line at a single large wick's tip.")
stS = input.string("Dotted", "style", options = ["Solid", "Dashed", "Dotted"], group = GD, inline = "d5",
     tooltip = "Line style of an untouched single level (default Dotted).")
tgSz = input.string("Tiny", "Tag size", options = ["Tiny", "Small", "Normal"], group = GD,
     tooltip = "TAG SIZE (default Tiny): size of the ×n tags at the start of each level.")
 
// ─────────────────────────────── E · visuals: signals ───────────────────────────────
GE = "E · Visuals: signals"
cSU = input.color(#ffd600, "Sweep above", group = GE, inline = "e1",
     tooltip = "SWEEP MARK COLOURS (default gold both sides): colour of ⚑ / ✕ when a level above is swept (mark above the candle) and when a level below is swept (mark below the candle).")
cSD = input.color(#ffd600, "below", group = GE, inline = "e1",
     tooltip = "Colour of the sweep mark when a level below is swept (default gold).")
cRt = input.color(#9aa4b2, "Return mark", group = GE,
     tooltip = "RETURN MARK COLOUR (default grey): colour of ↺ when price trades back to a swept level.")
sgSz = input.string("Small", "Signal size", options = ["Tiny", "Small", "Normal"], group = GE,
     tooltip = "SIGNAL SIZE (default Small): size of ⚑, ✕ and ↺. Every mark shows its full read on hover.")
 
// ─────────────────────────────── F · table ───────────────────────────────
GF = "F · Table"
tbLay = input.string("Full", "Layout", options = ["Full", "Mobile"], group = GF,
     tooltip = "LAYOUT (default Full): Full = every row with full wording. Mobile = four short rows (UP, DN, LAST, HIST) for a phone screen.")
tbPos = input.string("Top right", "Position", options = ["Top right", "Top left", "Bottom right", "Bottom left", "Middle right"], group = GF,
     tooltip = "TABLE POSITION (default Top right).")
tbSz = input.string("Small", "Text size", options = ["Tiny", "Small", "Normal"], group = GF,
     tooltip = "TABLE TEXT SIZE (default Small).")
cTb = input.color(#131722EB, "Background", group = GF,
     tooltip = "TABLE BACKGROUND (default near-black, 8 % transparent). Solid looks best on mobile.")
 
// ─────────────────────────────── G · break + target engine (v1.2) ───────────────────────────────
brOn = input.bool(true, "Cluster break engine (close → targets → return)", group = GA,
     tooltip = "BREAK ENGINE (default on) — a measurement cycle, not an entry signal: when a candle CLOSES past a wick cluster (a full close, not just a wick), a cycle starts: the broken cluster line, ATR targets T1–T4 with their reach odds, ✓ on each target hit, then a return tracker in the table (odds of coming back, % of the way back, points to go) and ✓ BACK when price touches the cluster again. Then it waits for the next cluster. Research (1h and 5m bars, 9 futures, Jul 2024 – Nov 2026, both halves): T1 0.5 ATR reached 73 %, T2 1 ATR 50 %, T3 1.5 ATR 37 %, T4 2 ATR 29 %; back to the cluster within 48 bars after T1 87 %, after T2 82 %, after T3 76 %, after T4 70 %. These are historical frequencies (≈ 8,200 breaks on 1h from Jul 2024 and ≈ 8,600 on 5m over 60 days, data through Nov 13 2026), not forecasts; against plain highs / lows (placebo) broken the same way, wick clusters ran further — T1 73 % vs 66 %, T2 ≈ 52 % vs 44 %, T3 ≈ 39 % vs 33 %, T4 ≈ 31 % vs 26 %, in both halves — while the return to the level and the retest (hold vs fail ≈ 45 / 43 %) were no different. Filters tested on top (3+ wicks, wick ≥ 55 % of the candle, volume ≥ 1.5× median) added nothing. Rules: the break candle's extreme counts toward the run; a candle that touches the cluster ends the cycle as a return and does not extend the run (order inside a candle is unknown — return first is a convention). Only the newest cycle is drawn; the table's chart odds include every cycle in the background, finished ones only, with pending ones shown. Off = no cycle, no target lines, no break rows.")
htfTF = input.string("60", "Cluster timeframe", options = ["Chart", "15", "30", "60", "120", "240", "D"], group = GA,
     tooltip = "CLUSTER TIMEFRAME (default 60 = 1 hour): the timeframe whose candles are read for large wicks and clusters, even on a 5-minute chart. Only completed candles are used (no repaint): a candle is read when the first chart candle of the next period closes, so a 1-hour level appears about 5 minutes after the hour on a 5-minute chart. Wick size, cluster tolerance and targets use that timeframe's ATR. Every window setting (cluster window, expiry, return window, follow-up, return-odds window, give-up) counts candles of this timeframe; sweeps, returns and target touches are still checked on every chart candle. D = the exchange daily candle (17:00–16:00 CT for CME futures), not a calendar day. Chart = the chart's own candles; a timeframe at or below the chart's, or not a whole multiple of it, also acts as Chart.")
GG = "G · Break + target engine"
brMd = input.string("Cluster-timeframe close", "Break confirmed on", options = ["Cluster-timeframe close", "Chart close"], group = GG,
     tooltip = "BREAK CONFIRMATION (default Cluster-timeframe close): a cycle starts when a candle of the cluster timeframe closes past the cluster — the tested rule. Chart close = the first chart candle that closes past it (earlier, more breaks that fail, untested).")
brSg = input.bool(false, "Single-wick levels can start a cycle", group = GG,
     tooltip = "SINGLE LEVELS (default off): off = only clusters (2+ wicks) start a cycle, as tested. On = a single large-wick level broken on a close also starts one (untested).")
t1K = input.float(0.5, "T1 (× ATR)", minval = 0.1, maxval = 10, step = 0.05, group = GG, inline = "g1",
     tooltip = "TARGET T1 (default 0.5 × ATR past the cluster, reached 73 % historically). The ATR is the cluster-timeframe ATR on the candle before the measured one. T1–T4 are sorted smallest to largest, so their order always matches the numbering.")
t2K = input.float(1.0, "T2", minval = 0.1, maxval = 10, step = 0.05, group = GG, inline = "g1",
     tooltip = "TARGET T2 (default 1.0 × ATR, reached about 50 %).")
t3K = input.float(1.5, "T3", minval = 0.1, maxval = 10, step = 0.05, group = GG, inline = "g2",
     tooltip = "TARGET T3 (default 1.5 × ATR, reached about 37 %).")
t4K = input.float(2.0, "T4", minval = 0.1, maxval = 10, step = 0.05, group = GG, inline = "g2",
     tooltip = "TARGET T4 (default 2.0 × ATR, reached about 29 % historically).")
rwN = input.int(48, "Return odds window (bars after a target)", minval = 1, maxval = 500, group = GG,
     tooltip = "RETURN WINDOW (default 48 bars): the return odds answer 'after reaching this target, how often did price trade back to the cluster within this many bars'. The research odds in the table are for 48 bars; change it and only the chart's own odds follow.")
rxN = input.int(240, "Give up after (bars)", minval = 10, maxval = 2000, group = GG,
     tooltip = "GIVE UP (default 240 bars): a cycle that has not returned to the cluster after this many bars (and after the return window of its last target) ends as 'no return' and the engine waits for the next cluster.")
minN = input.int(30, "Chart odds need at least (cycles)", minval = 5, maxval = 500, group = GG,
     tooltip = "MINIMUM SAMPLE (default 30): the table uses the loaded chart's own odds once at least this many finished cycles (or target hits) back them; below that it shows the research number marked (r).")
cBr = input.color(#ffd600, "Broken cluster line", group = GG, inline = "g3",
     tooltip = "BROKEN CLUSTER LINE (default gold, width 2): the cluster that broke on a close — the level price is expected to come back to.")
brW = input.int(2, "width", minval = 1, maxval = 6, group = GG, inline = "g3",
     tooltip = "Width of the broken cluster line (default 2).")
cTg = input.color(#b388ff, "Target lines", group = GG, inline = "g4",
     tooltip = "TARGET LINES (default purple, Dashed): T1–T4, each labelled with its price and reach odds.")
tgSt = input.string("Dashed", "style", options = ["Solid", "Dashed", "Dotted"], group = GG, inline = "g4",
     tooltip = "Line style of the target lines (default Dashed).")
cOk = input.color(#00e676, "✓ hit colour", group = GG,
     tooltip = "HIT COLOUR (default green): a target line and label turn this colour when hit, and ✓ BACK is drawn in it when price returns to the cluster.")
kpN = input.int(10, "Finished cycles kept on the chart", minval = 0, maxval = 40, group = GG,
     tooltip = "CYCLE HISTORY (default 10): how many finished cycles keep their cluster line, targets and ✓ BACK on the chart. Older ones are deleted, which keeps every drawing well inside TradingView's 500 lines / labels. 0 = only the live cycle. With 'Keep swept levels' off, a finished cycle's lines go at once and only its ✓ BACK mark stays until it ages out.")
tgW = input.int(1, "Target line width", minval = 1, maxval = 6, group = GG, inline = "g5",
     tooltip = "TARGET LINE WIDTH (default 1): thickness of the T1–T4 lines. Keep them thinner than the broken-cluster line so the cluster stays the main level on the chart.")
brSt = input.string("Solid", "Broken cluster style", options = ["Solid", "Dashed", "Dotted"], group = GG, inline = "g6",
     tooltip = "BROKEN CLUSTER LINE STYLE (default Solid): line style of the gold cluster line during a cycle. Its colour and width are set above.")
rsOn = input.bool(true, "Research row in the table", group = GA,
     tooltip = "RESEARCH ROW (default on): the last table row summarises what the history test found (wick clusters run further than plain levels; the return and the retest do not differ). Off = hide it to save space; the tooltips keep the same facts.")
dtOn = input.bool(true, "Status dots in the table", group = GA,
     tooltip = "STATUS DOTS (default on): a coloured ● at the start of each table row in that row's colour, so the state reads at a glance (cyan / magenta = side, gold = break, green = target or return, grey = idle). Off = text only.")
GH = "H · Table design"
cHd = input.color(#00e5ff, "Header colour", group = GH, inline = "h1",
     tooltip = "HEADER COLOUR (default cyan): colour of the table's title bar. Its transparency is set next to it.")
hdTr = input.int(80, "transparency", minval = 0, maxval = 100, group = GH, inline = "h1",
     tooltip = "HEADER TRANSPARENCY (default 80): 0 = solid header bar, 100 = no bar.")
cHt = input.color(#d1d4dc, "Header text", group = GH, inline = "h2",
     tooltip = "HEADER TEXT COLOUR (default light grey): the title and timeframe text in the header bar.")
cKy = input.color(#9aa4b2, "Row names", group = GH, inline = "h2",
     tooltip = "ROW NAME COLOUR (default grey): the left-hand names (Pool above, Targets, Return …).")
cVl = input.color(#d1d4dc, "Neutral values", group = GH, inline = "h3",
     tooltip = "NEUTRAL VALUE COLOUR (default light grey): values that have no side or state colour, such as the tally rows.")
cMt = input.color(#787b86, "Muted values", group = GH, inline = "h3",
     tooltip = "MUTED COLOUR (default grey): idle or empty states (waiting, none untouched) and the research row.")
cAm = input.color(#ffb000, "Back-through result", group = GH, inline = "h4",
     tooltip = "BACK-THROUGH COLOUR (default amber): the last-sweep row when the follow-up ended back through the level.")
cFr = input.color(#2a2e39, "Frame / borders", group = GH, inline = "h4",
     tooltip = "FRAME COLOUR (default dark grey): the table's outer frame and the lines between cells.")
frW = input.int(1, "Frame width", minval = 0, maxval = 5, group = GH, inline = "h5",
     tooltip = "FRAME WIDTH (default 1): outer frame thickness. 0 = no frame.")
bdW = input.int(0, "Cell borders", minval = 0, maxval = 3, group = GH, inline = "h5",
     tooltip = "CELL BORDERS (default 0): lines between cells. 0 = a clean card with no grid; 1 = a light grid.")
wmSz = input.string("Tiny", "Higher-TF wick mark size", options = ["Tiny", "Small", "Normal"], group = GD,
     tooltip = "HIGHER-TF WICK MARK SIZE (default Tiny): size of the ▼ / ▲ marks drawn at large wicks of the cluster timeframe. On the Chart setting the marks are plot shapes; change their size and shape in the Style tab.")
zBd = input.int(100, "Cluster zone border transparency", minval = 0, maxval = 100, group = GD,
     tooltip = "ZONE BORDER (default 100 = none): outline of the shaded cluster zone in the level colour. Lower it to outline the zone.")
 
// ─────────────────────────────── helpers ───────────────────────────────
string TZ = "America/Chicago"
f_sz(string s) =>
    s == "Tiny" ? size.tiny : s == "Small" ? size.small : size.normal
f_ls(string s) =>
    s == "Dashed" ? line.style_dashed : s == "Dotted" ? line.style_dotted : line.style_solid
f_tt(int t) =>
    na(t) ? "—" : str.format_time(t, "HH:mm", TZ)
f_p(float p) =>
    str.tostring(p, format.mintick)
f_pos(string s) =>
    s == "Top left" ? position.top_left : s == "Bottom right" ? position.bottom_right : s == "Bottom left" ? position.bottom_left : s == "Middle right" ? position.middle_right : position.top_right
f_pc(int a, int n) =>
    n > 0 ? str.tostring(math.round(a / n * 100)) + " %" : "—"
 
var array<Lv>    L   = array.new<Lv>()
var array<float> tpU = array.new<float>()
var array<int>   tbU = array.new<int>()
var array<float> tpD = array.new<float>()
var array<int>   tbD = array.new<int>()
var array<int>   txU = array.new<int>()
var array<int>   txD = array.new<int>()
var array<int>   ttU = array.new<int>()
var array<int>   ttD = array.new<int>()
var St ST = St.new()
 
// v1.2: cluster timeframe — completed candles only ([1] with lookahead on = the last closed candle, same on history and live)
string cTF = htfTF == "Chart" ? timeframe.period : htfTF
bool useH = htfTF != "Chart" and timeframe.in_seconds(cTF) > timeframe.in_seconds() and timeframe.in_seconds(cTF) % timeframe.in_seconds() == 0
[hO, hH, hL, hC, hA, hT] = request.security(syminfo.tickerid, cTF, [open[1], high[1], low[1], close[1], ta.atr(atrLen)[2], time[1]], lookahead = barmerge.lookahead_on)
bool tfc = timeframe.change(cTF)
bool hNew = useH and tfc
bool hProc = hNew and barstate.isconfirmed
var int hIdx = 0
var int hSB = 0
var int hPrevSB = 0
if hProc
    hIdx += 1
    hPrevSB := hSB
    hSB := bar_index
// v1.3: two clocks — every window counts candles of the cluster timeframe (hIdx), drawing positions use chart bars
int clk = useH ? hIdx : bar_index
array<float> TKS = array.from(t1K, t2K, t3K, t4K)
TKS.sort()
var array<Rn> FD = array.new<Rn>()
 
f_kill(Lv v) =>
    if not na(v.bx)
        v.bx.delete()
    if not na(v.ln)
        v.ln.delete()
    if not na(v.lb)
        v.lb.delete()
    true
 
// draw (or redraw) an untouched level
f_draw(Lv v) =>
    bool isC = v.cnt >= minC
    color c = v.side == 1 ? cLU : cLD
    float top = math.max(v.px, v.lo)
    float bot = math.min(v.px, v.lo)
    f_kill(v)
    if isC and zTr < 100
        v.bx := box.new(v.b0, top, bar_index, bot, border_color = color.new(c, zBd), bgcolor = color.new(c, zTr), extend = extend.right)
    v.ln := line.new(v.b0, v.px, bar_index, v.px, color = c, width = isC ? lwC : lwS, style = f_ls(isC ? stC : stS), extend = extend.right)
    if tgOn
        string tip = (isC ? "CLUSTER ×" + str.tostring(v.cnt) + " · " : "SINGLE WICK · ") + f_p(v.px) + (isC ? " · zone " + f_p(bot) + "–" + f_p(top) : "") + " · formed " + f_tt(v.t0)
        v.lb := label.new(v.b0, v.px, "×" + str.tostring(v.cnt), style = v.side == 1 ? label.style_label_down : label.style_label_up, color = color.new(c, 100), textcolor = c, size = f_sz(tgSz), tooltip = tip)
    true
 
// a new large wick: cluster it with recent tips, merge into an untouched level, or start a new level
f_wick(int side, float px, float wk, float a, array<float> tp, array<int> tbs, array<int> txs, array<int> tts, int ix, int bx, int tt) =>
    while tp.size() > 0 and (ix - tbs.first() > winN or tp.size() > 200)
        tp.shift()
        tbs.shift()
        txs.shift()
        tts.shift()
    int hits = 0
    float ext = px
    float edge = px
    int b0 = bx
    int t0 = tt
    if tp.size() > 0
        for i = 0 to tp.size() - 1
            float q = tp.get(i)
            if math.abs(q - px) <= tolK * a
                hits += 1
                ext := side == 1 ? math.max(ext, q) : math.min(ext, q)
                edge := side == 1 ? math.min(edge, q) : math.max(edge, q)
                b0 := math.min(b0, txs.get(i))
                t0 := math.min(t0, tts.get(i))
    tp.push(px)
    tbs.push(ix)
    txs.push(bx)
    tts.push(tt)
    Lv hitL = na
    if L.size() > 0
        for i = 0 to L.size() - 1
            Lv v = L.get(i)
            if v.side == side and v.st == 0 and math.abs(v.px - px) <= tolK * a
                hitL := v
                break
    if not na(hitL)
        hitL.cnt += 1
        hitL.px := side == 1 ? math.max(hitL.px, px) : math.min(hitL.px, px)
        hitL.lo := side == 1 ? math.min(hitL.lo, px) : math.max(hitL.lo, px)
        if (hitL.cnt >= minC and clOn) or (hitL.cnt < minC and sgOn)
            f_draw(hitL)
    else
        bool mkC = hits + 1 >= minC and clOn
        bool mkS = not mkC and sgOn and wk >= kS * a
        if mkC or mkS
            int x0 = mkC ? b0 : bx
            Lv v = Lv.new(mkC ? ext : px, mkC ? edge : px, side, mkC ? hits + 1 : 1, x0, 0, na, na, a, 0, mkC ? t0 : tt)
            v.bc := bar_index
            v.bcC := clk
            L.push(v)
            f_draw(v)
            // level cap: remove the oldest untouched level on this side
            int nS = 0
            int iOld = -1
            for i = 0 to L.size() - 1
                Lv w = L.get(i)
                if w.side == side and w.st == 0
                    nS += 1
                    iOld := iOld == -1 ? i : iOld
            if nS > maxN and iOld >= 0
                f_kill(L.get(iOld))
                L.remove(iOld)
    true
 
// stop a level's drawings at the sweep candle and recolour it
f_freeze(Lv v) =>
    if not na(v.ln)
        v.ln.set_extend(extend.none)
        v.ln.set_x2(bar_index)
        v.ln.set_color(cSw)
        v.ln.set_style(f_ls(swSt))
    if not na(v.bx)
        v.bx.set_extend(extend.none)
        v.bx.set_right(bar_index)
        v.bx.set_bgcolor(color.new(cSw, math.min(100, zTr + 5)))
    if not na(v.lb)
        v.lb.set_textcolor(cSw)
    true
 
// ─────────────────────────────── v1.2 break engine ───────────────────────────────
var array<Rn> RB = array.new<Rn>()
var Ts TS = Ts.new(0, 0, 0, array.new<int>(4, 0), array.new<int>(4, 0))
var Fc FC = Fc.new()
 
f_tk(int k) =>
    TKS.get(math.max(0, math.min(3, k - 1)))
f_rsR(int k) =>
    k == 1 ? 73 : k == 2 ? 50 : k == 3 ? 37 : 29
f_rsT(int k) =>
    k == 1 ? 87 : k == 2 ? 82 : k == 3 ? 76 : 70
f_pReach(int k) =>
    TS.nB >= minN ? str.tostring(math.round(TS.nR.get(k - 1) / TS.nB * 100)) + " % (n " + str.tostring(TS.nB) + ")" : str.tostring(f_rsR(k)) + " % (r)"
f_pRet(int k) =>
    int n = TS.nR.get(k - 1)
    n >= minN ? str.tostring(math.round(TS.nT.get(k - 1) / n * 100)) + " % (n " + str.tostring(n) + ")" : str.tostring(f_rsT(k)) + " % (r)"
f_bar(float p) =>
    int n = int(math.round(math.max(0.0, math.min(1.0, p)) * 10))
    (n > 0 ? str.repeat("▓", n) : "") + (n < 10 ? str.repeat("░", 10 - n) : "")
 
f_brDraw(Rn r) =>
    r.ln := line.new(r.b0, r.lv, bar_index, r.lv, color = cBr, width = brW, style = f_ls(brSt), extend = extend.right)
    for k = 1 to 4
        float p = r.lv + r.dir * f_tk(k) * r.a
        r.tl.push(line.new(r.b0, p, bar_index, p, color = cTg, width = tgW, style = f_ls(tgSt), extend = extend.right))
        r.tg.push(label.new(bar_index, p, "T" + str.tostring(k) + " " + f_p(p) + " · " + f_pReach(k), style = label.style_label_left, color = color.new(cTg, 100), textcolor = cTg, size = f_sz(tgSz)))
    true
 
// delete a cycle's drawings (lines and targets; the ✓ BACK mark too when wipeAll)
f_brWipe(Rn r, bool wipeAll) =>
    if not na(r.ln)
        r.ln.delete()
    if r.tl.size() > 0
        for k = 0 to r.tl.size() - 1
            r.tl.get(k).delete()
    if r.tg.size() > 0
        for k = 0 to r.tg.size() - 1
            r.tg.get(k).delete()
    r.tl.clear()
    r.tg.clear()
    if wipeAll and not na(r.rl)
        r.rl.delete()
    true
 
f_brEnd(Rn r) =>
    if not na(r.ln)
        r.ln.set_extend(extend.none)
        r.ln.set_x2(bar_index)
    if r.tl.size() > 0
        for k = 0 to r.tl.size() - 1
            line q = r.tl.get(k)
            q.set_extend(extend.none)
            q.set_x2(bar_index)
    if r.ret
        r.rl := label.new(bar_index, r.lv, "✓ BACK " + f_tt(time), yloc = r.dir == 1 ? yloc.belowbar : yloc.abovebar, style = label.style_none, textcolor = cOk, size = f_sz(sgSz), tooltip = "Back to the broken cluster " + f_p(r.lv) + " · " + f_tt(time) + " · best run " + str.tostring(r.mx, "#.##") + " ATR · targets hit " + str.tostring(r.hit) + "/4")
    if not kpOn
        f_brWipe(r, false)
    FD.push(r)
    while FD.size() > kpN
        f_brWipe(FD.shift(), true)
    true
 
f_brFin(Rn r) =>
    TS.nB += 1
    TS.nB0 += r.ret and r.hit == 0 ? 1 : 0
    if r.hit > 0
        for k = 1 to r.hit
            TS.nR.set(k - 1, TS.nR.get(k - 1) + 1)
            if r.ret and clk - r.rk.get(k - 1) <= rwN
                TS.nT.set(k - 1, TS.nT.get(k - 1) + 1)
    true
 
f_brNew(Lv v, float a) =>
    TS.nid += 1
    Rn r = Rn.new(id = TS.nid, lv = v.px, dir = v.side, cnt = v.cnt, b0 = bar_index, t0 = time, a = a, rk = array.new<int>(4, -1), tl = array.new<line>(), tg = array.new<label>(), b0C = clk)
    RB.push(r)
    // v1.3: never drop an open cycle silently — over 300 open cycles, the oldest non-live one is counted as censored
    if RB.size() > 300
        int iEv = -1
        for i = 0 to RB.size() - 1
            if RB.get(i).id != FC.fid
                iEv := i
                break
        if iEv >= 0
            TS.nCen += 1
            RB.remove(iEv)
    if na(FC.r) or FC.r.st == 3
        FC.r := r
        FC.fid := r.id
        f_brDraw(r)
    true
 
// every confirmed candle: run, targets, return, give-up for every open cycle; drawings only for the focus cycle
f_brStep() =>
    string m = ""
    int evR = 0
    if barstate.isconfirmed and RB.size() > 0
        for i = RB.size() - 1 to 0
            Rn r = RB.get(i)
            if r.st == 1
                bool isF = r.id == FC.fid
                bool back = bar_index > r.b0 and (r.dir == 1 ? low <= r.lv : high >= r.lv)
                if back
                    r.st := 3
                    r.ret := true
                    r.tRet := time
                    f_brFin(r)
                    if isF
                        f_brEnd(r)
                        evR := r.dir
                        m += "STRYK:WL " + syminfo.ticker + " BACK at the broken cluster " + f_p(r.lv) + " · " + f_tt(time)
                else
                    r.mx := math.max(r.mx, r.dir == 1 ? (high - r.lv) / r.a : (r.lv - low) / r.a)
                    for k = 1 to 4
                        if r.hit < k and r.mx >= f_tk(k)
                            r.hit := k
                            r.rk.set(k - 1, clk)
                            if isF and r.tg.size() >= k
                                r.tg.get(k - 1).set_text("T" + str.tostring(k) + " ✓ " + f_tt(time))
                                r.tg.get(k - 1).set_textcolor(cOk)
                                r.tl.get(k - 1).set_color(cOk)
                                m += (m == "" ? "" : " | ") + "STRYK:WL " + syminfo.ticker + " T" + str.tostring(k) + " hit " + f_tt(time)
                    if clk - r.b0C >= rxN and (r.hit == 0 or clk - r.rk.get(math.max(0, r.hit - 1)) > rwN)
                        r.st := 3
                        f_brFin(r)
                        if isF
                            f_brEnd(r)
            if r.st == 3 and r.id != FC.fid
                RB.remove(i)
    [evR, m]
 
// one confirmed candle: sweeps of untouched levels, returns, follow-ups, expiry
f_step(float a) =>
    int sU = 0
    int sD = 0
    int bk0 = 0
    string msg = ""
    if barstate.isconfirmed and L.size() > 0
        float buf = bufT * syminfo.mintick
        for i = L.size() - 1 to 0
            Lv v = L.get(i)
            bool isC = v.cnt >= minC
            bool done = false
            bool cfH = useH and brMd == "Cluster-timeframe close"
            float cx = cfH ? hC : close
            if brOn and not v.br and (isC or brSg) and bar_index > v.bc and (not cfH or hProc) and (v.side == 1 ? cx > v.px + buf : cx < v.px - buf)
                v.br := true
                f_brNew(v, a)
                bk0 := v.side
                msg += (msg == "" ? "" : " | ") + "STRYK:WL " + syminfo.ticker + " CLUSTER " + (v.side == 1 ? "above " : "below ") + f_p(v.px) + " BROKEN on a close " + f_tt(time) + " · T1 " + f_p(v.px + v.side * t1K * a)
            if v.st == 0
                bool tk = v.side == 1 ? (swMd == "Close through" ? close > v.px + buf : high > v.px + buf) : (swMd == "Close through" ? close < v.px - buf : low < v.px - buf)
                if tk and bar_index > v.bc
                    v.st := 1
                    v.sb := bar_index
                    v.sbC := clk
                    v.tS := time
                    v.a := a
                    f_freeze(v)
                    ST.n += 1
                    ST.nC += isC ? 1 : 0
                    ST.lv := v
                    string what = (isC ? "CLUSTER ×" + str.tostring(v.cnt) : "SINGLE WICK") + " " + (v.side == 1 ? "above " : "below ") + f_p(v.px)
                    if swOn
                        label.new(bar_index, v.px, isC ? "⚑" : "✕", yloc = v.side == 1 ? yloc.abovebar : yloc.belowbar, style = label.style_none, textcolor = v.side == 1 ? cSU : cSD, size = f_sz(sgSz), tooltip = "SWEPT " + what + " · " + f_tt(time) + " · watching " + str.tostring(rtN) + " bars for a return (historical ≈ 92 %; plain levels return about as often)")
                    if v.side == 1
                        sU := math.max(sU, isC ? 2 : 1)
                    else
                        sD := math.max(sD, isC ? 2 : 1)
                    msg += (msg == "" ? "" : " | ") + "STRYK:WL " + syminfo.ticker + " SWEPT " + what + " at " + f_tt(time)
                else if clk - v.bcC > expN
                    f_kill(v)
                    L.remove(i)
            else if v.st == 1
                bool back = v.side == 1 ? low <= v.px : high >= v.px
                if back and bar_index > v.sb
                    v.st := 2
                    v.rb := bar_index
                    v.rbC := clk
                    v.tR := time
                    ST.rt += 1
                    ST.rtC += isC ? 1 : 0
                    if rtOn
                        label.new(bar_index, v.px, "↺", yloc = v.side == 1 ? yloc.belowbar : yloc.abovebar, style = label.style_none, textcolor = cRt, size = f_sz(sgSz), tooltip = "RETURNED to " + f_p(v.px) + " · " + f_tt(time) + " · now: " + f_p(v.side == 1 ? v.px - mvK * v.a : v.px + mvK * v.a) + " back through vs " + f_p(v.side == 1 ? v.px + mvK * v.a : v.px - mvK * v.a) + " onward")
                else if clk - v.sbC >= rtN
                    v.res := 2
                    done := true
            else if v.st == 2
                bool bk = v.side == 1 ? low <= v.px - mvK * v.a : high >= v.px + mvK * v.a
                bool on = v.side == 1 ? high >= v.px + mvK * v.a : low <= v.px - mvK * v.a
                if bar_index <= v.rb
                    done := false
                else if bk and on
                    v.res := 4
                    ST.nt += 1
                    ST.ntC += isC ? 1 : 0
                    done := true
                else if bk
                    v.res := -1
                    ST.bk += 1
                    ST.bkC += isC ? 1 : 0
                    done := true
                else if on
                    v.res := 1
                    ST.on += 1
                    ST.onC += isC ? 1 : 0
                    done := true
                else if clk - v.rbC >= hzN
                    v.res := 3
                    ST.nt += 1
                    ST.ntC += isC ? 1 : 0
                    done := true
            if done
                v.st := 3
                if not kpOn
                    f_kill(v)
                L.remove(i)
    [sU, sD, msg, bk0]
 
// ─────────────────────────────── engine (confirmed candles only) ───────────────────────────────
float atrV = ta.atr(atrLen)
float aP = nz(atrV[1], high - low)
float uw = high - math.max(open, close)
float lw = math.min(open, close) - low
float bd = math.abs(close - open)
bool bigU = barstate.isconfirmed and aP > 0 and uw >= kW * aP and uw >= kB * bd
bool bigD = barstate.isconfirmed and aP > 0 and lw >= kW * aP and lw >= kB * bd
bool t17 = not na(time(timeframe.period, "1700-1701", TZ))
bool nDay = ssOn and t17 and not t17[1]
 
if nDay and barstate.isconfirmed
    if L.size() > 0
        for i = L.size() - 1 to 0
            Lv v = L.get(i)
            if v.st == 0
                f_kill(v)
                L.remove(i)
    tpU.clear()
    tbU.clear()
    tpD.clear()
    tbD.clear()
    txU.clear()
    txD.clear()
    ttU.clear()
    ttD.clear()
 
float aU = useH ? nz(hA, aP) : aP
[sU, sD, swMsg, brk] = f_step(aU)
[brR, brMsg] = f_brStep()
 
if not useH
    if bigU
        f_wick(1, high, uw, aP, tpU, tbU, txU, ttU, bar_index, bar_index, time)
    if bigD
        f_wick(-1, low, lw, aP, tpD, tbD, txD, ttD, bar_index, bar_index, time)
else if hProc and hIdx >= 2 and not na(hA) and hA > 0
    float hUw = hH - math.max(hO, hC)
    float hLw = math.min(hO, hC) - hL
    float hBd = math.abs(hC - hO)
    if hUw >= kW * hA and hUw >= kB * hBd
        f_wick(1, hH, hUw, hA, tpU, tbU, txU, ttU, hIdx, hPrevSB, hT)
        if wkOn
            label.new(hPrevSB, hH, "▼", style = label.style_none, textcolor = cWU, size = f_sz(wmSz), tooltip = "Large upper wick on the " + cTF + " candle of " + f_tt(hT) + " · " + f_p(hUw) + " (" + str.tostring(hUw / hA, "#.##") + " ATR)")
    if hLw >= kW * hA and hLw >= kB * hBd
        f_wick(-1, hL, hLw, hA, tpD, tbD, txD, ttD, hIdx, hPrevSB, hT)
        if wkOn
            label.new(hPrevSB, hL, "▲", style = label.style_none, textcolor = cWD, size = f_sz(wmSz), tooltip = "Large lower wick on the " + cTF + " candle of " + f_tt(hT) + " · " + f_p(hLw) + " (" + str.tostring(hLw / hA, "#.##") + " ATR)")
 
if alOn and (swMsg != "" or brMsg != "")
    alert(swMsg + (swMsg != "" and brMsg != "" ? " | " : "") + brMsg, alert.freq_once_per_bar_close)
 
plotshape(wkOn and not useH and bigU, "Large upper wick", shape.triangledown, location.abovebar, cWU, size = size.tiny)
plotshape(wkOn and not useH and bigD, "Large lower wick", shape.triangleup, location.belowbar, cWD, size = size.tiny)
alertcondition(sU > 0, "WL · Sweep above", "STRYK:WL — a wick cluster or level ABOVE price was swept")
alertcondition(sD > 0, "WL · Sweep below", "STRYK:WL — a wick cluster or level BELOW price was swept")
alertcondition(brk != 0, "WL · Cluster break (close)", "STRYK:WL — cluster close-through confirmed: ATR measurement cycle started. Not an entry signal.")
alertcondition(brR != 0, "WL · Back to broken cluster", "STRYK:WL — price came back to the broken wick cluster: cycle done")
 
// ─────────────────────────────── table (last bar) ───────────────────────────────
var table tb = table.new(f_pos(tbPos), 3, 12, frame_color = cFr, frame_width = frW, border_color = cFr, border_width = bdW)
 
f_cell(int r, string k, string v, color c) =>
    tb.cell(0, r, dtOn ? "●" : "", text_color = c, text_size = f_sz(tbSz), text_halign = text.align_center, bgcolor = cTb)
    tb.cell(1, r, k, text_color = cKy, text_size = f_sz(tbSz), text_halign = text.align_left, bgcolor = cTb)
    tb.cell(2, r, v, text_color = c, text_size = f_sz(tbSz), text_halign = text.align_left, bgcolor = cTb, text_font_family = font.family_monospace, tooltip = v)
    r + 1
 
f_near(int dir) =>
    Lv best = na
    float bd2 = na
    if L.size() > 0
        for i = 0 to L.size() - 1
            Lv v = L.get(i)
            if v.st == 0 and (dir == 1 ? v.px > close : v.px < close)
                float d = math.abs(v.px - close)
                if na(bd2) or d < bd2
                    bd2 := d
                    best := v
    best
 
f_lvTxt(Lv v, bool mob) =>
    na(v) ? "— none untouched" : (v.px > close ? "▲ " : "▼ ") + (v.cnt >= minC ? "CLUSTER ×" + str.tostring(v.cnt) : "SINGLE") + " " + f_p(v.px) + " · " + (v.px > close ? "+" : "−") + f_p(math.abs(v.px - close)) + (mob ? "" : " (" + str.tostring(math.abs(v.px - close) / math.max(useH ? nz(hA, aP) : aP, syminfo.mintick), "#.##") + " ATR) · formed " + f_tt(v.t0))
 
f_fuTxt(Lv v) =>
    v.st == 1 ? "waiting for a return" : v.st == 2 ? "returned ✓ " + f_tt(v.tR) + " · racing ±" + str.tostring(mvK) + " ATR" : v.res == -1 ? "returned ✓ · BACK THROUGH ✓" : v.res == 1 ? "returned ✓ · CONTINUED ✓" : v.res == 2 ? "no return in " + str.tostring(rtN) + " bars" : v.res == 4 ? "returned ✓ · NEITHER (one candle hit both sides)" : "returned ✓ · neither in " + str.tostring(hzN) + " bars"
 
f_lastTxt(Lv v) =>
    na(v) ? "— no sweep yet on the loaded chart" : (v.side == 1 ? "▲ " : "▼ ") + (v.cnt >= minC ? "×" + str.tostring(v.cnt) : "×1") + " " + f_p(v.px) + " swept " + f_tt(v.tS) + " · " + f_fuTxt(v)
 
if barstate.islast and brOn and not na(FC.r)
    if FC.r.st == 1 and FC.r.tg.size() > 0
        for k = 0 to FC.r.tg.size() - 1
            FC.r.tg.get(k).set_x(bar_index + 2)
 
if barstate.islast and tbOn
    tb.clear(0, 0, 2, 11)
    bool mob = tbLay == "Mobile"
    int r = 0
    tb.cell(0, r, "◆", text_color = cHd, text_size = f_sz(tbSz), text_halign = text.align_center, bgcolor = color.new(cHd, hdTr))
    tb.cell(1, r, mob ? "WL" : "STRYK · WL", text_color = cHt, text_size = f_sz(tbSz), text_halign = text.align_left, bgcolor = color.new(cHd, hdTr), text_formatting = text.format_bold)
    tb.cell(2, r, (mob ? "" : "wick liquidity · ") + (useH ? cTF + (cTF == "D" ? "" : "m") + " clusters" : "chart clusters") + " · " + str.tostring(L.size()) + " tracked", text_color = cHt, text_size = f_sz(tbSz), text_halign = text.align_left, bgcolor = color.new(cHd, hdTr))
    r += 1
    Lv up = f_near(1)
    Lv dn = f_near(-1)
    r := f_cell(r, mob ? "UP" : "Pool above", f_lvTxt(up, mob), na(up) ? cMt : up.side == 1 ? cLU : cLD)
    r := f_cell(r, mob ? "DN" : "Pool below", f_lvTxt(dn, mob), na(dn) ? cMt : dn.side == 1 ? cLU : cLD)
    r := f_cell(r, mob ? "LAST" : "Last sweep", f_lastTxt(ST.lv), na(ST.lv) ? cMt : ST.lv.res == -1 ? cAm : ST.lv.res == 1 ? cLD : cVl)
    if brOn
        Rn fr = FC.r
        bool live = not na(fr) and fr.st == 1
        string bT = na(fr) ? "waiting for a cluster to break on a candle close" : live ? (fr.dir == 1 ? "▲ " : "▼ ") + "×" + str.tostring(fr.cnt) + " " + f_p(fr.lv) + " broke " + f_tt(fr.t0) + " · run " + str.tostring(fr.mx, "#.##") + " ATR" : (fr.ret ? "✓ BACK " + f_tt(fr.tRet) : "no return in time") + " · waiting for the next cluster to break"
        r := f_cell(r, mob ? "BRK" : "Cluster break", bT, not live ? cMt : fr.dir == 1 ? cLD : cLU)
        if live
            string tT = ""
            for k = 1 to 4
                float pk = fr.lv + fr.dir * f_tk(k) * fr.a
                tT += (k > 1 ? " · " : "") + "T" + str.tostring(k) + (fr.hit >= k ? " ✓" : mob ? " " + f_p(pk) : " " + f_p(pk) + " " + f_pReach(k))
            r := f_cell(r, mob ? "TGT" : "Targets", tT, cTg)
            float runPts = fr.mx * fr.a
            float prog = runPts > 0 ? (runPts - (close - fr.lv) * fr.dir) / runPts : 0.0
            float togo = math.max(0.0, (close - fr.lv) * fr.dir)
            string rT = fr.hit == 0 ? "before T1 · back first " + f_pc(TS.nB0, TS.nB) + " · " + f_p(togo) + " to the cluster" : "back to " + f_p(fr.lv) + " within " + str.tostring(rwN) + (useH ? " × " + cTF + (cTF == "D" ? "" : "m") : "") + " candles after T" + str.tostring(fr.hit) + ": " + f_pRet(fr.hit) + " historical · distance back " + f_bar(prog) + " " + str.tostring(math.round(math.max(0.0, math.min(1.0, prog)) * 100)) + " % · " + f_p(togo) + " to go"
            r := f_cell(r, mob ? "RET" : "Return", rT, cOk)
        if not mob
            int pend = 0
            if RB.size() > 0
                for i = 0 to RB.size() - 1
                    pend += RB.get(i).st == 1 ? 1 : 0
            r := f_cell(r, "Cycle sample", "chart: " + str.tostring(TS.nB) + " finished · " + str.tostring(pend) + " open" + (TS.nCen > 0 ? " · " + str.tostring(TS.nCen) + " censored" : "") + " · odds use finished cycles only" + (TS.nB < minN ? " (research shown until " + str.tostring(minN) + ")" : ""), cMt)
    int nR = ST.bk + ST.on + ST.nt
    string hAll = "swept " + str.tostring(ST.n) + " · returned " + f_pc(ST.rt, ST.n) + " · of " + str.tostring(nR) + " returned and finished: back through " + f_pc(ST.bk, nR) + " · onward " + f_pc(ST.on, nR) + " · neither " + f_pc(ST.nt, nR)
    if mob
        r := f_cell(r, "HIST", "ret " + f_pc(ST.rt, ST.n) + " · back " + f_pc(ST.bk, nR) + " · on " + f_pc(ST.on, nR) + " · nei " + f_pc(ST.nt, nR) + " (n " + str.tostring(ST.n) + ")", cVl)
    else
        r := f_cell(r, "All levels", hAll, cVl)
        int nRC = ST.bkC + ST.onC + ST.ntC
        r := f_cell(r, "Clusters only", "swept " + str.tostring(ST.nC) + " · returned " + f_pc(ST.rtC, ST.nC) + " · of " + str.tostring(nRC) + ": back through " + f_pc(ST.bkC, nRC) + " · onward " + f_pc(ST.onC, nRC) + " · neither " + f_pc(ST.ntC, nRC), cVl)
        if rsOn
            r := f_cell(r, "Research", "historical (9 futures, 1h + 5m, to Nov 13 2026): broken wick clusters run further than plain levels (T1 73 vs 66 %, T2 52 vs 44 %) · the return (≈ 92 %) and the retest (≈ coin flip) match plain levels · not an entry signal", cMt)

← 返回列表