本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// =============================================================================
// STRYK:IM PRO v2.2 — adaptive noise-band breakouts, 08:30 VWAP, candle engine,
// breakout score, follow-through statistics and a hyper-gradient visual system.
//
// Built on STRYK:IM v1.2 (noise area after Zarattini, Aziz & Barbon; first 30m →
// last 30m after Gao, Han, Li & Zhou; 08:30 VWAP; N-day daily trend; VWAP trail
// trades). Every decision is made on a CONFIRMED bar unless "Intrabar preview"
// is chosen, which only adds provisional candidate dots that can disappear.
// Daily / higher-timeframe values are always the last COMPLETED bar.
//
// TradingView limits that shape the visuals (stated honestly):
// • there is no native multi-stop gradient; gradients here are colour
// interpolation (color.from_gradient) and two-colour plot fills.
// • barcolor() recolours candle bodies only — wicks / borders follow your
// chart settings and candle WIDTH can't be changed by a script.
// Research tool, not a promise of returns; not financial advice.
// =============================================================================
//@version=6
indicator("STRYK: INTRADAY MOMENTUM PRO", "STRYK:IMP", overlay = true, max_labels_count = 500, max_bars_back = 500)
// =============================================================================
// INPUTS
// =============================================================================
string GA = "A · Core"
mOn = input.bool(true, "INDICATOR ON", group = GA,
tooltip = "Master switch. Off = nothing calculated for display, no table, no alerts.")
preset = input.string("Average — balanced signals", "Preset (testing)", options = ["Slow — few signals", "Average — balanced signals", "Fast — many signals", "Paper (original)", "Custom"], group = GA,
tooltip = "One click sets every breakout rule. Switch between them and compare the PERFORMANCE section (follow-through %, events) on the same chart.\nSLOW — FEW SIGNALS: band ×1.25, median, opening-range adjust, 2 confirmations on 30-minute checks, volume ≥ 1.2× normal, score ≥ 60, 6-bar cooldown. Strongest moves only.\nAVERAGE — BALANCED (default): band ×1.0, median, opening-range adjust, 2 confirmations on 30-minute checks, no volume filter, 3-bar cooldown.\nFAST — MANY SIGNALS: band ×0.75, median, opening-range adjust, 1 confirmation checked every bar from 15 minutes after the open, 1-bar cooldown. Earliest entries, most false breakouts.\nPAPER (ORIGINAL): the published rule — average, band ×1.0, no adjust, 1 confirmation, 30-minute checks. The baseline.\nCUSTOM: your own values in sections B, C and F.")
tzIn = input.string("America/Chicago", "Timezone", group = GA, inline = "a1")
sessIn = input.session("0830-1500", "Cash session", group = GA, inline = "a1",
tooltip = "The session everything is anchored to (opening price, VWAP, noise slots, cash close). Default = CME equity cash hours in Chicago time; daylight saving is handled by the timezone.")
nDays = input.int(14, "History (days)", minval = 3, maxval = 60, group = GA,
tooltip = "How many past sessions feed the noise band, the opening-range norm and the same-time-of-day volume. 14 = the paper.")
sigMode = input.string("Bar close (confirmed)", "Signal mode", options = ["Bar close (confirmed)", "Intrabar preview"], group = GA,
tooltip = "BAR CLOSE: signals only on closed bars — they never move or disappear.\nINTRABAR PREVIEW: also shows a provisional candidate dot on the live bar the moment price crosses a band. It CAN disappear before the bar closes. Confirmed signals are identical in both modes.")
string GB = "B · Noise bands"
nStat = input.string("Median", "History statistic", options = ["Median", "Average", "Trimmed mean"], group = GB,
tooltip = "How past days' moves at this time of day are combined (CUSTOM preset only). MEDIAN: robust to news days. AVERAGE: the paper. TRIMMED MEAN: average after dropping the top and bottom 10 %.")
anchorM = input.string("Open + prior close (paper)", "Anchoring", options = ["Open + prior close (paper)", "Open only", "Prior close only"], group = GB,
tooltip = "Where the band is measured from. OPEN + PRIOR CLOSE (paper): upper band from the higher of today's open and yesterday's cash close, lower band from the lower — a gap widens the band. OPEN ONLY: both from today's open (tighter on gap days). PRIOR CLOSE ONLY: both from yesterday's close.")
vmUp = input.float(1.0, "Width × up", minval = 0.25, maxval = 4.0, step = 0.05, group = GB, inline = "b1")
vmDn = input.float(1.0, "down", minval = 0.25, maxval = 4.0, step = 0.05, group = GB, inline = "b1",
tooltip = "(CUSTOM preset only.) Width multipliers for the upper and lower band separately (asymmetric bands). 1.0 = the paper; 0.75 = tighter, earlier but more false breakouts.")
showBands = input.bool(true, "Bands", group = GB, inline = "b2")
cBandUp = input.color(#00E5A8, "", group = GB, inline = "b2")
cBandDn = input.color(#FF426D, "", group = GB, inline = "b2")
wBand = input.int(1, "width", minval = 1, maxval = 4, group = GB, inline = "b2")
bandSty = input.string("Line", "", options = ["Line", "Circles", "Cross"], group = GB, inline = "b2",
tooltip = "Upper / lower band lines: colours, width and style.")
fillMode = input.string("Gradient", "Band fill", options = ["Gradient", "Regime colour", "Off"], group = GB, inline = "b3")
fillT = input.int(90, "transparency", minval = 0, maxval = 100, group = GB, inline = "b3",
tooltip = "GRADIENT: fades from the up colour at the top band to the down colour at the bottom band. REGIME COLOUR: one colour from calm blue to hot red by today's volatility regime.")
extLn = input.bool(true, "Extend lines to the next 08:30 open", group = GB,
tooltip = "On (default) = the noise bands (last value at the cash close), band fill, centre line, opening range and prior close carry on flat through the overnight session until the next cash open, where they restart. Off = drawn only during the cash session.")
showMid = input.bool(false, "Centre line", group = GB, inline = "b4")
showOR = input.bool(true, "Opening range", group = GB, inline = "b4")
showPC = input.bool(true, "Prior close", group = GB, inline = "b4")
cRef = input.color(#FFBE55, "", group = GB, inline = "b4",
tooltip = "Optional reference lines: band centre, the opening range high / low (08:30–09:30 by default, drawn once complete) and yesterday's cash close.")
string GC = "C · Volatility"
orLen = input.int(60, "Opening range (minutes)", minval = 15, maxval = 120, step = 15, group = GC,
tooltip = "Length of the opening range from the cash open. 60 = 08:30–09:30 (default, the opening box). It sets the opening-range lines, the volatility regime and the band scale. The first-30-minute → last-30-minute bias always uses 30 minutes, as in the research.")
orAdj = input.bool(true, "Opening-range adjust", group = GC,
tooltip = "(CUSTOM preset only.) Once the opening range is complete (09:30 by default) the band is scaled by today's opening range ÷ its usual size. Checks before that are never adjusted — the range isn't known yet — and the scale is frozen for the rest of the day.")
orSens = input.float(1.0, "Sensitivity", minval = 0.25, maxval = 2.0, step = 0.05, group = GC, inline = "c1")
orMin = input.float(0.75, "min ×", minval = 0.3, maxval = 1.0, step = 0.05, group = GC, inline = "c1")
orMax = input.float(1.5, "max ×", minval = 1.0, maxval = 3.0, step = 0.05, group = GC, inline = "c1",
tooltip = "SENSITIVITY: 1 = scale by the ratio itself, 0.5 = by its square root (gentler), 2 = squared (stronger). MIN / MAX cap the scale (default 0.75× to 1.5×).")
rgQ = input.float(0.8, "Regime: quiet <", minval = 0.3, maxval = 1.0, step = 0.05, group = GC, inline = "c2")
rgE = input.float(1.25, "elevated >", minval = 1.0, maxval = 3.0, step = 0.05, group = GC, inline = "c2")
rgX = input.float(1.75, "extreme >", minval = 1.1, maxval = 5.0, step = 0.05, group = GC, inline = "c2",
tooltip = "Today's opening range ÷ the usual opening range decides the regime: below QUIET = Quiet, above ELEVATED = Elevated, above EXTREME = Extreme, otherwise Normal.")
cCalm = input.color(#397BFF, "Calm", group = GC, inline = "c3")
cWarm = input.color(#FFBE55, "Warm", group = GC, inline = "c3")
cHot = input.color(#FF4057, "Hot", group = GC, inline = "c3",
tooltip = "Volatility colours (regime band fill, volatility candles, dashboard).")
string GD = "D · Candles"
cMode = input.string("Improved HTF delta", "Candle mode", options = ["Improved HTF delta", "Original", "Gradient momentum", "Trend-coloured", "Volatility-coloured", "Pattern highlight", "Signal confirmation", "Minimal institutional"], group = GD,
tooltip = "IMPROVED HTF DELTA (default): price against the value area of the last 23 one-hour candles (section M) — blue inside value, bull colours above, bear colours below — brightened by distance, acceptance, relative size, POC migration and delta, and gated by momentum, trend and fuel.\nORIGINAL: no change. GRADIENT MOMENTUM: emerald → cyan → blue for stronger up candles, coral → pink → violet for stronger down candles (body size vs ATR). TREND: by side of the 08:30 VWAP and its slope. VOLATILITY: calm blue → amber → hot red by range vs ATR. PATTERN: gold on pattern bars, others dimmed. SIGNAL: bright only while a breakout trade is open. MINIMAL: greys, colour only on signal bars.")
cB1 = input.color(#00E5A8, "Bull", group = GD, inline = "d1")
cB2 = input.color(#00D9FF, "", group = GD, inline = "d1")
cB3 = input.color(#397BFF, "", group = GD, inline = "d1",
tooltip = "Bullish gradient: weak → medium → strong.")
cR1 = input.color(#FF426D, "Bear", group = GD, inline = "d2")
cR2 = input.color(#FF2D95, "", group = GD, inline = "d2")
cR3 = input.color(#8B5CFF, "", group = GD, inline = "d2",
tooltip = "Bearish gradient: weak → medium → strong.")
cSil = input.color(#C8D3E4, "Neutral", group = GD, inline = "d3")
cGry = input.color(#8190A8, "Dim", group = GD, inline = "d3")
cGold = input.color(#FFE66D, "Pattern", group = GD, inline = "d3")
candT = input.int(0, "body transparency", minval = 0, maxval = 90, group = GD, inline = "d3",
tooltip = "Neutral, dimmed and pattern colours, and how see-through the recoloured bodies are.")
paintM = input.string("Full candle (body + wick + border)", "Paint", options = ["Full candle (body + wick + border)", "Body only"], group = GD,
tooltip = "FULL CANDLE (default): the indicator redraws every candle on top of the chart's own, so body, wick and border all take the engine colour. BODY ONLY: recolours bodies with barcolor() and leaves wicks / borders to your chart settings. Tip for full candle: if you change chart candle colours you can also untick the chart's own Body / Borders / Wick (Settings → Symbol) — the painted candles sit exactly on top either way.")
string GE = "E · Candle patterns"
pMom = input.bool(true, "Momentum", group = GE, inline = "e1")
pRej = input.bool(true, "Rejection", group = GE, inline = "e1")
pInd = input.bool(true, "Indecision", group = GE, inline = "e1")
pMul = input.bool(true, "Multi-bar", group = GE, inline = "e1",
tooltip = "MOMENTUM: strong body, marubozu, wide-range expansion. REJECTION: hammer, shooting star, failed band breakout. INDECISION: doji, inside bar, NR7. MULTI-BAR: engulfing, piercing / dark cloud, morning / evening star, three-bar continuation, tweezers. Descriptions of the candle, not predictions.")
thBody = input.float(0.7, "Strong body ≥", minval = 0.4, maxval = 0.95, step = 0.05, group = GE, inline = "e2")
thWick = input.float(0.6, "rejection wick ≥", minval = 0.4, maxval = 0.9, step = 0.05, group = GE, inline = "e2")
thDoji = input.float(0.1, "doji body ≤", minval = 0.02, maxval = 0.3, step = 0.01, group = GE, inline = "e2")
thWide = input.float(1.5, "wide range ≥ ATR ×", minval = 1.0, maxval = 4.0, step = 0.1, group = GE, inline = "e3",
tooltip = "Thresholds as a share of the candle's range (body, wick) and as a multiple of ATR(14) for wide-range candles.")
patLab = input.bool(false, "Pattern labels", group = GE, inline = "e4")
patMax = input.int(60, "max", minval = 5, maxval = 200, group = GE, inline = "e4",
tooltip = "Tiny name tag on pattern bars (one per bar, highest-priority pattern only). Off by default to keep the chart clean; MAX = how many stay on the chart.")
string GF = "F · Breakouts"
confMode = input.string("Every 30 minutes", "Checks", options = ["Every 30 minutes", "Every bar"], group = GF, inline = "f1")
firstChk = input.int(30, "first (min after open)", minval = 5, maxval = 300, group = GF, inline = "f1",
tooltip = "(CUSTOM preset only.) EVERY 30 MINUTES (paper): breakouts, confirmations and the VWAP trailing exit are only evaluated on bars that CLOSE on :00 / :30 by the clock, so 2 confirmations = two separate 30-minute checks on any chart timeframe up to 30m. EVERY BAR: on every bar close. FIRST: no breakout before this many minutes after the open.")
nConf = input.int(2, "Confirmations", minval = 1, maxval = 4, group = GF, inline = "f2")
cooldown = input.int(3, "cooldown (bars)", minval = 0, maxval = 50, group = GF, inline = "f2",
tooltip = "(CUSTOM preset only.) CONFIRMATIONS: checks in a row outside the band. COOLDOWN: bars to wait after a trade closes before a new one; one breakout event never fires twice.")
retestOn = input.bool(false, "Require retest", group = GF, inline = "f3")
retestN = input.int(6, "within bars", minval = 1, maxval = 50, group = GF, inline = "f3",
tooltip = "Off (default) = enter on the confirmed breakout. On = after the confirmed breakout wait for a bar that touches the band and closes back beyond it, within this many bars; no retest in time = the setup expires.")
rvOn = input.bool(false, "Volume filter", group = GF, inline = "f4")
rvMin = input.float(1.2, "min × normal", minval = 0.5, maxval = 5.0, step = 0.1, group = GF, inline = "f4",
tooltip = "(CUSTOM preset only.) A check only counts when the bar's volume is at least this multiple of normal volume for the SAME time of day. With too little history the filter passes (stated in diagnostics).")
scoreMin = input.int(0, "Min score", minval = 0, maxval = 100, group = GF, inline = "f5")
hiConf = input.int(70, "high confluence ≥", minval = 1, maxval = 100, group = GF, inline = "f5",
tooltip = "MIN SCORE (CUSTOM preset only): signals below it are skipped. HIGH CONFLUENCE: signals at or above it get the bright marker and their own alert. The score is a weighted checklist, not a probability.")
wtBand = input.int(2, "Weights: band push", minval = 0, maxval = 5, group = GF, inline = "w1")
wtVol = input.int(2, "volume", minval = 0, maxval = 5, group = GF, inline = "w1")
wtBody = input.int(1, "body", minval = 0, maxval = 5, group = GF, inline = "w1")
wtVw = input.int(2, "VWAP", minval = 0, maxval = 5, group = GF, inline = "w2")
wtDay = input.int(1, "daily trend", minval = 0, maxval = 5, group = GF, inline = "w2")
wt30 = input.int(1, "first 30m", minval = 0, maxval = 5, group = GF, inline = "w2")
wtEma = input.int(1, "EMA trend", minval = 0, maxval = 5, group = GF, inline = "w3")
wtReg = input.int(1, "regime", minval = 0, maxval = 5, group = GF, inline = "w3",
tooltip = "Score 0–100 = weighted share of: how far the close pushed beyond the band (in band-widths), relative volume, body strength, side of the 08:30 VWAP, daily trend, first-30-minute bias, EMA trend (when on) and volatility regime. Weight 0 removes a part; the rest re-normalise to 100.")
string GG = "G · VWAP & trend"
showVw = input.bool(true, "08:30 VWAP", group = GG, inline = "g1")
vwCol = input.string("Gradient by distance", "", options = ["Gradient by distance", "Side colours"], group = GG, inline = "g1")
wVw = input.int(2, "width", minval = 1, maxval = 6, group = GG, inline = "g1",
tooltip = "GRADIENT BY DISTANCE: silver at the VWAP, brightening to the bull colours above and the bear colours below as price stretches (in σ). SIDE COLOURS: plain up / down colour.")
vwRth = input.bool(false, "VWAP lines in the cash session only", group = GG,
tooltip = "Off (default) = the 08:30 VWAP and its deviation bands run until the next 08:30 open, where they restart. On = drawn only from 08:30 to the cash close. Calculations are the same either way.")
showVwB = input.bool(true, "Deviation bands", group = GG, inline = "g2")
vwB1 = input.float(1.0, "inner σ", minval = 0.25, maxval = 4.0, step = 0.25, group = GG, inline = "g2")
vwB2 = input.float(2.0, "outer σ", minval = 0.5, maxval = 5.0, step = 0.25, group = GG, inline = "g2")
vwBT = input.int(88, "shading", minval = 0, maxval = 100, group = GG, inline = "g2",
tooltip = "Two volume-weighted deviation bands around the 08:30 VWAP with gradient shading between them (stronger toward the outer band).")
showSv = input.bool(false, "Session VWAP (17:00)", group = GG, inline = "g3")
cSv = input.color(#8190A8, "", group = GG, inline = "g3",
tooltip = "The full futures-session VWAP from the 17:00 CT open, for reference.")
emaOn = input.bool(true, "EMA ribbon", group = GG, inline = "g4")
emaF = input.int(21, "", minval = 2, maxval = 400, group = GG, inline = "g4")
emaS = input.int(55, "", minval = 3, maxval = 500, group = GG, inline = "g4")
emaT = input.int(85, "ribbon fill", minval = 0, maxval = 100, group = GG, inline = "g4",
tooltip = "Fast / slow EMA ribbon; the fill shades from the bear to the bull palette by how far apart they are (in ATR). Its direction feeds the score.")
htfOn = input.bool(false, "HTF trend filter", group = GG, inline = "g5")
htfTf = input.timeframe("60", "", group = GG, inline = "g5")
htfLen = input.int(50, "EMA", minval = 2, maxval = 400, group = GG, inline = "g5",
tooltip = "On = longs only while the last COMPLETED higher-timeframe close is above its EMA, shorts only below. Use a timeframe above the chart's.")
trDays = input.int(20, "Daily trend: N-day return", minval = 2, maxval = 260, group = GG,
tooltip = "Up when the last completed daily close is above the close N days before it. 20 ≈ a month, 250 ≈ a year (classic CTA).")
lastT = input.int(90, "Last-30m shading", minval = 0, maxval = 100, group = GG,
tooltip = "Shades the final 30 minutes of the cash session in the colour of the first-half-hour bias (100 = off).")
string GH = "H · Signals"
showL = input.bool(true, "Longs", group = GH, inline = "h1")
showS = input.bool(true, "Shorts", group = GH, inline = "h1")
sigTag = input.bool(false, "LONG / SHORT tag", group = GH, inline = "h1",
tooltip = "Which signals are drawn, and whether the word LONG / SHORT is added to the arrow.")
sigSz = input.string("Small", "Marker size", options = ["Tiny", "Small", "Normal", "Large", "Huge"], group = GH, inline = "h2")
sigOff = input.int(2, "offset (ticks)", minval = 0, maxval = 200, group = GH, inline = "h2",
tooltip = "Size of the signal arrows and how far below / above the candle they sit.")
showSc = input.bool(true, "Score", group = GH, inline = "h3")
showPx = input.bool(false, "Price", group = GH, inline = "h3")
showVm = input.bool(true, "Volume ◆", group = GH, inline = "h3",
tooltip = "Extra details on each signal: the 0–100 score, the breakout price, and ◆ when volume was above normal for that time of day.")
sigT = input.int(0, "Signal transparency", minval = 0, maxval = 80, group = GH, inline = "h4",
tooltip = "0 = full intensity. Signal colour also brightens with the score (low score = first palette colour, high = last).")
showCand = input.bool(true, "Candidate dots", group = GH, inline = "h5")
showRej = input.bool(true, "Failed ✕", group = GH, inline = "h5",
tooltip = "CANDIDATE DOTS: a small dot on any check that closes outside a band before it is confirmed. FAILED ✕: a confirmed breakout that closed back inside the band before reaching its follow-through target.")
string GI = "I · Trade management"
exVw = input.bool(true, "VWAP trailing exit", group = GI, inline = "i1")
exBand = input.bool(false, "Band invalidation", group = GI, inline = "i1")
exOpp = input.bool(true, "Opposite signal", group = GI, inline = "i1",
tooltip = "Exits for signal trades. VWAP TRAILING (paper): on a check, close back past max(upper band, VWAP) for longs / min(lower band, VWAP) for shorts. BAND INVALIDATION: any close back inside the band. OPPOSITE SIGNAL: a confirmed signal the other way. Always flat at the cash close.")
atrSt = input.bool(false, "ATR stop", group = GI, inline = "i2")
atrK = input.float(2.0, "× ATR", minval = 0.25, maxval = 10.0, step = 0.25, group = GI, inline = "i2")
tgtOn = input.bool(false, "Target", group = GI, inline = "i2")
tgtK = input.float(2.0, "target × band", minval = 0.25, maxval = 10.0, step = 0.25, group = GI, inline = "i2",
tooltip = "Optional hard stop (ATR(14) × K from entry) and target (K band-widths beyond the entry).")
beOn = input.bool(false, "Break-even at", group = GI, inline = "i3")
beK = input.float(1.0, "BE × band", minval = 0.25, maxval = 5.0, step = 0.25, group = GI, inline = "i3",
tooltip = "Moves the ATR stop to the entry once price has gone this many band-widths in your favour (needs ATR stop on).")
showStop = input.bool(true, "Trail / stop line", group = GI, inline = "i4")
cStop = input.color(#FFE66D, "", group = GI, inline = "i4")
costTk = input.float(2.0, "Cost per trade (ticks)", minval = 0.0, maxval = 50.0, step = 0.5, group = GI,
tooltip = "Commission + slippage per round trip, taken off every signal trade and VWAP trail trade in the table. Points are not money; this is an observation tool, not a backtest.")
mTrail = input.bool(true, "VWAP trail trades", group = GI, inline = "i5")
tvMode = input.string("Only after a noise breakout", "", options = ["Only after a noise breakout", "Every VWAP cross"], group = GI, inline = "i5",
tooltip = "The separate VWAP-trail module from STRYK:IM: long while price closes above the 08:30 VWAP, short below; a close back through it exits and reverses. ONLY AFTER A NOISE BREAKOUT: only the side today has broken out to.")
tvBuf = input.int(0, "trail buffer (ticks)", minval = 0, maxval = 100, group = GI, inline = "i6")
tvLast = input.int(360, "last entry (min)", minval = 30, maxval = 600, group = GI, inline = "i6",
tooltip = "BUFFER: the close must be this many ticks through the VWAP to count. LAST ENTRY: minutes after the open (360 = 14:30 CT).")
string GJ = "J · Dashboard"
tblOn = input.bool(true, "Dashboard", group = GJ, inline = "j1")
tblPos = input.string("Bottom right", "", options = ["Top left", "Top center", "Top right", "Middle left", "Middle right", "Bottom left", "Bottom center", "Bottom right"], group = GJ, inline = "j1")
tblSz = input.string("Small", "", options = ["Tiny", "Small", "Normal"], group = GJ, inline = "j1")
compact = input.bool(false, "Compact", group = GJ, inline = "j1",
tooltip = "Position, text size; COMPACT hides the detail column.")
secCore = input.bool(true, "Core", group = GJ, inline = "j2")
secPerf = input.bool(true, "Performance", group = GJ, inline = "j2")
secReg = input.bool(true, "Regimes", group = GJ, inline = "j2")
secIdea = input.bool(true, "Ideas", group = GJ, inline = "j2",
tooltip = "Which sections are shown.")
cTbBg = input.color(#0B1020, "Background", group = GJ, inline = "j3")
tbT = input.int(8, "transparency", minval = 0, maxval = 90, group = GJ, inline = "j3")
cTbTx = input.color(#C8D3E4, "Text", group = GJ, inline = "j3")
cTbBd = input.color(#1C2638, "Border", group = GJ, inline = "j4")
wTbBd = input.int(1, "border", minval = 0, maxval = 4, group = GJ, inline = "j4")
cTbFr = input.color(#397BFF, "Frame", group = GJ, inline = "j4")
wTbFr = input.int(1, "frame", minval = 0, maxval = 4, group = GJ, inline = "j4",
tooltip = "Header rows use a stepped bull → bear gradient strip from the candle palettes.")
string GK = "K · Statistics"
ftOn = input.bool(true, "Follow-through tracking", group = GK, inline = "k1")
ftK = input.float(1.0, "target × band", minval = 0.25, maxval = 4.0, step = 0.25, group = GK, inline = "k1",
tooltip = "Every confirmed breakout is scored. TARGET: this many band-widths beyond the band (band-width = anchor → band at signal time). HIT = target reached first; FAILED = close back inside the band first; AMBIGUOUS = both on the same candle (order unknown, kept separate); UNRESOLVED = session ended first (not counted as hit or fail).")
ftMinN = input.int(20, "Min sample", minval = 5, maxval = 200, group = GK,
tooltip = "Rates based on fewer events than this are flagged 'low n'.")
string GM = "M · Improved HTF delta candles"
ihTf = input.timeframe("60", "Value area: TF", group = GM, inline = "m1")
ihN = input.int(23, "× candles", minval = 3, maxval = 100, group = GM, inline = "m1")
ihVa = input.int(70, "value area %", minval = 50, maxval = 95, group = GM, inline = "m1",
tooltip = "The reference for the candle colours: a volume profile of the last N COMPLETED candles of this timeframe (default 23 × 1 hour = one futures session), its POC and its value area. Completed candles only, so it never repaints; it updates once per hour.")
ihRamp = input.int(50, "Distance ramp (% of VA)", minval = 10, maxval = 200, group = GM, inline = "m2")
ihLean = input.float(0.35, "inside lean", minval = 0.0, maxval = 1.0, step = 0.05, group = GM, inline = "m2",
tooltip = "RAMP: how far beyond the value area (as % of its width) a candle must close to reach full distance strength. INSIDE LEAN: inside value the candle tilts from the inside colour toward bull above the POC / bear below it, this much at the value-area edge.")
cInside = input.color(#2D5BD8, "Inside value", group = GM, inline = "m3",
tooltip = "Colour of candles closing inside the value area.")
ihMomOn = input.bool(true, "Momentum gate", group = GM, inline = "m4")
ihMomLen = input.int(5, "bars", minval = 1, maxval = 50, group = GM, inline = "m4")
ihMomK = input.float(0.5, "min × ATR", minval = 0.0, maxval = 5.0, step = 0.1, group = GM, inline = "m4")
ihCap = input.float(0.35, "cap", minval = 0.0, maxval = 1.0, step = 0.05, group = GM, inline = "m4",
tooltip = "MOMENTUM GATE: a candle outside value only lights up fully when price has moved at least MIN × ATR(14) in that direction over the last BARS. Without that momentum its brightness is capped at CAP (0 = stays at the faintest bull / bear shade).")
ihTrOn = input.bool(true, "Trend", group = GM, inline = "m5")
ihTrB = input.float(0.25, "boost", minval = 0.0, maxval = 1.0, step = 0.05, group = GM, inline = "m5",
tooltip = "Two trend reads: the EMA ribbon (section G) and the delta of the current 23-hour session (17:00 CT). Both agree with the candle's side = brighter by BOOST, both against = dimmer by BOOST, one each = unchanged.")
ihFuOn = input.bool(true, "Fuel", group = GM, inline = "m6")
ihPeak = input.int(60, "full at participation", minval = 30, maxval = 90, group = GM, inline = "m6")
ihBellW = input.int(30, "bell", minval = 5, maxval = 50, group = GM, inline = "m6",
tooltip = "FUEL = is the move paid for: participation (volume percentile vs the last 100 bars) shaped by a bell that is full at FULL AT and above, × whether the candle's delta agrees with its body. Low fuel dims the candle toward half strength.")
hdSrc = input.string("Intrabar 1-min, fall back to estimate", "Delta source", options = ["Intrabar 1-min, fall back to estimate", "Estimate from chart bars"], group = GM,
tooltip = "INTRABAR 1-MIN: each 1-minute bar inside the chart bar counts as buying (close > open) or selling; TradingView keeps limited 1-minute history, so older bars fall back to the estimate. ESTIMATE: from where each chart bar closed in its range.")
string GN = "N · Alerts"
aCand = input.bool(false, "Candidates", group = GN, inline = "n1")
aConf = input.bool(true, "Confirmed", group = GN, inline = "n1")
aHiC = input.bool(true, "High confluence", group = GN, inline = "n1")
aFail = input.bool(true, "Failed", group = GN, inline = "n2")
aRt = input.bool(false, "Retest", group = GN, inline = "n2")
aExit = input.bool(true, "Trade exit", group = GN, inline = "n2")
aTrd = input.bool(false, "Trend change", group = GN, inline = "n3")
aReg = input.bool(false, "Regime change", group = GN, inline = "n3",
tooltip = "Pick which events send an alert, then create ONE alert on this indicator with the condition 'Any alert() function call'. Each message says the event, direction, price, score and regime. Alerts fire once at the bar close; an alert is not an executed order.")
string GL = "L · Diagnostics"
dbg = input.bool(false, "Debug rows", group = GL,
tooltip = "Adds rows with history coverage, session state, current band values and why the last breakout was skipped.")
// =============================================================================
// HELPERS
// =============================================================================
f_sz(string s) => s == "Tiny" ? size.tiny : s == "Small" ? size.small : s == "Large" ? size.large : s == "Huge" ? size.huge : size.normal
f_pos(string p) =>
switch p
"Top left" => position.top_left
"Top center" => position.top_center
"Top right" => position.top_right
"Middle left" => position.middle_left
"Middle right" => position.middle_right
"Bottom left" => position.bottom_left
"Bottom center" => position.bottom_center
=> position.bottom_right
f_cl(float x, float lo, float hi) => math.max(lo, math.min(hi, x))
// three-stop colour ramp: t in 0..1
f_ramp(float t, color a, color b, color c) => t <= 0.5 ? color.from_gradient(t, 0.0, 0.5, a, b) : color.from_gradient(t, 0.5, 1.0, b, c)
// preset → effective rules
bool pCust = preset == "Custom"
bool pPaper = preset == "Paper (original)"
bool pSlow = preset == "Slow — few signals"
bool pFast = preset == "Fast — many signals"
string eStat = pCust ? nStat : pPaper ? "Average" : "Median"
bool eOr = pCust ? orAdj : not pPaper
int eConf = pCust ? nConf : pPaper or pFast ? 1 : 2
bool eRv = pCust ? rvOn : pSlow
float eRvMin = pCust ? rvMin : 1.2
int eScMin = pCust ? scoreMin : pSlow ? 60 : 0
float eVmU = pCust ? vmUp : pSlow ? 1.25 : pFast ? 0.75 : 1.0
float eVmD = pCust ? vmDn : pSlow ? 1.25 : pFast ? 0.75 : 1.0
string eChk = pCust ? confMode : pFast ? "Every bar" : "Every 30 minutes"
int eFirst = pCust ? firstChk : pFast ? 15 : 30
int eCool = pCust ? cooldown : pSlow ? 6 : pFast ? 1 : pPaper ? 0 : 3
// =============================================================================
// 1 · SESSION & TIME ENGINE
// =============================================================================
int openMin = int(str.tonumber(str.substring(sessIn, 0, 2))) * 60 + int(str.tonumber(str.substring(sessIn, 2, 4)))
int closeMin = int(str.tonumber(str.substring(sessIn, 5, 7))) * 60 + int(str.tonumber(str.substring(sessIn, 7, 9)))
int mOfDay = hour(time, tzIn) * 60 + minute(time, tzIn)
int mClose = hour(time_close, tzIn) * 60 + minute(time_close, tzIn)
bool inRth = mOfDay >= openMin and mOfDay < closeMin
bool rthStart = inRth and (not inRth[1] or time - time[1] > 3 * 3600000)
bool rthLast = inRth and mClose >= closeMin
int sinceOpen = mClose - openMin
int orEnd = openMin + orLen
int b30End = openMin + 30
var float dOpen = na
var float prevClose = na
var float lastRthC = na
if rthStart
prevClose := lastRthC
dOpen := open
if inRth
lastRthC := close
bool chk = inRth and (eChk == "Every bar" or mClose % 30 == 0)
// =============================================================================
// 2 · HISTORICAL NOISE ENGINE — same-time-of-day moves and volume
// =============================================================================
type Slot
array<float> moves
array<float> vols
f_stat(array<float> a) =>
float r = na
int n = a.size()
if n > 0
if eStat == "Median"
r := a.median()
else if eStat == "Average"
r := a.avg()
else
array<float> c = a.copy()
c.sort()
int k = n >= 5 ? math.max(1, int(n * 0.1)) : 0
float s = 0.0
for i = k to n - 1 - k
s += c.get(i)
r := s / (n - 2 * k)
r
var map<int, Slot> slots = map.new<int, Slot>()
float sig = na
float relV = na
int slotN = 0
if inRth and not na(dOpen)
int key = mOfDay - openMin
if not slots.contains(key)
slots.put(key, Slot.new(array.new_float(), array.new_float()))
Slot sl = slots.get(key)
slotN := sl.moves.size()
if slotN >= nDays
sig := f_stat(sl.moves)
float nv = f_stat(sl.vols)
relV := nv > 0 ? nz(volume) / nv : na
if barstate.isconfirmed
sl.moves.push(math.abs(close / dOpen - 1))
sl.vols.push(nz(volume))
if sl.moves.size() > nDays
sl.moves.shift()
sl.vols.shift()
// =============================================================================
// 3 · ADAPTIVE VOLATILITY ENGINE — opening range vs its norm, frozen after
// =============================================================================
var array<float> orHist = array.new_float()
var float orH = na
var float orL = na
var float dayFac = 1.0
var float orRatio = na
var int regime = -1 // -1 pending, 0 quiet, 1 normal, 2 elevated, 3 extreme
if rthStart
orH := high
orL := low
dayFac := 1.0
orRatio := na
regime := -1
else if inRth and mOfDay < orEnd
orH := math.max(orH, high)
orL := math.min(orL, low)
if inRth and mClose == orEnd and barstate.isconfirmed and not na(orH)
float orT = orH - orL
if orHist.size() >= 5
float orN = f_stat(orHist)
if orN > 0
orRatio := orT / orN
dayFac := f_cl(math.pow(orRatio, orSens), orMin, orMax)
regime := orRatio < rgQ ? 0 : orRatio > rgX ? 3 : orRatio > rgE ? 2 : 1
orHist.push(orT)
if orHist.size() > nDays
orHist.shift()
float fac = eOr and mOfDay >= orEnd ? dayFac : 1.0
color regCol = regime == 0 ? cCalm : regime == 1 ? color.from_gradient(0.5, 0, 1, cCalm, cWarm) : regime == 2 ? cWarm : regime == 3 ? cHot : cGry
string regTxt = regime == 0 ? "Quiet" : regime == 1 ? "Normal" : regime == 2 ? "Elevated" : regime == 3 ? "Extreme" : "pending"
// bands
float aHi = anchorM == "Open only" ? dOpen : anchorM == "Prior close only" ? nz(prevClose, dOpen) : na(prevClose) ? dOpen : math.max(dOpen, prevClose)
float aLo = anchorM == "Open only" ? dOpen : anchorM == "Prior close only" ? nz(prevClose, dOpen) : na(prevClose) ? dOpen : math.min(dOpen, prevClose)
float upB = na(sig) ? na : aHi * (1 + eVmU * fac * sig)
float dnB = na(sig) ? na : aLo * (1 - eVmD * fac * sig)
float bwU = upB - aHi
float bwD = aLo - dnB
var float lastUp = na
var float lastDn = na
var float lastBwU = na
var float lastBwD = na
var int lastSlotN = 0
if not na(upB)
lastUp := upB
lastDn := dnB
lastBwU := bwU
lastBwD := bwD
if inRth
lastSlotN := slotN
// =============================================================================
// 4 · VWAP ENGINE
// =============================================================================
[vwap, vU1, vL1] = ta.vwap(hlc3, rthStart, vwB1)
[vwap2, vU2, vL2] = ta.vwap(hlc3, rthStart, vwB2)
float sVw = ta.vwap(hlc3, timeframe.change("D"))
float vSd = vwB1 > 0 ? (vU1 - vwap) / vwB1 : na
float vZ = vSd > 0 ? (close - vwap) / vSd : 0.0
int vSide = na(vwap) ? 0 : close > vwap ? 1 : close < vwap ? -1 : 0
int vSlope = na(vwap[3]) ? 0 : vwap > vwap[3] ? 1 : vwap < vwap[3] ? -1 : 0
// =============================================================================
// 5 · TREND & REGIME ENGINE
// =============================================================================
float atr = ta.atr(14)
float eF = ta.ema(close, emaF)
float eS = ta.ema(close, emaS)
int emaDir = eF > eS ? 1 : eF < eS ? -1 : 0
[hE, hC] = request.security(syminfo.tickerid, htfTf, [ta.ema(close, htfLen)[1], close[1]], lookahead = barmerge.lookahead_on)
int htfDir = na(hE) or na(hC) ? 0 : hC > hE ? 1 : -1
[dC, dCn] = request.security(syminfo.tickerid, "D", [close[1], close[1 + trDays]], lookahead = barmerge.lookahead_on)
int dSide = na(dC) or na(dCn) ? 0 : dC > dCn ? 1 : dC < dCn ? -1 : 0
// first half-hour → last half-hour
var int lBias = 0
var float r30 = na
if rthStart
lBias := 0
r30 := na
if inRth and mClose == b30End and barstate.isconfirmed and not na(prevClose)
r30 := close / prevClose - 1
lBias := r30 > 0 ? 1 : r30 < 0 ? -1 : 0
bool inLast = inRth and mOfDay >= closeMin - 30
// =============================================================================
// 6 · CANDLE ANATOMY ENGINE
// =============================================================================
float rng = high - low
float body = math.abs(close - open)
float bR = rng > 0 ? body / rng : 0.0
float uR = rng > 0 ? (high - math.max(open, close)) / rng : 0.0
float lR = rng > 0 ? (math.min(open, close) - low) / rng : 0.0
int cDir = close > open ? 1 : close < open ? -1 : 0
float rAtr = atr > 0 ? rng / atr : 0.0
float bAtr = atr > 0 ? body / atr : 0.0
float rngLo7 = ta.lowest(rng, 7)
bool nr7 = rng > 0 and rng <= rngLo7
// =============================================================================
// 7 · CANDLESTICK PATTERN ENGINE — one name per bar, highest priority wins
// =============================================================================
bool engBu = cDir == 1 and cDir[1] == -1 and close >= open[1] and open <= close[1] and body > body[1]
bool engBe = cDir == -1 and cDir[1] == 1 and close <= open[1] and open >= close[1] and body > body[1]
bool pierc = cDir == 1 and cDir[1] == -1 and open < close[1] and close > (open[1] + close[1]) / 2 and close < open[1]
bool dCld = cDir == -1 and cDir[1] == 1 and open > close[1] and close < (open[1] + close[1]) / 2 and close > open[1]
bool mStar = cDir[2] == -1 and bR[2] >= 0.5 and bR[1] <= 0.3 and cDir == 1 and close > (open[2] + close[2]) / 2
bool eStar = cDir[2] == 1 and bR[2] >= 0.5 and bR[1] <= 0.3 and cDir == -1 and close < (open[2] + close[2]) / 2
bool three3U = cDir == 1 and cDir[1] == 1 and cDir[2] == 1 and close > close[1] and close[1] > close[2] and bR >= 0.5 and bR[1] >= 0.5 and bR[2] >= 0.5
bool three3D = cDir == -1 and cDir[1] == -1 and cDir[2] == -1 and close < close[1] and close[1] < close[2] and bR >= 0.5 and bR[1] >= 0.5 and bR[2] >= 0.5
bool twzTop = cDir[1] == 1 and cDir == -1 and math.abs(high - high[1]) <= 2 * syminfo.mintick
bool twzBot = cDir[1] == -1 and cDir == 1 and math.abs(low - low[1]) <= 2 * syminfo.mintick
bool hammer = lR >= thWick and uR <= 0.15 and bR <= 0.35
bool sStar = uR >= thWick and lR <= 0.15 and bR <= 0.35
bool failUp = not na(upB) and high > upB and close < upB
bool failDn = not na(dnB) and low < dnB and close > dnB
bool maru = bR >= 0.9 and rng > 0
bool strong = bR >= thBody and rng > 0
bool wide = rAtr >= thWide
bool doji = rng > 0 and bR <= thDoji
bool inside = high < high[1] and low > low[1]
string patNm = ""
int patD = 0
if pMul
patNm := engBu ? "Engulf" : engBe ? "Engulf" : pierc ? "Piercing" : dCld ? "Dark cloud" : mStar ? "Morning ★" : eStar ? "Evening ★" : three3U ? "3 up" : three3D ? "3 down" : twzBot ? "Tweezer" : twzTop ? "Tweezer" : ""
patD := engBu or pierc or mStar or three3U or twzBot ? 1 : engBe or dCld or eStar or three3D or twzTop ? -1 : 0
if patNm == "" and pRej
patNm := failUp ? "Failed ▲" : failDn ? "Failed ▼" : hammer ? "Hammer" : sStar ? "Shooting ★" : ""
patD := failDn or hammer ? 1 : failUp or sStar ? -1 : 0
if patNm == "" and pMom
patNm := maru ? "Marubozu" : wide and strong ? "Wide range" : strong ? "Strong" : ""
patD := patNm != "" ? cDir : 0
if patNm == "" and pInd
patNm := doji ? "Doji" : inside ? "Inside" : nr7 ? "NR7" : ""
patD := 0
bool isPat = patNm != ""
// =============================================================================
// 8–10 · MOMENTUM, VOLUME & BREAKOUT CONFIRMATION ENGINE
// =============================================================================
f_score(int d) =>
float ws = 0.0
float ss = 0.0
if wtBand > 0
float bw = d == 1 ? bwU : bwD
float px = d == 1 ? close - upB : dnB - close
ws += wtBand
ss += wtBand * (bw > 0 ? f_cl(px / bw, 0.0, 1.0) : 0.0)
if wtVol > 0
ws += wtVol
ss += wtVol * (na(relV) ? 0.5 : f_cl(relV / 2.0, 0.0, 1.0))
if wtBody > 0
ws += wtBody
ss += wtBody * (cDir == d ? bR : 0.0)
if wtVw > 0
ws += wtVw
ss += wtVw * (vSide == d ? 1.0 : 0.0)
if wtDay > 0
ws += wtDay
ss += wtDay * (dSide == d ? 1.0 : dSide == 0 ? 0.5 : 0.0)
if wt30 > 0
ws += wt30
ss += wt30 * (lBias == d ? 1.0 : lBias == 0 ? 0.5 : 0.0)
if wtEma > 0 and emaOn
ws += wtEma
ss += wtEma * (emaDir == d ? 1.0 : 0.0)
if wtReg > 0
ws += wtReg
ss += wtReg * (regime == 1 or regime == 2 ? 1.0 : regime == 0 ? 0.5 : regime == 3 ? 0.3 : 0.5)
ws > 0 ? 100.0 * ss / ws : 0.0
float scU = na(upB) ? na : f_score(1)
float scD = na(dnB) ? na : f_score(-1)
var int cntUp = 0
var int cntDn = 0
var int dayBrk = 0
var string why = "–"
if rthStart
cntUp := 0
cntDn := 0
dayBrk := 0
bool vOk = not eRv or na(relV) or relV >= eRvMin
bool brkUp = false
bool brkDn = false
bool candUp = false
bool candDn = false
if chk and barstate.isconfirmed and not na(upB) and sinceOpen >= eFirst
candUp := close > upB
candDn := close < dnB
int pu = cntUp
int pd = cntDn
cntUp := close > upB ? (vOk ? cntUp + 1 : cntUp) : 0
cntDn := close < dnB ? (vOk ? cntDn + 1 : cntDn) : 0
brkUp := cntUp >= eConf and pu < eConf
brkDn := cntDn >= eConf and pd < eConf
if (candUp or candDn) and not vOk
why := "volume " + (na(relV) ? "–" : str.tostring(relV, "#.##") + "×") + " < " + str.tostring(eRvMin, "#.#") + "×"
dayBrk := brkUp ? 1 : brkDn ? -1 : dayBrk
bool prevUp = sigMode == "Intrabar preview" and not barstate.isconfirmed and inRth and not na(upB) and close > upB
bool prevDn = sigMode == "Intrabar preview" and not barstate.isconfirmed and inRth and not na(dnB) and close < dnB
// retest (optional)
var int rtDir = 0
var int rtBar = na
bool rtUp = false
bool rtDn = false
if barstate.isconfirmed and inRth
if rtDir != 0 and bar_index - rtBar > retestN
rtDir := 0
why := "retest expired"
if rtDir == 1 and not na(upB) and low <= upB and close > upB and bar_index > rtBar
rtUp := true
rtDir := 0
else if rtDir == -1 and not na(dnB) and high >= dnB and close < dnB and bar_index > rtBar
rtDn := true
rtDir := 0
if retestOn and brkUp
rtDir := 1
rtBar := bar_index
else if retestOn and brkDn
rtDir := -1
rtBar := bar_index
if rthStart
rtDir := 0
// =============================================================================
// 11 · TRADE STATE & TRAILING ENGINE (indicator signals, not orders)
// =============================================================================
var int pos = 0
var float ent = na
var float stp = na
var float tgt = na
var float entBw = na
var int lastExit = -1000
var int tN = 0
var int tW = 0
var float tNet = 0.0
float trailNow = na
int sigEvt = 0 // 1 long, -1 short
int exEvt = 0 // 1 exit
float exPx = na
float sigSc = na
float cost = costTk * syminfo.mintick
bool trigUp = retestOn ? rtUp : brkUp
bool trigDn = retestOn ? rtDn : brkDn
if mOn and barstate.isconfirmed and inRth and not na(upB)
// exits first
if pos != 0
bool lg = pos == 1
float tr = lg ? math.max(upB, vwap) : math.min(dnB, vwap)
if beOn and atrSt and not na(entBw) and (lg ? high >= ent + beK * entBw : low <= ent - beK * entBw)
stp := lg ? math.max(stp, ent) : math.min(stp, ent)
bool hS = atrSt and (lg ? low <= stp : high >= stp)
bool hT = tgtOn and (lg ? high >= tgt : low <= tgt)
bool xV = exVw and chk and (lg ? close < tr : close > tr)
bool xB = exBand and (lg ? close < upB : close > dnB)
bool xO = exOpp and (lg ? trigDn : trigUp)
if hS or hT or xV or xB or xO or rthLast
exPx := hS ? stp : hT ? tgt : close
float pts = (exPx - ent) * pos - cost
tN += 1
tW += pts > 0 ? 1 : 0
tNet += pts
pos := 0
exEvt := 1
lastExit := bar_index
else
trailNow := tr
// entries
bool timeOk = sinceOpen >= eFirst and not rthLast
bool coolOk = bar_index - lastExit >= eCool
bool htfOkU = not htfOn or htfDir == 1
bool htfOkD = not htfOn or htfDir == -1
if pos == 0 and timeOk
if trigUp and showL
if not coolOk
why := "cooldown"
else if not htfOkU
why := "HTF trend down"
else if scU < eScMin
why := "score " + str.tostring(scU, "#") + " < " + str.tostring(eScMin)
else
pos := 1
sigEvt := 1
sigSc := scU
else if trigDn and showS
if not coolOk
why := "cooldown"
else if not htfOkD
why := "HTF trend up"
else if scD < eScMin
why := "score " + str.tostring(scD, "#") + " < " + str.tostring(eScMin)
else
pos := -1
sigEvt := -1
sigSc := scD
if sigEvt != 0
ent := close
entBw := sigEvt == 1 ? bwU : bwD
stp := ent - sigEvt * atrK * atr
tgt := ent + sigEvt * tgtK * entBw
trailNow := sigEvt == 1 ? math.max(upB, vwap) : math.min(dnB, vwap)
if not inRth
pos := 0
// VWAP trail trades (STRYK:IM module)
var int vp = 0
var float vEnt = na
var int vN = 0
var int vW = 0
var float vNet = 0.0
int vEvt = 0
if mOn and mTrail and inRth and barstate.isconfirmed and not na(vwap)
float tb = tvBuf * syminfo.mintick
bool flip = (vp == 1 and close < vwap - tb) or (vp == -1 and close > vwap + tb)
if (flip or rthLast) and vp != 0
float pts = (close - vEnt) * vp - cost
vN += 1
vW += pts > 0 ? 1 : 0
vNet += pts
vp := 0
vEvt := 3
bool okT = sinceOpen >= eFirst and sinceOpen <= tvLast and not rthLast
bool every = tvMode == "Every VWAP cross"
if vp == 0 and okT
if close > vwap + tb and (every or dayBrk == 1)
vp := 1
vEnt := close
vEvt := 1
else if close < vwap - tb and (every or dayBrk == -1)
vp := -1
vEnt := close
vEvt := -1
if not inRth
vp := 0
// =============================================================================
// 14 · FOLLOW-THROUGH & PERFORMANCE ENGINE (observed signal behaviour)
// =============================================================================
type FtStats
int n = 0
int hit = 0
int fail = 0
int amb = 0
int unres = 0
float mfe = 0.0
float mae = 0.0
int tBars = 0
var FtStats ftL = FtStats.new()
var FtStats ftS = FtStats.new()
var array<int> rgN = array.new_int(4, 0)
var array<int> rgH = array.new_int(4, 0)
var int fDir = 0
var float fLvl = na
var float fBw = na
var float fTgt = na
var int fBar = na
var int fReg = -1
var float fMfe = 0.0
var float fMae = 0.0
int fEvt = 0 // 1 hit, 2 failed, 3 ambiguous, 4 unresolved
if ftOn and mOn and barstate.isconfirmed
if fDir != 0 and bar_index > fBar
bool lg = fDir == 1
fMfe := math.max(fMfe, lg ? (high - fLvl) / fBw : (fLvl - low) / fBw)
fMae := math.max(fMae, lg ? (fLvl - low) / fBw : (high - fLvl) / fBw)
bool hit = lg ? high >= fTgt : low <= fTgt
bool bad = inRth and (lg ? (not na(upB) and close < upB) : (not na(dnB) and close > dnB))
bool end = not inRth or rthLast
if hit or bad or end
fEvt := hit and bad ? 3 : hit ? 1 : bad ? 2 : 4
FtStats st = lg ? ftL : ftS
if fEvt == 4
st.unres := st.unres + 1
else
st.n := st.n + 1
st.mfe := st.mfe + fMfe
st.mae := st.mae + fMae
if fEvt == 1
st.hit := st.hit + 1
st.tBars := st.tBars + bar_index - fBar
else if fEvt == 2
st.fail := st.fail + 1
else
st.amb := st.amb + 1
if fReg >= 0
rgN.set(fReg, rgN.get(fReg) + 1)
rgH.set(fReg, rgH.get(fReg) + (fEvt == 1 ? 1 : 0))
fDir := 0
if fDir == 0 and (brkUp or brkDn)
fDir := brkUp ? 1 : -1
fLvl := brkUp ? upB : dnB
fBw := math.max(brkUp ? bwU : bwD, syminfo.mintick)
fTgt := fLvl + fDir * ftK * fBw
fBar := bar_index
fReg := regime
fMfe := 0.0
fMae := 0.0
// =============================================================================
// 16 · IMPROVED HTF DELTA CANDLE ENGINE
// value area of the last N completed HTF candles + distance, acceptance, size,
// POC migration, delta — gated by momentum, trend (EMA + 23h session delta) and fuel
// =============================================================================
bool hdIntra = hdSrc == "Intrabar 1-min, fall back to estimate"
string hdLtf = hdIntra and timeframe.in_seconds() > 60 ? "1" : timeframe.period
[iO, iC, iV] = request.security_lower_tf(syminfo.tickerid, hdLtf, [open, close, volume])
float vol0 = nz(volume)
float dBar = high > low ? vol0 * ((close - low) - (high - close)) / (high - low) : close > open ? vol0 : close < open ? -vol0 : 0.0
if hdIntra and iC.size() > 0
float sIn = 0.0
for i = 0 to iC.size() - 1
float o1 = iO.get(i)
float c1 = iC.get(i)
float w1 = nz(iV.get(i))
sIn += c1 > o1 ? w1 : c1 < o1 ? -w1 : 0.0
dBar := sIn
// profile of HTF candles off .. off+n-1 (runs in the HTF context): [POC, VAH, VAL]
f_vaProf(int off, int n) =>
int R = 40
float lo = na
float hi = na
for i = off to off + n - 1
lo := na(lo) ? low[i] : math.min(lo, low[i])
hi := na(hi) ? high[i] : math.max(hi, high[i])
float poc = na
float vah = na
float val = na
if not na(lo) and hi > lo
float rh = (hi - lo) / R
array<float> rv = array.new_float(R, 0.0)
float tot = 0.0
for i = off to off + n - 1
float v = nz(volume[i])
if v > 0 and not na(low[i])
int r0 = math.max(0, math.min(R - 1, int((low[i] - lo) / rh)))
int r1 = math.max(0, math.min(R - 1, int((high[i] - lo) / rh)))
float sh = v / (r1 - r0 + 1)
for r = r0 to r1
rv.set(r, rv.get(r) + sh)
tot += v
if tot > 0
int pr = rv.indexof(rv.max())
int up = pr
int dn = pr
float acc = rv.get(pr)
while acc < tot * ihVa / 100.0 and (up < R - 1 or dn > 0)
float vu = up < R - 1 ? rv.get(up + 1) : -1.0
float vd = dn > 0 ? rv.get(dn - 1) : -1.0
if vu >= vd
up += 1
acc += vu
else
dn -= 1
acc += vd
poc := lo + (pr + 0.5) * rh
vah := lo + (up + 1) * rh
val := lo + dn * rh
[poc, vah, val]
f_win() =>
[p0, h0, l0] = f_vaProf(1, ihN)
[p3, h3, l3] = f_vaProf(4, ihN)
[p0, h0, l0, p3]
[ihPoc, ihVah, ihVal, ihPocB] = request.security(syminfo.tickerid, ihTf, f_win(), lookahead = barmerge.lookahead_off)
// 23h session delta (17:00 CT) for the trend read
var float sessD = 0.0
if timeframe.change("D")
sessD := 0.0
float sessDNow = sessD + dBar
if barstate.isconfirmed
sessD += dBar
int sessDir = sessDNow > 0 ? 1 : sessDNow < 0 ? -1 : 0
// participation → fuel
float pVE = ta.ema(vol0, 10)
float prE = ta.percentrank(pVE, 100)
float prB = ta.percentrank(vol0, 100)
float part = math.max(nz(prE, 50.0), nz(prB, 50.0))
float bell = part >= ihPeak ? 1.0 : math.exp(-math.pow(part - ihPeak, 2) / (2.0 * ihBellW * ihBellW))
bool dAgree = (dBar > 0 and close >= open) or (dBar < 0 and close <= open)
float fuel = bell * (dAgree ? 1.0 : 0.6)
// acceptance: consecutive closes beyond the same edge
bool ihUp = not na(ihVah) and close > ihVah
bool ihDn = not na(ihVal) and close < ihVal
var int ihAcc = 0
int ihAccNow = ihUp or ihDn ? ((ihUp and ihUp[1]) or (ihDn and ihDn[1]) ? ihAcc + 1 : 1) : 0
if barstate.isconfirmed
ihAcc := ihAccNow
float volSma = ta.sma(vol0, 20)
float momN = atr > 0 ? (close - close[ihMomLen]) / atr : 0.0
// final colour + a read-out for the dashboard
f_ramp4(float t, color n, color a, color b, color c) => t <= 0.33 ? color.from_gradient(t, 0.0, 0.33, n, a) : t <= 0.66 ? color.from_gradient(t, 0.33, 0.66, a, b) : color.from_gradient(t, 0.66, 1.0, b, c)
color ihCol = cInside
float ihT = 0.0
string ihTxt = "no value area yet"
if not na(ihPoc) and ihVah > ihVal
float w = ihVah - ihVal
if ihUp or ihDn
int d = ihUp ? 1 : -1
float dist = math.min(1.0, (ihUp ? close - ihVah : ihVal - close) / math.max(syminfo.mintick, w * ihRamp / 100.0))
float accF = math.min(1.0, ihAccNow / 3.0)
float rvB = volSma > 0 ? vol0 / volSma : 1.0
float sizF = f_cl((rvB - 1.0) / 1.0, 0.0, 1.0)
float mig = na(ihPocB) ? 0.0 : (ihPoc - ihPocB) / w
float migF = mig * d > 0 ? math.min(1.0, math.abs(mig)) : 0.0
float t = (dist + (accF + sizF + migF) / 3.0) / 2.0
t := t + (math.sign(dBar) == d ? 0.15 : -0.15)
bool momOk = momN * d >= ihMomK
if ihMomOn and not momOk
t := math.min(t, ihCap)
int tAl = (emaDir == d ? 1 : 0) + (sessDir == d ? 1 : 0)
if ihTrOn
t := t * (1.0 + ihTrB * (tAl - 1))
if ihFuOn
t := t * (0.5 + 0.5 * fuel)
ihT := f_cl(t, 0.0, 1.0)
ihCol := d == 1 ? f_ramp4(ihT, cInside, cB1, cB2, cB3) : f_ramp4(ihT, cInside, cR1, cR2, cR3)
ihTxt := (d == 1 ? "above VA" : "below VA") + " · mom " + (momOk ? "✓" : "✗") + " · trend " + str.tostring(tAl) + "/2 · fuel " + str.tostring(fuel * 100, "#") + "%"
else
float halfW = math.max(syminfo.mintick, math.max(ihVah - ihPoc, ihPoc - ihVal))
float lean = ihLean * math.min(1.0, math.abs(close - ihPoc) / halfW)
ihCol := close >= ihPoc ? color.from_gradient(lean, 0, 1, cInside, cB1) : color.from_gradient(lean, 0, 1, cInside, cR1)
ihTxt := "inside value · " + (close >= ihPoc ? "above" : "below") + " POC " + str.tostring(ihPoc, format.mintick)
// =============================================================================
// 13 · VISUAL RENDERING ENGINE
// =============================================================================
bool vis = mOn
// noise bands
bool onLn = inRth or (extLn and not na(dOpen))
float upX = inRth ? upB : lastUp
float dnX = inRth ? dnB : lastDn
bool sb = vis and showBands and onLn
pU = plot(sb ? upX : na, "Noise upper", cBandUp, wBand, bandSty == "Circles" ? plot.style_circles : bandSty == "Cross" ? plot.style_cross : plot.style_linebr)
pD = plot(sb ? dnX : na, "Noise lower", cBandDn, wBand, bandSty == "Circles" ? plot.style_circles : bandSty == "Cross" ? plot.style_cross : plot.style_linebr)
color fTop = fillMode == "Gradient" ? color.new(cBandUp, fillT) : fillMode == "Regime colour" ? color.new(regCol, fillT) : na
color fBot = fillMode == "Gradient" ? color.new(cBandDn, fillT) : fillMode == "Regime colour" ? color.new(regCol, math.min(100, fillT + 6)) : na
fill(pU, pD, upX, dnX, fTop, fBot, "Noise area")
plot(sb and showMid ? (upX + dnX) / 2 : na, "Band centre", color.new(cSil, 50), 1, plot.style_linebr)
plot(vis and showOR and ((inRth and mOfDay >= orEnd) or (not inRth and extLn)) ? orH : na, "Opening range high", color.new(cRef, 30), 1, plot.style_linebr)
plot(vis and showOR and ((inRth and mOfDay >= orEnd) or (not inRth and extLn)) ? orL : na, "Opening range low", color.new(cRef, 30), 1, plot.style_linebr)
plot(vis and showPC and onLn ? prevClose : na, "Prior close", color.new(cRef, 55), 1, plot.style_circles)
// 08:30 VWAP: gradient by stretch, deviation bands with gradient fills
color cVwap = vwCol == "Side colours" ? (vSide >= 0 ? cB1 : cR1) : vZ >= 0 ? f_ramp(f_cl(vZ / 2.5, 0, 1), cSil, cB1, cB2) : f_ramp(f_cl(-vZ / 2.5, 0, 1), cSil, cR1, cR2)
plot(vis and showVw and (inRth or not vwRth) ? vwap : na, "08:30 VWAP", cVwap, wVw, plot.style_linebr)
bool sv = vis and showVwB and (inRth or not vwRth)
pVU1 = plot(sv ? vU1 : na, "VWAP +σ1", color.new(cB2, 60), 1, plot.style_linebr)
pVU2 = plot(sv ? vU2 : na, "VWAP +σ2", color.new(cB3, 45), 1, plot.style_linebr)
pVL1 = plot(sv ? vL1 : na, "VWAP −σ1", color.new(cR2, 60), 1, plot.style_linebr)
pVL2 = plot(sv ? vL2 : na, "VWAP −σ2", color.new(cR3, 45), 1, plot.style_linebr)
fill(pVU2, pVU1, vU2, vU1, color.new(cB3, vwBT), color.new(cB2, math.min(100, vwBT + 8)), "VWAP upper shading")
fill(pVL1, pVL2, vL1, vL2, color.new(cR2, math.min(100, vwBT + 8)), color.new(cR3, vwBT), "VWAP lower shading")
plot(vis and showSv ? sVw : na, "Session VWAP", cSv, 1, plot.style_linebr)
// EMA ribbon
float spr = atr > 0 ? (eF - eS) / atr : 0.0
color cRib = spr >= 0 ? f_ramp(f_cl(spr / 2, 0, 1), cSil, cB1, cB3) : f_ramp(f_cl(-spr / 2, 0, 1), cSil, cR1, cR3)
pEF = plot(vis and emaOn ? eF : na, "EMA fast", color.new(cSil, 55), 1)
pES = plot(vis and emaOn ? eS : na, "EMA slow", color.new(cGry, 55), 1)
fill(pEF, pES, color.new(cRib, emaT), "EMA ribbon")
// trail / stop
plot(vis and showStop and pos != 0 ? (atrSt ? stp : trailNow) : na, "Trail / stop", cStop, 1, plot.style_linebr)
// last 30m bias shading
bgcolor(vis and inLast and lBias != 0 ? color.new(lBias > 0 ? cB1 : cR1, lastT) : na, title = "Last 30m bias")
// candidate dots (confirmed checks + intrabar preview)
plotshape(vis and showCand and ((candUp and cntUp < eConf) or (prevUp and cntUp < eConf)) ? upB : na, "Candidate up", shape.circle, location.absolute, color.new(cB2, 30), size = size.tiny)
plotshape(vis and showCand and ((candDn and cntDn < eConf) or (prevDn and cntDn < eConf)) ? dnB : na, "Candidate down", shape.circle, location.absolute, color.new(cR2, 30), size = size.tiny)
// signal markers
if vis and sigEvt != 0
bool up = sigEvt == 1
float t = f_cl(sigSc / 100, 0, 1)
color c = up ? f_ramp(t, cB1, cB2, cB3) : f_ramp(t, cR1, cR2, cR3)
bool hc = sigSc >= hiConf
string tx = up ? (hc ? "▲▲" : "▲") : (hc ? "▼▼" : "▼")
tx += sigTag ? (up ? " LONG" : " SHORT") : ""
tx += showSc ? " " + str.tostring(sigSc, "#") : ""
tx += showVm and not na(relV) and relV >= eRvMin ? " ◆" : ""
tx += showPx ? "\n" + str.tostring(close, format.mintick) : ""
float y = up ? low - sigOff * syminfo.mintick : high + sigOff * syminfo.mintick
label.new(bar_index, y, tx, style = up ? label.style_label_up : label.style_label_down, color = color.new(c, 100),
textcolor = color.new(c, hc ? 0 : sigT), size = f_sz(sigSz))
if vis and exEvt != 0
label.new(bar_index, high + sigOff * syminfo.mintick, "■", style = label.style_label_down, color = color.new(cSil, 100), textcolor = color.new(cSil, 30), size = size.tiny)
if vis and showRej and fEvt == 2
label.new(bar_index, fDir == 0 and close > nz(upB, close) ? high : low, "✕", style = label.style_label_center, color = color.new(cGry, 100), textcolor = cGry, size = size.tiny)
if vis and mTrail and vEvt != 0
color cv = vEvt == 1 ? cB2 : vEvt == -1 ? cR2 : cGry
label.new(bar_index, vEvt == 1 ? low : high, vEvt == 1 ? "△" : vEvt == -1 ? "▽" : "□", style = vEvt == 1 ? label.style_label_up : label.style_label_down,
color = color.new(cv, 100), textcolor = cv, size = size.tiny)
// pattern labels (capped)
var array<label> patLabs = array.new<label>()
if vis and patLab and isPat and barstate.isconfirmed
color pc = patD > 0 ? cB1 : patD < 0 ? cR1 : cGold
patLabs.push(label.new(bar_index, patD >= 0 ? low : high, patNm, style = patD >= 0 ? label.style_label_up : label.style_label_down,
color = color.new(pc, 100), textcolor = color.new(pc, 20), size = size.tiny))
if patLabs.size() > patMax
label.delete(patLabs.shift())
// candle engine
color cc = na
if vis and cMode != "Original"
if cMode == "Improved HTF delta"
cc := ihCol
else if cMode == "Gradient momentum"
float t = f_cl(bAtr / 1.5, 0, 1)
cc := cDir > 0 ? f_ramp(t, cB1, cB2, cB3) : cDir < 0 ? f_ramp(t, cR1, cR2, cR3) : cSil
else if cMode == "Trend-coloured"
cc := vSide == 1 ? (vSlope == 1 ? cB2 : cB1) : vSide == -1 ? (vSlope == -1 ? cR2 : cR1) : cSil
else if cMode == "Volatility-coloured"
float t = f_cl(rAtr / 2.0, 0, 1)
cc := f_ramp(t, cCalm, cWarm, cHot)
else if cMode == "Pattern highlight"
cc := isPat ? cGold : color.new(cGry, 40)
else if cMode == "Signal confirmation"
cc := pos == 1 ? cB2 : pos == -1 ? cR2 : color.new(cGry, 30)
else
cc := sigEvt == 1 ? cB2 : sigEvt == -1 ? cR2 : cDir > 0 ? cSil : cGry
bool paintFull = paintM == "Full candle (body + wick + border)"
color ccB = vis and cMode != "Original" ? color.new(cc, candT) : na
barcolor(not paintFull ? ccB : na, title = "Candle engine (bodies)")
plotcandle(open, high, low, close, "Candle engine (full)", color = paintFull ? ccB : na, wickcolor = paintFull ? ccB : na, bordercolor = paintFull ? ccB : na)
// =============================================================================
// 15 · ALERT ENGINE (bar close; an alert is not an executed order)
// =============================================================================
// one "Any alert() function call" alert covers every event below (alertcondition() would cost plot slots)
string aPx = " @ " + str.tostring(close, format.mintick) + " · regime " + regTxt
if mOn and barstate.isconfirmed
if aCand and ((candUp and cntUp < eConf) or (candDn and cntDn < eConf))
alert("STRYK:IM PRO " + syminfo.ticker + " — " + (candUp ? "long" : "short") + " breakout candidate" + aPx, alert.freq_once_per_bar_close)
if sigEvt != 0 and (aConf or (aHiC and sigSc >= hiConf))
alert("STRYK:IM PRO " + syminfo.ticker + " — " + (sigSc >= hiConf ? "HIGH-CONFLUENCE " : "confirmed ") + (sigEvt == 1 ? "LONG" : "SHORT") + " · score " + str.tostring(sigSc, "#") + aPx, alert.freq_once_per_bar_close)
if aFail and fEvt == 2
alert("STRYK:IM PRO " + syminfo.ticker + " — breakout FAILED (closed back inside the band)" + aPx, alert.freq_once_per_bar_close)
if aRt and (rtUp or rtDn)
alert("STRYK:IM PRO " + syminfo.ticker + " — " + (rtUp ? "long" : "short") + " retest confirmed" + aPx, alert.freq_once_per_bar_close)
if aExit and exEvt == 1
alert("STRYK:IM PRO " + syminfo.ticker + " — signal trade closed at " + str.tostring(exPx, format.mintick), alert.freq_once_per_bar_close)
if aTrd and (dSide != dSide[1] or emaDir != emaDir[1])
alert("STRYK:IM PRO " + syminfo.ticker + " — trend changed: daily " + (dSide > 0 ? "up" : dSide < 0 ? "down" : "flat") + " · EMA " + (emaDir > 0 ? "up" : emaDir < 0 ? "down" : "flat"), alert.freq_once_per_bar_close)
if aReg and regime != regime[1] and regime >= 0
alert("STRYK:IM PRO " + syminfo.ticker + " — volatility regime: " + regTxt, alert.freq_once_per_bar_close)
// =============================================================================
// 12 · DASHBOARD
// =============================================================================
var table tb = table.new(position.bottom_right, 3, 44)
f_c(int c, int r, string s, color tc, color bg) =>
table.cell(tb, c, r, s, text_color = tc, text_size = f_sz(tblSz), bgcolor = bg, text_halign = c == 0 ? text.align_left : text.align_center)
f_hd(int r, string s) =>
// stepped gradient header strip: bull → cyan → bear across the three columns
color h0 = color.new(cB1, 55)
color h1 = color.new(cB3, 55)
color h2 = color.new(cR3, 55)
f_c(0, r, s, #FFFFFF, h0)
f_c(1, r, "", #FFFFFF, h1)
f_c(2, r, "", #FFFFFF, compact ? na : h2)
f_dc(int d) => d > 0 ? cB1 : d < 0 ? cR1 : cGry
f_dt(int d) => d > 0 ? "▲ up" : d < 0 ? "▼ down" : "– flat"
f_pct(int a, int b) => b > 0 ? str.tostring(100.0 * a / b, "#") + "%" : "–"
if barstate.islast
table.clear(tb, 0, 0, 2, 43)
table.set_position(tb, f_pos(tblPos))
table.set_border_color(tb, cTbBd)
table.set_border_width(tb, wTbBd)
table.set_frame_color(tb, cTbFr)
table.set_frame_width(tb, wTbFr)
if mOn and tblOn
color bg = color.new(cTbBg, tbT)
color dim = color.new(cTbTx, 35)
int r = 0
if secCore
f_hd(r, "STRYK:IM PRO · " + preset)
r += 1
int tdir = dSide + emaDir + (htfOn ? htfDir : 0)
f_c(0, r, "Trend", cTbTx, bg)
f_c(1, r, f_dt(tdir), f_dc(tdir), bg)
f_c(2, r, compact ? "" : "daily " + f_dt(dSide) + " · EMA " + f_dt(emaDir) + (htfOn ? " · HTF " + f_dt(htfDir) : ""), dim, bg)
r += 1
f_c(0, r, "HTF delta candle", cTbTx, bg)
f_c(1, r, ihUp ? "▲ above VA" : ihDn ? "▼ below VA" : "inside VA", ihCol, bg)
f_c(2, r, compact ? "" : ihTxt + (ihUp or ihDn ? " · strength " + str.tostring(ihT * 100, "#") + "%" : ""), dim, bg)
r += 1
string bs = pos != 0 ? (pos == 1 ? "LONG active" : "SHORT active") : rtDir != 0 ? "retest pending" : cntUp >= eConf ? "confirmed ▲ · " + str.tostring(cntUp) + " checks" : cntDn >= eConf ? "confirmed ▼ · " + str.tostring(cntDn) + " checks" : cntUp > 0 ? "candidate ▲ " + str.tostring(cntUp) + "/" + str.tostring(eConf) : cntDn > 0 ? "candidate ▼ " + str.tostring(cntDn) + "/" + str.tostring(eConf) : dayBrk != 0 ? (dayBrk == 1 ? "broke ▲ today" : "broke ▼ today") : "inside band"
f_c(0, r, "Breakout", cTbTx, bg)
f_c(1, r, bs, pos == 1 or (pos == 0 and dayBrk == 1) ? cB2 : pos == -1 or (pos == 0 and dayBrk == -1) ? cR2 : cSil, bg)
f_c(2, r, compact ? "" : na(lastUp) ? "building history" : "band " + str.tostring(nz(dnB, lastDn), format.mintick) + " – " + str.tostring(nz(upB, lastUp), format.mintick), dim, bg)
r += 1
f_c(0, r, "Regime", cTbTx, bg)
f_c(1, r, regTxt, regCol, bg)
f_c(2, r, compact ? "" : na(orRatio) ? "opening range not complete" : "OR " + str.tostring(orRatio, "#.##") + "× normal · band ×" + str.tostring(fac, "#.##"), dim, bg)
r += 1
f_c(0, r, "08:30 VWAP", cTbTx, bg)
f_c(1, r, f_dt(vSide), f_dc(vSide), bg)
f_c(2, r, compact ? "" : str.tostring(vZ, "#.##") + "σ · slope " + (vSlope > 0 ? "▲" : vSlope < 0 ? "▼" : "–"), dim, bg)
r += 1
f_c(0, r, "Score ▲ / ▼", cTbTx, bg)
f_c(1, r, (na(scU) ? "–" : str.tostring(scU, "#")) + " / " + (na(scD) ? "–" : str.tostring(scD, "#")), cGold, bg)
f_c(2, r, compact ? "" : "min " + str.tostring(eScMin) + " · high ≥ " + str.tostring(hiConf), dim, bg)
r += 1
f_c(0, r, "Rel. volume", cTbTx, bg)
f_c(1, r, na(relV) ? "–" : str.tostring(relV, "#.##") + "×", na(relV) ? cGry : relV >= eRvMin ? cB2 : cSil, bg)
f_c(2, r, compact ? "" : "same time of day · filter " + (eRv ? "on" : "off"), dim, bg)
r += 1
f_c(0, r, "Trade", cTbTx, bg)
f_c(1, r, pos == 1 ? "LONG" : pos == -1 ? "SHORT" : "flat", f_dc(pos), bg)
f_c(2, r, compact ? "" : pos != 0 ? "in " + str.tostring(ent, format.mintick) + " · " + (atrSt ? "stop " + str.tostring(stp, format.mintick) : "trail " + str.tostring(trailNow, format.mintick)) : str.tostring(tN) + " trades · " + f_pct(tW, tN) + " win · " + str.tostring(tNet, "#.##") + " pts", dim, bg)
r += 1
f_c(0, r, "Band width", cTbTx, bg)
f_c(1, r, na(lastBwU) ? "–" : str.tostring(nz(bwU, lastBwU), format.mintick) + " / " + str.tostring(nz(bwD, lastBwD), format.mintick), cSil, bg)
f_c(2, r, compact ? "" : "history " + str.tostring(math.min(inRth ? slotN : lastSlotN, nDays)) + "/" + str.tostring(nDays) + " · " + eStat, dim, bg)
r += 1
if secPerf and ftOn
f_hd(r, "PERFORMANCE · follow-through " + str.tostring(ftK, "#.##") + "× band")
r += 1
int nAll = ftL.n + ftS.n
f_c(0, r, "Events", cTbTx, bg)
f_c(1, r, str.tostring(nAll), cSil, bg)
f_c(2, r, compact ? "" : "▲ " + str.tostring(ftL.n) + " · ▼ " + str.tostring(ftS.n) + (nAll < ftMinN ? " · low n" : ""), nAll < ftMinN ? cWarm : dim, bg)
r += 1
f_c(0, r, "Long hit", cTbTx, bg)
f_c(1, r, f_pct(ftL.hit, ftL.n), cB2, bg)
f_c(2, r, compact ? "" : "fail " + f_pct(ftL.fail, ftL.n) + " · ambiguous " + str.tostring(ftL.amb), dim, bg)
r += 1
f_c(0, r, "Short hit", cTbTx, bg)
f_c(1, r, f_pct(ftS.hit, ftS.n), cR2, bg)
f_c(2, r, compact ? "" : "fail " + f_pct(ftS.fail, ftS.n) + " · ambiguous " + str.tostring(ftS.amb), dim, bg)
r += 1
f_c(0, r, "Overall", cTbTx, bg)
f_c(1, r, f_pct(ftL.hit + ftS.hit, nAll), cGold, bg)
f_c(2, r, compact ? "" : "unresolved " + str.tostring(ftL.unres + ftS.unres) + " (not counted)", dim, bg)
r += 1
int hits = ftL.hit + ftS.hit
f_c(0, r, "MFE / MAE", cTbTx, bg)
f_c(1, r, nAll > 0 ? str.tostring((ftL.mfe + ftS.mfe) / nAll, "#.##") + " / " + str.tostring((ftL.mae + ftS.mae) / nAll, "#.##") : "–", cSil, bg)
f_c(2, r, compact ? "" : "avg band-widths · time to target " + (hits > 0 ? str.tostring((ftL.tBars + ftS.tBars) / hits, "#.#") + " bars" : "–"), dim, bg)
r += 1
if secReg and ftOn
f_hd(r, "MARKET REGIME · hit rate")
r += 1
for k = 0 to 3
string nm = k == 0 ? "Quiet" : k == 1 ? "Normal" : k == 2 ? "Elevated" : "Extreme"
color rc = k == 0 ? cCalm : k == 1 ? color.from_gradient(0.5, 0, 1, cCalm, cWarm) : k == 2 ? cWarm : cHot
f_c(0, r, nm + (k == regime ? " ◀" : ""), rc, bg)
f_c(1, r, f_pct(rgH.get(k), rgN.get(k)), cSil, bg)
f_c(2, r, compact ? "" : "n " + str.tostring(rgN.get(k)), dim, bg)
r += 1
if secIdea
f_hd(r, "IDEAS")
r += 1
f_c(0, r, "First 30m → last 30m", cTbTx, bg)
f_c(1, r, f_dt(lBias), f_dc(lBias), bg)
f_c(2, r, compact ? "" : na(r30) ? "set after the first 30 minutes" : str.tostring(r30 * 100, "#.##") + "% · final 30 minutes", dim, bg)
r += 1
if mTrail
f_c(0, r, "VWAP trail", cTbTx, bg)
f_c(1, r, vp == 1 ? "LONG" : vp == -1 ? "SHORT" : "flat", f_dc(vp), bg)
f_c(2, r, compact ? "" : str.tostring(vN) + " trades · " + f_pct(vW, vN) + " win · " + str.tostring(vNet, "#.##") + " pts net", dim, bg)
r += 1
if dbg
f_hd(r, "DIAGNOSTICS")
r += 1
f_c(0, r, "Session", cTbTx, bg)
f_c(1, r, inRth ? "cash open" : "closed", inRth ? cB1 : cGry, bg)
f_c(2, r, "open " + str.tostring(openMin) + " · close " + str.tostring(closeMin) + " min · " + tzIn, dim, bg)
r += 1
f_c(0, r, "History", cTbTx, bg)
f_c(1, r, str.tostring(slots.size()) + " slots", cSil, bg)
f_c(2, r, "this slot " + str.tostring(slotN) + "/" + str.tostring(nDays) + " · OR days " + str.tostring(orHist.size()), dim, bg)
r += 1
f_c(0, r, "Last skip", cTbTx, bg)
f_c(1, r, why, cWarm, bg)
f_c(2, r, "conf " + str.tostring(eConf) + " · vol " + (eRv ? str.tostring(eRvMin, "#.#") + "×" : "off") + " · retest " + (retestOn ? "on" : "off"), dim, bg)
r += 1