//@version=6 // ╔═══════════════════════════════════════════════════════════════════════════════════╗ // ║ Gex and EFP Basis Matrix | GEX+ALMA+AMT Sovereign+MLMI+SMI+g3+YZsqz | XAUUSD ║ // ║ Pine Script v6 | CE:0 RE:0 CW:0 | BUDGET: 19/64u declared ~64/64u total ║ // ║ Production Grade: CME/COMEX + LBMA Gold Desk Standard ║ // ╚═══════════════════════════════════════════════════════════════════════════════════╝ // // CHANGES v29 → v30 (17 Sep 2026 · LEVEL-1 FIXES · 0 plot-budget · defaults = user's live H1 settings (TFH1 build)) // ───────────────────────────────────────────────────────────────────────────────── // [v30-1] GVZ spike/crisis z-score is now computed INSIDE the daily request (was a 20-chart-bar // z-score over a series that is constant intraday → fired ≈ every day GVZ ticked up). // [v30-2] Delayed GC1! guard: request the futures bar time; when the futures print lags the chart // by > 2 bars in realtime, the basis is HELD at its last value and the regime label shows // 'GC1! delayed' (was: live basis absorbed 10–15 min of gold movement → fake ARB/DIV/Frozen). // [v30-3] Sessions are evaluated in America/New_York (values 20/03/08/17 were NY clock times but // were read as UTC → no DST, 7-h Asia block mislabelled). LBMA fix windows in Europe/London. // [v30-4] CONF: 'frame' terms retired (frame ≥ 6.5 ATR by construction → +10 always, −20 never); // base moved 50 → 60 so the CONF scale is unchanged. frame_ok gates retired (always true). // [v30-5] MLMI neutral bypass only during warm-up (memory < k), not on any prediction tie. // Inputs: defaults set to the user's live H1 values (TFH1 build) (read off the chart 17 Sep 2026); Style-tab // overrides that code can express (hidden plots, widths) are applied in the plot calls. // ───────────────────────────────────────────────────────────────────────────────── // CHANGES v28 → v29 (all DISPLAY-ONLY · 0 plot-budget · file stays 63/64) // ───────────────────────────────────────────────────────────────────────────────── // [v29-1] §19 ACTION AUTO-FLIP on Γ conflict — the headline verb now FLIPS // (FOLLOW↔FADE/RANGE, MR-FADE↔FOLLOW/BREAK) + route + colour when // the Γ-proxy strongly overrides the direction cell (|Γ-score| ≥ // i_rm_gth), with i_rm_hyst-bar hysteresis to kill flicker. Toggle // i_rm_autoflip (default ON). OFF = v28 (headline stays, ⚠ tag only). // Same info — removes the mis-read that "FOLLOW + Γ⚠fade-risk" caused. // [v29-2] §19 ADX/DI rows (i_rm_adx, default OFF) — ta.dmi → 2 table rows (ADX strength // + DI± direction). ⚠ read WITH DI, never a lone gate (ER lesson). // [v29-3] §19c DEEP-FIB PREMIUM/DISCOUNT (i_rm_fib, default OFF) — swing range split into // PREMIUM(upper/sell) / DISCOUNT(lower/buy) + deep 0.705–0.886 zones // (Kmer 'trade from discount'). box/line/label only. Isolated block. // All three: own toggles, own prefixes, NO existing logic touched, // NO plot/fill/alert added → no RE10140 risk. // // CHANGES v27 → v28 // ───────────────────────────────────────────────────────────────────────────────── // [v28-1] §19 REGIME MATRIX + Γ-PROXY — NEW, group ⑳. DISPLAY-ONLY (one table → 0 // plot-budget; file stays 63/64). Unifies Direction × Volatility // into the 6-regime matrix (Bull/Sideways/Bear × Quiet/Volatile) // with a per-cell prescription (follow full / ×0.6 / MR-fade @VA / // STAND ASIDE / preserve ×0.5) + EA routing. Direction = close vs // EMA200 baseline + slope; Volatility = YZ ratio expansion / GVZ // elevated-extreme. Plus a POS/NEG-GAMMA PROXY (NOT real dealer // gamma — gold has no options chain; a vol-behaviour footprint): // 5 orthogonal votes → signed Γ-score → // VarianceRatio VR(k) (replaces Hurst) · RV−GVZ (realized vs // implied) · YZ fast/slow · trend-efficiency ER · vs g1 flip. // pos-Γ = vol dampening → fade/failed BO; neg-Γ = amplifying → // follow/trend. Γ tag flags fade-vs-trend conflict on the action. // Black table bg (default), adjustable size + position (default // Top Left). Toggle i_rm_on. NOT entry — no gate/conf_score touched // (port to gate → walk-forward OOS first). M5 defaults. // // CHANGES v26 → v27 // ───────────────────────────────────────────────────────────────────────────────── // [v27-1] §16c EXPANSION SCORE + MR-INTO-TREND — NEW, group ⑲. DISPLAY-ONLY. // Two reads from the "3 primitives" framework, as labels only: // • EXPANSION = breakout trigger — bar range ≥ i_exp_thr × the // i_exp_len-bar average range → "EXP▲/▼ N×" marker (dir by // candle). The volatility-expansion counterpart to the ⑰ squeeze // (compression) detector. // • MR-INTO-TREND = buy-the-dip WITH the trend — inside regime ±1, // price retests the g1 flip level (broken resistance→support in an // uptrend / support→resistance in a downtrend) → "MR→trend BUY/ // SELL" label + pullback-depth% in tooltip (deeper = higher prob). // The systematic answer to "never fade AGAINST the trend": this // fades TOWARD it. // Uses only label.new (0 plot-budget — file is at 63/64). Dedup via // i_dedup; expansion fires on fresh onset only. Toggles: i_xmt_on + // i_exp_lbl / i_mrt_lbl. NOT an entry — no gate/conf_score touched // (any port to entry logic → walk-forward OOS first). M5 defaults. // // CHANGES v25 → v26 // ───────────────────────────────────────────────────────────────────────────────── // [v26-1] §11b BUBBLE CONTEXT ENGINE (LTF Position → AMT event) — NEW, group ⑬b. // Upgrades the ⑫ volume bubbles: previously they only reported // size + BUY/SELL side. Now, on each classified bubble bar, the // engine pulls lower-TF intrabar bars (request.security_lower_tf), // bins them into the candle's high→low range, finds the volume POC // (the intrabar cluster), reads the net delta AT that cluster, and // combines {candle direction × cluster side × cluster position} to // NAME the event exactly per the AMT reference cards: // Bullish candle → cluster TOP+sell = rejection · TOP+buy = // abs-contrarian (both bearish/red) · MID buy = acceptance buy · // BOT sell = abs-continue (both bullish/green). // Bearish candle = mirror image. // Draws: (a) a position DOT at the true cluster price (colored by // cluster side buy/sell), (b) a CONTEXT LABEL naming the pattern, // colored by OUTCOME (green=bullish, red=bearish), placed below the // low (bullish outcome) / above the high (bearish outcome). // Toggles: master (i_bctx_on), labels (i_bctx_lbl), dot (i_bctx_dot), // LTF res (i_bctx_ltf, def "1"), bins (20), top/bot zone (.66/.34), // size gate (Medium+), colors, size, side-arrow. M5 defaults. // + 2 alerts (reversal UP / DOWN). DISPLAY-ONLY: touches no gate / // conf_score / entry logic (any port to entry → walk-forward OOS). // Proxy caveat: LTF wick-weighted delta = eyes, not a validated edge. // // CHANGES v24 → v25 // ───────────────────────────────────────────────────────────────────────────────── // [v25-1] §12 AMT ACCEPTANCE LABELS: "Accept Buy" / "Accept Sell" text labels added // alongside the existing "●" dot for ACCEPTANCE BUY/SELL patterns. // Text uses size.tiny (matches normal chart labels). Dot (●) at // _emj_sz_resolved unchanged. Text label added to _amt_lbs array // (cap 400 preserved). // [v25-2] INPUT DEFAULTS updated to match preferred configuration: // EFP Basis Mode: SESSION (was ORIGINAL) // PBV L1: 1.71% (was 2.150%), PBV L2: 2.1278% (was 3.414%), // PBV L3: 3.618% (was 3.730%) // Explosion (g3): 5.0 (was 4.236) // CB Signal Gate: true (was false) // Show gFlip g1 Labels: false (was true) // Show SpotEx ATM: false (was true) // Show Gamma Wall Labels: false (was true) // Show Explosion Labels: false (was true) // Show PHI System: false (was true) // Show EM +/-2sigma: true (was false) // ALMA L1/L2/L3 Width: 1 (was 2) // QA Small Percentile: 90 (was 75), Medium Percentile: 93 (was 90) // Show Small Clusters: false (was true) // // CHANGES v23 → v24 (prior changelog preserved) // ───────────────────────────────────────────────────────────────────────────────── // [v23-1] §14 : Squeeze false-positive filters added (2-layer) // Filter 1: Min Compression Duration — sqz_dur[1] >= i_sqz_min_dur // Filter 2: YZ Ratio Expansion Confirmation — _yz_ratio > _yz_ratio[1] // [v23-2] §17 : alert titles/messages updated // CHANGES v23 → v24 : max_boxes_count=500, MLMI array cap (preserved) // CHANGES v22 → v23 : Squeeze false-positive filters (preserved) // CHANGES v21 → v22 : YZ-based Squeeze Detector + 2 alerts (preserved) // CHANGES v18 → v21 : table fix, London VWAP reset, basis_cv abs, DXY filter, // cond_I/J dedup, GOFO input, COMEX CB tiers, ATR fallback, // Globex open, conf_score CB penalty (all preserved) // ───────────────────────────────────────────────────────────────────────────────── indicator( title = "Gex and EFP Basis Matrix v30 TFH1 | GEX+ALMA+AMT Sovereign+MLMI+SMI+g3+YZsqz+BubbleCtx+ExpMRT+RegimeMatrix | XAUUSD", shorttitle = "GEX+EFP Matrix v30 TFH1", overlay = true, max_lines_count = 500, max_labels_count = 500, max_boxes_count = 500, max_bars_back = 2000) // ═══════════════════════════════════════════════════════════════════════════════ // §1 INPUTS // ═══════════════════════════════════════════════════════════════════════════════ const string G_FEED = "① BASIS MATRIX" string i_efp_mode = input.string("SESSION","EFP Basis Mode",options=["ORIGINAL","SESSION","1-MINUTE"],group=G_FEED) string i_fut_sym = input.symbol("COMEX:GC1!","Futures Ticker (COMEX)",group=G_FEED) string i_gvz_sym = input.symbol("CBOE:GVZ", "GVZ Vol Index (CBOE)", group=G_FEED) int i_basis_len = input.int(200, "Basis SMA Length",group=G_FEED,minval=20) float i_block = input.float(25.0,"COMEX Strike Block ($)",group=G_FEED,step=5.0) float i_sd_mult = input.float(1.618,"SD Level phi (sigma)",group=G_FEED,step=0.001) float i_pbv_1 = input.float(1.71, "PBV L1 % (1.71)", group=G_FEED,step=0.001) float i_pbv_2 = input.float(2.1278,"PBV L2 % (2.1278)",group=G_FEED,step=0.001) float i_pbv_3 = input.float(3.618, "PBV L3 % (3.618)", group=G_FEED,step=0.001) float i_gofo_rate = input.float(4.20,"GOFO Rate % (1-month)",group=G_FEED,step=0.05,minval=0.0,maxval=20.0,tooltip="1-month Gold Forward Offered Rate. Update daily from LBMA GOFO page.") const string G_GEX = "② GEX PHYSICS (Yang-Zhang)" int i_vol_lb = input.int(233, "YZ Lookback (bars)", group=G_GEX, minval=50) float i_vol_mult = input.float(3.0, "Implied Vol Multiplier", group=G_GEX, step=0.1) string i_sigma_mode= input.string("FIBONACCI","sigma Level Mode",group=G_GEX,options=["FIBONACCI","GAUSSIAN"]) float i_g1 = input.float(0.618, "Zero Gamma Flip", group=G_GEX, step=0.001) float i_g2 = input.float(1.1278, "Gamma Wall", group=G_GEX, step=0.001) float i_g3 = input.float(1.887, "Explosion", group=G_GEX, step=0.001) float i_sig_floor = input.float(2.0, "Sigma Floor (xATR14)",group=G_GEX,step=0.1) const string G_VOL = "③ GVZ REGIME FILTER" bool i_gvz_en = input.bool(true, "Enable GVZ Filter",group=G_VOL) float i_gvz_norm = input.float(24.0,"GVZ Normal Threshold",group=G_VOL,step=1.0) float i_gvz_elev = input.float(32.0,"GVZ Elevated Threshold",group=G_VOL,step=1.0) float i_gvz_ext = input.float(42.0,"GVZ Extreme Threshold",group=G_VOL,step=1.0) const string G_DXY = "④ DXY MACRO FILTER" bool i_dxy_en = input.bool(true,"Enable DXY Filter",group=G_DXY) int i_dxy_roc = input.int(5,"DXY ROC Period (bars)",group=G_DXY,minval=2,maxval=20) float i_dxy_thr = input.float(0.3,"DXY ROC Threshold (%)",group=G_DXY,step=0.1) const string G_CB = "⑤ COMEX CIRCUIT BREAKER (Awareness)" bool i_show_cb = input.bool(true, "Show CB Tier Lines",group=G_CB,tooltip="COMEX Globex rule 589: ±3/±6/±9% from prior settle triggers halts. Displayed as awareness only — does NOT block signals unless CB Gate enabled.") bool i_cb_gate = input.bool(true, "Enable CB Signal Gate (blocks MR inside ±3%)",group=G_CB,tooltip="When enabled, MR signals are blocked if price is within the ±3% CB tier band. Recommended: OFF for scalping, ON for swing.") color i_cb_t1_col = input.color(color.rgb(255, 255, 255, 0), "CB Tier 1 (±3%) Color", group=G_CB) color i_cb_t2_col = input.color(color.rgb(255, 255, 255, 0), "CB Tier 2 (±6%) Color", group=G_CB) color i_cb_t3_col = input.color(color.rgb(255, 255, 255, 0), "CB Tier 3 (±9%) Color", group=G_CB) const string G_EXEC = "⑥ EXECUTION" float i_tol = input.float(3.0,"Zone Tolerance ($)",group=G_EXEC,step=0.5) float i_body_min = input.float(0.40,"Min Candle Body Ratio",group=G_EXEC,step=0.05) int i_evt_win = input.int(5,"Event Window (bars)",group=G_EXEC,minval=1,maxval=20) float i_prox_mult = input.float(1.5,"Bubble Proximity Mult",group=G_EXEC,step=0.1) int i_dedup = input.int(5,"Dedup Window (bars)",group=G_EXEC,minval=1,maxval=20) bool i_prio_gate = input.bool(true,"Signal Priority Gate C/D>A/B>E/F",group=G_EXEC) int i_out_bars = input.int(2,"Regime Hysteresis (bars)",group=G_EXEC,minval=1,maxval=5) int i_n_str = input.int(2,"N Strikes to show",group=G_EXEC,minval=1,maxval=4) bool i_sess_filt = input.bool(true,"No MR during Asia session (20:00–02:59 New York)",group=G_EXEC) const string G_VIS = "⑦ VISUALIZATION" bool i_show_map = input.bool(true, "Show Regime Heatmap",group=G_VIS) bool i_show_g1 = input.bool(false,"Show gFlip g1 Labels",group=G_VIS) bool i_show_atm = input.bool(false,"Show SpotEx ATM",group=G_VIS) bool i_show_vwap = input.bool(true, "Show VWAP Label",group=G_VIS) bool i_show_dvwap = input.bool(false,"Show Daily VWAP (secondary)",group=G_VIS) bool i_rich_lbl = input.bool(true, "Rich Strike Labels",group=G_VIS) bool i_show_g2 = input.bool(false,"Show Gamma Wall Labels (2x)",group=G_VIS) bool i_show_g3 = input.bool(false,"Show Explosion Labels (3x)",group=G_VIS) bool i_show_sd = input.bool(true, "Show SD/PBV Levels",group=G_VIS) bool i_show_phi = input.bool(false," Show PHI System (1.618sigma)",group=G_VIS) bool i_show_delta_sys = input.bool(true," Show DELTA System (25D/15D/5D)",group=G_VIS) string i_sd_signal = input.string("DELTA"," Signal Source (cond_C/D)",group=G_VIS,options=["PHI","DELTA"]) bool i_show_str = input.bool(true, "Show SpotEx Strikes",group=G_VIS) bool i_show_em = input.bool(true, "Show Expected Move +/-1sigma",group=G_VIS) bool i_show_em2 = input.bool(true, "Show Expected Move +/-2sigma",group=G_VIS) bool i_show_rr = input.bool(true, "Show Risk Reversal Label",group=G_VIS) bool i_show_vpin = input.bool(true, "Show VPIN Proxy Label",group=G_VIS) color i_c_g1 = input.color(color.rgb(31, 255, 232, 0), "gFlip color", group=G_VIS) color i_c_g2u = input.color(color.rgb(216, 255, 59, 0), "Wall+2x", group=G_VIS) color i_c_g2d = input.color(color.rgb(216, 255, 59, 0), "Wall-2x", group=G_VIS) color i_c_g3 = input.color(color.rgb(255, 0, 255, 0), "Explosion 3x", group=G_VIS) color i_c_sd = input.color(color.rgb(255, 255, 255, 0), "SD Level", group=G_VIS) color i_c_pbv = input.color(color.rgb(255, 255, 255, 0), "PBV Level", group=G_VIS) color i_c_buy = input.color(#00E676,"BUY Signal",group=G_VIS) color i_c_sell = input.color(#FF1744,"SELL Signal",group=G_VIS) const string G_STR_COL = "⑦ VISUALIZATION — SPOTEX COLORS" color i_cc_line = input.color(color.rgb(247, 82, 95, 50), "Call Line", group=G_STR_COL) color i_cp_line = input.color(color.rgb(102, 187, 106, 50), "Put Line", group=G_STR_COL) color i_c_blk_ln = input.color(color.rgb(255, 167, 38, 35), "Blocked Line", group=G_STR_COL) color i_cc_bg_norm = input.color(color.rgb(247, 82, 95, 50), "Call Label BG (Normal)", group=G_STR_COL) color i_cc_bg_med = input.color(color.rgb(178, 40, 51, 20), "Call Label BG (Med)", group=G_STR_COL) color i_cc_bg_str = input.color(color.rgb(128, 25, 34, 10), "Call Label BG (Strong)", group=G_STR_COL) color i_cp_bg_norm = input.color(color.rgb(102, 187, 106, 50), "Put Label BG (Normal)", group=G_STR_COL) color i_cp_bg_med = input.color(color.rgb(56, 142, 60, 20), "Put Label BG (Med)", group=G_STR_COL) color i_cp_bg_str = input.color(color.rgb(27, 94, 32, 10), "Put Label BG (Strong)", group=G_STR_COL) color i_c_blk_bg = input.color(color.rgb(230, 81, 0, 40), "Blocked Label BG", group=G_STR_COL) color i_cc_txt_norm= input.color(color.rgb(255, 255, 255, 0), "Call Text (Normal)", group=G_STR_COL) color i_cc_txt_med = input.color(color.rgb(255, 255, 255, 0), "Call Text (Med)", group=G_STR_COL) color i_cc_txt_str = input.color(color.rgb(255, 255, 255, 0), "Call Text (Strong)", group=G_STR_COL) color i_cp_txt_norm= input.color(color.rgb(255, 255, 255, 0), "Put Text (Normal)", group=G_STR_COL) color i_cp_txt_med = input.color(color.rgb(255, 255, 255, 0), "Put Text (Med)", group=G_STR_COL) color i_cp_txt_str = input.color(color.rgb(255, 255, 255, 0), "Put Text (Strong)", group=G_STR_COL) color i_c_blk_txt = input.color(color.rgb(255, 255, 255, 0), "Blocked Text", group=G_STR_COL) const string G_STYL = "⑧ LINE STYLE — PHI System" color i_phi_col = input.color(color.new(#FF9800,25),"PHI Line Color",group=G_STYL) int i_phi_width = input.int(1,"PHI Line Width (1-4)",group=G_STYL,minval=1,maxval=4) string i_phi_style = input.string("Dotted","PHI Line Style",group=G_STYL,options=["Solid","Dashed","Dotted"]) int i_phi_lbl_tr= input.int(75,"PHI Label Transparency",group=G_STYL,minval=0,maxval=100) const string G_STYL2 = "⑧ LINE STYLE — DELTA System" float i_delta_dte = input.float(1.0," DELTA DTE (days)",group=G_STYL2,step=0.25,minval=0.1,maxval=5.0) float i_skew_15d_p = input.float(1.29,"15D Put Skew x",group=G_STYL2,step=0.01,minval=0.8,maxval=2.0) float i_skew_15d_c = input.float(1.27,"15D Call Skew x",group=G_STYL2,step=0.01,minval=0.8,maxval=2.0) float i_skew_5d_p = input.float(1.21," 5D Put Skew x",group=G_STYL2,step=0.01,minval=0.8,maxval=2.0) float i_skew_5d_c = input.float(1.23," 5D Call Skew x",group=G_STYL2,step=0.01,minval=0.8,maxval=2.0) color i_d25_col = input.color(color.new(#FF6F00,5), "25D Color",group=G_STYL2) int i_d25_width = input.int(1,"25D Width (1-4)",group=G_STYL2,minval=1,maxval=4) string i_d25_style = input.string("Dotted","25D Style",group=G_STYL2,options=["Solid","Dashed","Dotted"]) int i_d25_lbl_tr = input.int(50,"25D Label Transparency",group=G_STYL2,minval=0,maxval=100) color i_d15_col = input.color(color.new(#FFA726,35),"15D Color",group=G_STYL2) int i_d15_width = input.int(1,"15D Width (1-4)",group=G_STYL2,minval=1,maxval=4) string i_d15_style = input.string("Dotted","15D Style",group=G_STYL2,options=["Solid","Dashed","Dotted"]) int i_d15_lbl_tr = input.int(65,"15D Label Transparency",group=G_STYL2,minval=0,maxval=100) color i_d5_col = input.color(color.new(#90A4AE,55)," 5D Color",group=G_STYL2) int i_d5_width = input.int(1," 5D Width (1-4)",group=G_STYL2,minval=1,maxval=4) string i_d5_style = input.string("Dotted"," 5D Style",group=G_STYL2,options=["Solid","Dashed","Dotted"]) int i_d5_lbl_tr = input.int(75," 5D Label Transparency",group=G_STYL2,minval=0,maxval=100) string i_sd_lbl_sz = input.string("Tiny","SD/Delta Label Size",group=G_STYL2,options=["Tiny","Small","Normal"]) color i_d35_col = input.color(color.new(#FF5722,50),"35D Color",group=G_STYL2) color i_d45_col = input.color(color.new(#E64A19,50),"45D Color",group=G_STYL2) bool i_show_fill = input.bool(true,"Show Delta Zone Fills",group=G_STYL2) color i_fill_5_15 = input.color(color.rgb(76, 175, 80, 85), "Fill 5D-15D", group=G_STYL2) color i_fill_15_25 = input.color(color.rgb(41, 98, 255, 85), "Fill 15D-25D", group=G_STYL2) color i_fill_25_35 = input.color(color.rgb(255, 235, 59, 85), "Fill 25D-35D", group=G_STYL2) color i_fill_35_45 = input.color(color.rgb(0, 0, 0, 85), "Fill 35D-45D", group=G_STYL2) const string G_BAND = "⑨ GEX BANDS — Continuous History" bool i_show_g1_band = input.bool(true,"Show gFlip g1 Band (+/-1.618sigma)",group=G_BAND) color i_band_g1_col = input.color(color.rgb(31, 255, 232, 0), "g1 Band Color", group=G_BAND) int i_band_g1_w = input.int(1,"g1 Width (1-4)",group=G_BAND,minval=1,maxval=4) bool i_show_g2_band = input.bool(true,"Show gWall g2 Band (+/-3.414sigma)",group=G_BAND) color i_band_g2u_col = input.color(color.rgb(216, 255, 59, 0), "g2+ Call Wall Color", group=G_BAND) color i_band_g2d_col = input.color(color.rgb(216, 255, 59, 0), "g2- Put Wall Color", group=G_BAND) int i_band_g2_w = input.int(1,"g2 Width (1-4)",group=G_BAND,minval=1,maxval=4) bool i_show_g3_band = input.bool(true,"Show gExp g3 Band (+/-5sigma)",group=G_BAND) color i_band_g3_col = input.color(color.rgb(255, 0, 255, 0), "g3 Explosion Color", group=G_BAND) int i_band_g3_w = input.int(1,"g3 Width (1-4)",group=G_BAND,minval=1,maxval=4) string i_band_g1_sty = input.string("Dotted","g1 Band Style",group=G_BAND,options=["Solid","Dashed","Dotted"]) string i_band_g2_sty = input.string("Dotted","g2 Band Style",group=G_BAND,options=["Solid","Dashed","Dotted"]) string i_band_g3_sty = input.string("Dotted","g3 Band Style",group=G_BAND,options=["Solid","Dashed","Dotted"]) const string G_CVP = "⑩ K-MEANS CLUSTER VP" bool i_show_cvp = input.bool(true, "Show K-Means Cluster VP",group=G_CVP) int i_cvp_lb = input.int(377, "Lookback Period (bars)",group=G_CVP,minval=50,maxval=2000) int i_n_clusters = input.int(5, "Number of Clusters",group=G_CVP,minval=2,maxval=10) int i_km_iter = input.int(50, "K-Means Iterations",group=G_CVP,minval=10,maxval=200) color i_cvp_col = input.color(color.rgb(255, 235, 59, 30), "Cluster Line Color", group=G_CVP) bool i_cvp_label = input.bool(true,"Show Cluster Labels",group=G_CVP) bool i_cvp_dots = input.bool(true,"Highlight Price at Cluster Level",group=G_CVP) int i_cvp_ext = input.int(50,"Cluster Line Extension (bars)",group=G_CVP,minval=10,maxval=500) int i_cvp_line_w = input.int(1,"Cluster Line Width (1-4)",group=G_CVP,minval=1,maxval=4) string i_cvp_poc_sty= input.string("Dotted","POC Line Style",group=G_CVP,options=["Solid","Dashed","Dotted"]) string i_cvp_clus_sty=input.string("Dotted","Cluster Line Style",group=G_CVP,options=["Solid","Dashed","Dotted"]) string i_cvp_lbl_sz = input.string("Tiny","Cluster Label Size",group=G_CVP,options=["Tiny","Small","Normal"]) string i_cvp_dot_sz2= input.string("small","CVP Dot Size (near cluster)",group=G_CVP,options=["tiny","small","normal"]) color i_cvp_poc_col= input.color(color.rgb(255, 0, 255, 0), "POC Star Color", group=G_CVP) const string G_ALMA = "⑪ ALMA MOVING AVERAGES" bool i_show_alma = input.bool(true,"Show ALMA Lines",group=G_ALMA) int i_al1_len = input.int(59, "L1 Length (Fast)",group=G_ALMA,minval=2) float i_al1_offset = input.float(0.85,"L1 Offset (0-1)",group=G_ALMA,step=0.01,minval=0.0,maxval=1.0) float i_al1_sigma = input.float(6.0, "L1 Sigma",group=G_ALMA,step=0.5,minval=1.0) color i_al1_col = input.color(color.new(#00FF88,0),"L1 Color (Fast)",group=G_ALMA) int i_al1_w = input.int(1,"L1 Width (1-4)",group=G_ALMA,minval=1,maxval=4) int i_al2_len = input.int(125, "L2 Length (Medium)",group=G_ALMA,minval=2) float i_al2_offset = input.float(0.85,"L2 Offset",group=G_ALMA,step=0.01,minval=0.0,maxval=1.0) float i_al2_sigma = input.float(6.0, "L2 Sigma",group=G_ALMA,step=0.5,minval=1.0) color i_al2_col = input.color(color.new(#FFCC00,0),"L2 Color (Med)",group=G_ALMA) int i_al2_w = input.int(1,"L2 Width (1-4)",group=G_ALMA,minval=1,maxval=4) int i_al3_len = input.int(215, "L3 Length (Slow)",group=G_ALMA,minval=2) float i_al3_offset = input.float(0.85,"L3 Offset",group=G_ALMA,step=0.01,minval=0.0,maxval=1.0) float i_al3_sigma = input.float(6.0, "L3 Sigma",group=G_ALMA,step=0.5,minval=1.0) color i_al3_col = input.color(color.new(#FF0044,0),"L3 Color (Slow)",group=G_ALMA) int i_al3_w = input.int(1,"L3 Width (1-4)",group=G_ALMA,minval=1,maxval=4) const string G_QA = "⑫ VOLUME INTELLIGENCE (QuantAlgo Consensus)" int i_qa_short = input.int(20, "Short Window",group=G_QA,minval=5,maxval=100) int i_qa_mid = input.int(50, "Medium Window",group=G_QA,minval=10,maxval=300) int i_qa_long = input.int(100, "Long Window",group=G_QA,minval=20,maxval=500) float i_qa_sm_pct = input.float(75.0, "Small Percentile", group=G_QA, step=1.0, minval=50.0, maxval=95.0) float i_qa_md_pct = input.float(93.0,"Medium Percentile",group=G_QA,step=1.0,minval=60.0,maxval=98.0) float i_qa_bg_pct = input.float(97.0,"Big Percentile",group=G_QA,step=1.0,minval=70.0,maxval=99.9) bool i_qa_show_sm = input.bool(true, "Show Small Clusters", group=G_QA) bool i_qa_show_md = input.bool(true,"Show Medium Clusters",group=G_QA) bool i_qa_show_bg = input.bool(true,"Show Big Clusters",group=G_QA) color i_qa_c_buy = input.color(color.new(#00E676,20),"Bubble BUY Color",group=G_QA) color i_qa_c_sell = input.color(color.new(#FF1744,20),"Bubble SELL Color",group=G_QA) color i_qa_c_mix = input.color(color.new(#FFD700,30),"Bubble MIXED Color",group=G_QA) bool i_qa_show_lbl= input.bool(true, "Show Numbers in Bubbles",group=G_QA,tooltip="Text inside each bubble: Volume / Delta / Ratio") string i_qa_lbl_cnt= input.string("Volume","Bubble Text",group=G_QA,options=["Volume","Delta","Ratio","Vol+Delta","Vol+Ratio"],tooltip="Volume: raw bar vol\nDelta: net buy-sell (proxy)\nRatio: x SMA50\nVol+Delta / Vol+Ratio: two lines") const string G_AMT = "⑬ AMT PATTERN ENGINE (Sovereign 24b)" bool i_show_amt = input.bool(true,"Show AMT Patterns",group=G_AMT) bool i_amt_rej = input.bool(true," Show Rejection (reversal wick)",group=G_AMT) bool i_amt_abs = input.bool(true," Show Absorption (continuation)",group=G_AMT) bool i_amt_ctr = input.bool(true," Show Contrarian (exhaustion warn)",group=G_AMT) bool i_amt_acc = input.bool(true," Show Acceptance (balanced)",group=G_AMT) bool i_amt_ice = input.bool(true," Show Iceberg at GEX zones (signal)",group=G_AMT) bool i_ice_strikes= input.bool(true," Show Iceberg warning at SpotEx",group=G_AMT) float i_amt_wick_rej=input.float(0.40,"Rejection Wick % (of range)",group=G_AMT,step=0.05,minval=0.20,maxval=0.80) float i_amt_vol_dom =input.float(1.50,"Absorption Dominance Ratio",group=G_AMT,step=0.10,minval=1.10,maxval=3.00) float i_ice_mass = input.float(1.8,"Iceberg Mass Threshold (xSMA50)",group=G_AMT,step=0.1,minval=1.2,maxval=3.0) color i_amt_rej_col= input.color(color.new(#9C27B0,0),"Rejection Color",group=G_AMT) color i_amt_abs_col= input.color(color.new(#00BCD4,0),"Absorption Color",group=G_AMT) color i_amt_ice_col= input.color(color.new(#FFD700,0),"Iceberg Color",group=G_AMT) string i_amt_emj_sz= input.string("Large","AMT Symbol Size (Rejection/Absorption/Iceberg)",group=G_AMT,options=["Small","Normal","Large","Huge"],tooltip="Size of emoji symbols on chart: Rejection / Absorption / Iceberg") // [v26] BUBBLE CONTEXT — Lower-TF intrabar POSITION → AMT event classifier const string G_BCTX = "⑬b BUBBLE CONTEXT (LTF Position Engine)" bool i_bctx_on = input.bool(true, "Enable Bubble Context (LTF position → pattern)", group=G_BCTX, tooltip="Upgrades the ⑫ volume bubbles: pulls lower-TF intrabar data to find WHERE inside the current candle the volume/delta cluster sits, then names the AMT event.\n\nBullish candle → cluster at BOTTOM (sellers absorbed)=abs-continue · MID buy=acceptance buy · TOP buy=abs-contrarian · TOP sell=rejection.\nBearish candle = mirror image.") bool i_bctx_lbl = input.bool(true, " Show Context Labels (abs-continue / acceptance / rejection …)", group=G_BCTX) bool i_bctx_dot = input.bool(true, " Show Position Dot (bubble at LTF cluster, colored by side)", group=G_BCTX) string i_bctx_ltf = input.timeframe("30", "LTF Resolution (intrabar)", group=G_BCTX, tooltip="Lower timeframe used to locate the intrabar cluster. MUST be ≤ chart TF.\nM5 chart: 1 = 5 intrabars · 15S = 20 (finer, needs seconds data) · 5S = 60.") int i_bctx_bins = input.int(20, "Position Bins (vertical resolution)", group=G_BCTX, minval=4, maxval=50, tooltip="The candle's high→low range is split into this many horizontal price bins; the bin holding the most LTF volume = the cluster (mini volume-profile POC).") float i_bctx_top = input.float(0.66, "Top Zone Threshold (frac of range)", group=G_BCTX, minval=0.50, maxval=0.90, step=0.01, tooltip="Cluster fraction ≥ this = TOP zone (upper wick / distribution).") float i_bctx_bot = input.float(0.34, "Bottom Zone Threshold (frac of range)", group=G_BCTX, minval=0.10, maxval=0.50, step=0.01, tooltip="Cluster fraction ≤ this = BOTTOM zone (lower wick / accumulation).") string i_bctx_gate = input.string("Medium+", "Min Bubble Size to Classify", group=G_BCTX, options=["Small+","Medium+","Big only"], tooltip="Only classify bars where a ⑫ volume bubble of at least this tier is visible.") color i_bctx_up = input.color(color.new(#00E676,0), "Bullish-Outcome Label Color", group=G_BCTX, tooltip="Color for abs-continue / acceptance on a bullish candle, and rejection / abs-contrarian on a bearish candle.") color i_bctx_dn = input.color(color.new(#FF1744,0), "Bearish-Outcome Label Color", group=G_BCTX) string i_bctx_sz = input.string("Small","Context Label Size",group=G_BCTX,options=["Tiny","Small","Normal","Large"]) bool i_bctx_arrow= input.bool(true, " Prefix side arrow on label (▲buy / ▼sell)", group=G_BCTX) const string G_MOM = "⑭ MOMENTUM — MLMI + SMI" int i_mlmi_k = input.int(987, "MLMI Neighbors (k)",group=G_MOM,minval=10,maxval=2000) int i_mlmi_mw = input.int(10, "MLMI Momentum Window",group=G_MOM,minval=5,maxval=50) int i_mlmi_cap = input.int(2500,"MLMI Max Stored Trades (perf cap)",group=G_MOM,minval=987,maxval=10000,tooltip="[v24] Bounds the kNN trade memory so the array cannot grow unbounded → kills execution-timeout / array-size RE on deep history.\nKeeps the most-recent N crossover trades. Must be >= k (987). 2500 >> k so prediction is functionally unchanged.") bool i_mlmi_gate = input.bool(true,"Enable MLMI/SMI Signal Gate",group=G_MOM) int i_mlmi_d_lon = input.int(8, "MLMI Decay LON+NY (bars)",group=G_MOM,minval=3,maxval=20) int i_mlmi_d_asia= input.int(5, "MLMI Decay ASIA (bars)",group=G_MOM,minval=2,maxval=15) int i_mlmi_expire= input.int(21, "MLMI Expire (bars)",group=G_MOM,minval=5,maxval=50) int i_smi_k = input.int(10, "SMI %K Length",group=G_MOM,minval=1,maxval=50) int i_smi_d = input.int(3, "SMI %D Length",group=G_MOM,minval=1,maxval=20) int i_smi_ema = input.int(3, "SMI EMA Length",group=G_MOM,minval=1,maxval=20) float i_smi_ob = input.float(40.0, "SMI Overbought Level",group=G_MOM,step=1.0) float i_smi_os = input.float(-40.0,"SMI Oversold Level",group=G_MOM,step=1.0) const string G_EMAV = "⑮ EXPECTED MOVE — Annualized Vol" bool i_show_em3 = input.bool(true,"Show EM +/-3sigma Band (99.7%)",group=G_EMAV) color i_c_em3 = input.color(color.new(#FF1744,30),"EM +/-3sigma Color",group=G_EMAV) bool i_show_em_lbl= input.bool(true,"Show EM Probability Labels",group=G_EMAV) bool i_show_yz_av = input.bool(true,"Show YZ Realized Vol Band",group=G_EMAV) const string G_QBLK = "⑯ EFP + Q-BLOCK GRID" bool i_show_qblk = input.bool(true,"Show Q-Block Grid Lines",group=G_QBLK) bool i_show_basis = input.bool(true,"Show EFP Basis Labels on Chart",group=G_QBLK) color i_qblk_w0_col= input.color(color.new(#607D8B,30),"W0 ATM Color",group=G_QBLK) color i_qblk_wu_col= input.color(color.new(#FF1744,40),"W+1/+2 Call Color",group=G_QBLK) color i_qblk_wd_col= input.color(color.new(#00E676,40),"W-1/-2 Put Color",group=G_QBLK) int i_qblk_w = input.int(1,"Q-Block Line Width",group=G_QBLK,minval=1,maxval=3) const string G_SQZ = "⑰ SQUEEZE DETECTOR (Yang-Zhang)" bool i_sqz_en = input.bool(false, "Enable Squeeze Labels", group=G_SQZ) int i_sqz_yz_fast = input.int(20, "YZ Fast Window (bars)", group=G_SQZ, minval=5, maxval=100, tooltip="Short-window realized vol — responds quickly to compression onset") int i_sqz_yz_slow = input.int(100, "YZ Slow Window (bars)", group=G_SQZ, minval=20, maxval=500, tooltip="Long-window structural baseline vol — sets the compression floor") float i_sqz_ratio = input.float(0.7, "Compression Ratio Threshold", group=G_SQZ, step=0.05, minval=0.3, maxval=0.95, tooltip="Squeeze ON when fast YZ < slow YZ × this ratio. Lower = tighter squeeze required") int i_sqz_min_dur = input.int(3, "Min Compression Bars (Filter ①)", group=G_SQZ, minval=1, maxval=20, tooltip="Squeeze must be compressed for at least this many bars before release is valid. Eliminates 1-2 bar transient false signals") string i_sqz_up_txt = input.string("SqUp","Bull Label Text", group=G_SQZ) string i_sqz_dn_txt = input.string("SqDn","Bear Label Text", group=G_SQZ) color i_sqz_up_col = input.color(color.new(#00E676,0), "SqUp Color", group=G_SQZ) color i_sqz_dn_col = input.color(color.new(#FF1744,0), "SqDn Color", group=G_SQZ) int i_sqz_lbl_tr = input.int(20, "Label Background Transparency (0-100)", group=G_SQZ, minval=0, maxval=100) string i_sqz_lbl_sz = input.string("Small","Label Size", group=G_SQZ, options=["Tiny","Small","Normal","Large"]) string i_sqz_txt_sz = input.string("Small","Text Size", group=G_SQZ, options=["Tiny","Small","Normal"]) float i_sqz_offset = input.float(0.5, "Label Offset (x ATR14)", group=G_SQZ, step=0.1, minval=0.0, maxval=5.0) const string G_FRZ = "⑱ FROZEN ZONE DISPLAY (BasisMatrix §13)" bool i_show_frz = input.bool(true, "Show Supply/Demand Frozen Zones", group=G_FRZ) float i_frz_mult = input.float(2.0, "Zone Sensitivity (×σ basis)", group=G_FRZ, step=0.1) float i_frz_vfac = input.float(1.5, "Volume Spike Factor", group=G_FRZ, step=0.1) int i_frz_warmup = input.int(10, "Warmup (bars)", group=G_FRZ, minval=0, maxval=100) // [v27] EXPANSION SCORE + MR-INTO-TREND — display-only (label only → 0 plot-budget) const string G_XMT = "⑲ EXPANSION + MR-INTO-TREND (display)" bool i_xmt_on = input.bool(false, "Enable Expansion / MR-into-Trend module", group=G_XMT, tooltip="Two reads from the 3-primitives framework:\n• EXPANSION = breakout trigger (this bar's range ≫ trailing average).\n• MR-into-TREND = buy-the-dip WITH the trend (pullback/retest to the g1 flip level inside an established trend — NOT a fade against it).\nDISPLAY-ONLY: no gate / conf_score / entry touched.") bool i_exp_lbl = input.bool(true, " Show Expansion labels", group=G_XMT) int i_exp_len = input.int(5, " Expansion avg window (bars)", group=G_XMT, minval=2, maxval=100, tooltip="Trailing bars for the average range. Transcript: last 5 candles avg 1%, 6th = 2% → expansion.") float i_exp_thr = input.float(2.0, " Expansion multiple (× avg range)", group=G_XMT, step=0.1, minval=1.1, tooltip="Flag EXPANSION when this bar's range ≥ this × average range.") bool i_mrt_lbl = input.bool(true, " Show MR-into-Trend labels", group=G_XMT) int i_mrt_look = input.int(20, " Retrace lookback (bars)", group=G_XMT, minval=5, maxval=200, tooltip="Bars used to find the recent swing extreme for the pullback-depth read shown in the tooltip.") color i_xmt_up = input.color(color.new(#00E676,0), " Bullish label color", group=G_XMT) color i_xmt_dn = input.color(color.new(#FF1744,0), " Bearish label color", group=G_XMT) color i_exp_col = input.color(color.new(#FFD700,0), " Expansion label color", group=G_XMT) string i_xmt_sz = input.string("Small"," Label size",group=G_XMT,options=["Tiny","Small","Normal","Large"]) // [v28] REGIME MATRIX + Γ-PROXY — display-only (one table → 0 plot-budget) const string G_RM = "⑳ REGIME MATRIX + Γ-PROXY (display)" bool i_rm_on = input.bool(true, "Enable Regime Matrix + Γ-proxy", group=G_RM, tooltip="Unifies direction × volatility into the 6-regime matrix + a POSITIVE/NEGATIVE-gamma PROXY, and prescribes fade / follow / stand-aside.\n\nΓ-proxy = a VOL-BEHAVIOUR proxy, NOT real dealer gamma (gold spot has no options chain). It reads the FOOTPRINT gamma leaves: vol dampening (pos-Γ → fade, failed breakouts) vs amplification (neg-Γ → follow, trends). Eyes, not a validated edge.\nDISPLAY-ONLY — no gate / conf_score / entry touched.") int i_rm_dir_len= input.int(200, " Direction baseline EMA (bars)", group=G_RM, minval=20, maxval=1000, tooltip="Bull if close>baseline & rising, Bear if close parameter1 array parameter2 array priceArray array resultArray method mlmi_store(MLMIData d, float p1, float p2) => d.parameter1.push(d.parameter1.get(d.parameter1.size() - 1)) d.parameter2.push(d.parameter2.get(d.parameter2.size() - 1)) d.priceArray.push(d.priceArray.get(d.priceArray.size() - 1)) d.resultArray.push(close >= d.priceArray.get(d.priceArray.size() - 1) ? 1.0 : -1.0) d.parameter1.set(d.parameter1.size() - 1, p1) d.parameter2.set(d.parameter2.size() - 1, p2) d.priceArray.set(d.priceArray.size() - 1, close) // [v24-2] RE-FIX: bound kNN memory — drop oldest trades beyond cap (keeps recent regime) int _cap = math.max(i_mlmi_cap, i_mlmi_k) if d.parameter1.size() > _cap d.parameter1.shift() d.parameter2.shift() d.priceArray.shift() d.resultArray.shift() method mlmi_predict(MLMIData d, float p1, float p2, int k) => distances = array.new_float(0) int n = d.parameter1.size() - 1 for i = 0 to n float dist = math.sqrt(math.pow(p1 - d.parameter1.get(i), 2.0) + math.pow(p2 - d.parameter2.get(i), 2.0)) distances.push(dist) sortedD = distances.copy() sortedD.sort() selected = sortedD.slice(0, math.min(k, sortedD.size())) float maxDist = selected.max() neighbors = array.new_float(0) for i = 0 to distances.size() - 1 if distances.get(i) <= maxDist neighbors.push(d.resultArray.get(i)) neighbors.sum() f_alma(float src, int len, float off, float sig) => float _m = off * float(len - 1) float _s = float(len) / sig float _ws = 0.0 float _wv = 0.0 for _i = 0 to len - 1 float _w = math.exp(-math.pow(float(_i) - _m, 2.0) / (2.0 * math.pow(_s, 2.0))) _wv += src[len - 1 - _i] * _w _ws += _w _ws > 0.0 ? _wv / _ws : src f_ls(string s) => switch s "Solid" => line.style_solid "Dotted" => line.style_dotted => line.style_dashed f_lsz(string s) => switch s "Small" => size.small "Normal" => size.normal => size.tiny f_dsz(string s) => switch s "tiny" => size.tiny "normal" => size.normal => size.small // Yang-Zhang realized volatility estimator (gold desk standard) f_yz(_len, _mult) => float _c_ret = math.log(math.max(close / math.max(open, syminfo.mintick), syminfo.mintick)) // log(Close/Open) float _o_ret = math.log(math.max(open / math.max(nz(close[1], close), syminfo.mintick), syminfo.mintick)) // log(Open/Close_prev) float _ho = math.log(math.max(high / math.max(open, syminfo.mintick), syminfo.mintick)) float _lo = math.log(math.max(low / math.max(open, syminfo.mintick), syminfo.mintick)) float _v_c = ta.variance(_c_ret, _len) // V_close float _v_o = ta.variance(_o_ret, _len) // V_overnight float _vrs = ta.sma((_ho * (_ho - _c_ret)) + (_lo * (_lo - _c_ret)), _len) float _k = 0.34 / (1.34 + float(_len + 1) / float(math.max(_len - 1, 1))) float _vyz = _v_o + _k * _v_c + (1.0 - _k) * _vrs math.sqrt(math.max(_vyz, 0.0)) * close * _mult f_touch(float price, float target) => math.abs(price - target) <= i_tol f_dir_score(bool _is_buy, bool _bub_b3, bool _bub_s3, bool _gvz_c, bool _gvz_n, bool _gvz_el, bool _gvz_ex, string _sig_rg, bool _is_l, bool _is_n, bool _is_a, bool _dxy_pb, bool _dxy_ps, bool _frm_ok, bool _sqz_u, bool _sqz_d, float _b_dev) => int sc = 50 sc := sc + (_is_buy and _bub_b3 ? 12 : 0) sc := sc - (_is_buy and _bub_s3 ? 10 : 0) sc := sc + (not _is_buy and _bub_s3 ? 12 : 0) sc := sc - (not _is_buy and _bub_b3 ? 10 : 0) sc := sc + (_gvz_c ? 12 : _gvz_n ? 6 : _gvz_el ? -8 : _gvz_ex ? -20 : 0) sc := sc + (_sig_rg == "COMPRESSED" ? 8 : _sig_rg == "NORMAL" ? 4 : _sig_rg == "EXPANDING" ? -5 : -12) sc := sc + (_is_l ? 8 : _is_n ? 4 : _is_a ? -8 : 0) sc := sc - (_is_buy and _dxy_pb ? 10 : 0) sc := sc - (not _is_buy and _dxy_ps ? 10 : 0) sc := sc + (_frm_ok ? 5 : -10) sc := sc + (_is_buy and _sqz_u ? 8 : 0) sc := sc + (not _is_buy and _sqz_d ? 8 : 0) sc := sc + (_b_dev < 1.0 ? 5 : _b_dev > 2.0 ? -5 : 0) math.min(95, math.max(5, sc)) f_body(float o, float c, float h, float l) => float rng = math.max(math.abs(h - l), syminfo.mintick) math.abs(c - o) / rng f_emaema(float src, int len) => ta.ema(ta.ema(src, len), len) f_qa_cons(bool pS, bool pM, bool pL) => int hits = (pS ? 1 : 0) + (pM ? 1 : 0) + (pL ? 1 : 0) hits >= 2 // QuantAlgo volume formatter (K/M/B) f_qa_fmtn(float v) => float av = math.abs(v) string sg = v < 0.0 ? "-" : "" string result = sg + str.tostring(av, "#") if av >= 1000000000.0 result := sg + str.tostring(av / 1000000000.0, "#.##") + "B" else if av >= 1000000.0 result := sg + str.tostring(av / 1000000.0, "#.##") + "M" else if av >= 1000.0 result := sg + str.tostring(av / 1000.0, "#.##") + "K" result // ═══════════════════════════════════════════════════════════════════════════════ // §3 RS DATA FETCH (7 calls — _efp_fut_h4 H4 restored in v21 revised) // ═══════════════════════════════════════════════════════════════════════════════ float fut_live = request.security(i_fut_sym, timeframe.period, close, barmerge.gaps_off, barmerge.lookahead_off, ignore_invalid_symbol=true) int fut_time = request.security(i_fut_sym, timeframe.period, time, barmerge.gaps_off, barmerge.lookahead_off, ignore_invalid_symbol=true) // v30-2 float fut_d = request.security(i_fut_sym, "D", close[1], barmerge.gaps_off, barmerge.lookahead_off, ignore_invalid_symbol=true) float spt_d = request.security(syminfo.tickerid, "D", close[1], barmerge.gaps_off, barmerge.lookahead_off) [gvz_d, gvz_z_d] = request.security(i_gvz_sym, "D", [close[1], (close[1] - ta.sma(close[1], 20)) / math.max(ta.stdev(close[1], 20), 0.001)], barmerge.gaps_off, barmerge.lookahead_off, ignore_invalid_symbol=true) // v30-1: z on DAILY bars float fut_1m = na // not fetched; see basis_1m below float _efp_fut_h4 = request.security(i_fut_sym, "240", close[1], barmerge.gaps_off, barmerge.lookahead_off, ignore_invalid_symbol=true) float _efp_spt_h4 = request.security(syminfo.tickerid, "240", close[1], barmerge.gaps_off, barmerge.lookahead_off) float dxy_raw = request.security("TVC:DXY", "D", close[1], barmerge.gaps_off, barmerge.lookahead_off, ignore_invalid_symbol=true) float fut_now = nz(fut_live, close) float d_spt = nz(spt_d, close) float d_fut = nz(fut_d, fut_now) float gvz_v = nz(gvz_d, 18.0) float basis_1m = fut_now - close // fut_1m RS removed (saves 6 plot-budget units); equivalent to raw_basis // v30-2: the user's GC1! feed is DELAYED (~10–15 min). In realtime the last futures print lags the chart bar; // when that lag exceeds 2 bars the basis is frozen at its last value instead of absorbing spot movement. bool fut_stale = barstate.isrealtime and not na(fut_time) and (time - fut_time) > 2 * timeframe.in_seconds() * 1000 // ═══════════════════════════════════════════════════════════════════════════════ // §4 BASIS ENGINE + COMEX CIRCUIT BREAKER TIERS // ═══════════════════════════════════════════════════════════════════════════════ float _basis_now = fut_now - close var float raw_basis = na raw_basis := fut_stale ? nz(raw_basis, _basis_now) : _basis_now // v30-2: hold the last basis while GC1! is stale float b_mean = ta.sma(raw_basis, i_basis_len) float b_std = ta.stdev(raw_basis, i_basis_len) float p_std = ta.stdev(fut_now, i_basis_len) float atr14 = ta.atr(14) float vol_sma50 = ta.sma(volume, 50) // v30-3: the boundaries below are NEW YORK clock times (Asia 20:00–02:59 = Tokyo day · London 03:00–07:59 = London morning · // NY 08:00–16:59). v29 evaluated them in UTC (no DST; Asia block was 7 h and labelled "00–02:59 UTC"). int _hm = hour(time,"America/New_York") * 100 + minute(time,"America/New_York") int _hm_ldn = hour(time,"Europe/London") * 100 + minute(time,"Europe/London") bool _is_asia = _hm >= 2000 or _hm < 300 bool _is_lon = _hm >= 300 and _hm < 800 bool _is_ny = _hm >= 800 and _hm < 1700 int _cur_sess = _is_ny ? 3 : _is_lon ? 2 : 1 // LBMA fix windows in LONDON time (auctions 10:30 / 15:00 London) — v30-3 int _fix_hm = _hm_ldn bool in_lbma_am = _fix_hm >= 1000 and _fix_hm < 1030 bool in_lbma_pm = _fix_hm >= 1500 and _fix_hm < 1515 bool in_fix = in_lbma_am or in_lbma_pm bool in_pre_fix = (_fix_hm >= 930 and _fix_hm < 1000) or (_fix_hm >= 1430 and _fix_hm < 1500) bool is_globex_open = dayofweek == dayofweek.sunday and _hm >= 1800 // v30-3: 18:00 New York string fix_lbl = in_lbma_am ? "AM FIX" : in_lbma_pm ? "PM FIX" : in_pre_fix ? "PRE-FIX" : is_globex_open ? "GLOBEX OPEN" : "" bool _sess_ok_mr = not i_sess_filt or not _is_asia var int _last_s = 0 var float _frozen = na if na(_frozen) and not na(raw_basis) _frozen := raw_basis bool is_new_day = dayofmonth != dayofmonth[1] or month != month[1] or year != year[1] int _prev_sess = _last_s if _cur_sess != _last_s _last_s := _cur_sess _frozen := nz(raw_basis, nz(b_mean, 0.0)) float fb = nz(_frozen, nz(b_mean, 0.0)) var float _snap_asia = na var float _snap_lon = na var float _snap_ny = na var string _sess_lbl = "--" bool _sess_flip = _cur_sess != 0 and _cur_sess != _prev_sess if _sess_flip if _cur_sess == 1 _sess_lbl := "ASIA" _snap_asia := nz(raw_basis, 0.0) else if _cur_sess == 2 _sess_lbl := "LON" _snap_lon := nz(raw_basis, 0.0) else if _cur_sess == 3 _sess_lbl := "NY" _snap_ny := nz(raw_basis, 0.0) float _snap_sess = _cur_sess == 3 ? nz(_snap_ny, nz(raw_basis, fb)) : _cur_sess == 2 ? nz(_snap_lon, nz(raw_basis, fb)) : nz(_snap_asia, nz(raw_basis, fb)) float _rb_safe = nz(raw_basis, nz(raw_basis[1], nz(raw_basis[2], 0.0))) float _bv_raw = _rb_safe - nz(_rb_safe[5], _rb_safe) float basis_vel = b_std > 0.0 ? _bv_raw / b_std : 0.0 bool basis_conv= (raw_basis > 0 and basis_vel < -0.2) or (raw_basis < 0 and basis_vel > 0.2) bool basis_divg= (raw_basis > 0 and basis_vel > 0.2) or (raw_basis < 0 and basis_vel < -0.2) string basis_trend_s = basis_conv ? "CONV" : basis_divg ? "DIV" : "FLAT" var float[] _sz_asia = array.new_float(0) var float[] _sz_lon = array.new_float(0) var float[] _sz_ny = array.new_float(0) if barstate.isconfirmed and not na(raw_basis) if _is_asia array.push(_sz_asia, raw_basis) if array.size(_sz_asia) > 60 array.shift(_sz_asia) else if _is_lon array.push(_sz_lon, raw_basis) if array.size(_sz_lon) > 60 array.shift(_sz_lon) else array.push(_sz_ny, raw_basis) if array.size(_sz_ny) > 60 array.shift(_sz_ny) float[] _cur_sarr = _cur_sess == 3 ? _sz_ny : _cur_sess == 2 ? _sz_lon : _sz_asia float _sess_mean = array.size(_cur_sarr) > 1 ? array.avg(_cur_sarr) : nz(b_mean, fb) float _sess_std = array.size(_cur_sarr) > 1 ? array.stdev(_cur_sarr) : nz(b_std, 0.5) float sess_z = _sess_std > 0.0 ? (_rb_safe - _sess_mean) / _sess_std : 0.0 bool sess_z_ext = math.abs(sess_z) >= 2.0 float _gofo_rate_dec = i_gofo_rate / 100.0 float gofo_carry = close * _gofo_rate_dec * (30.0 / 365.0) float gofo_excess = _rb_safe - gofo_carry bool gofo_backw = gofo_excess < -nz(b_std, 0.5) * 0.3 bool gofo_cont = gofo_excess > nz(b_std, 0.5) * 0.3 string gofo_regime = gofo_backw ? "BACKWRD" : gofo_cont ? "CNTNG+" : "FAIR" float bm = switch i_efp_mode "SESSION" => _snap_sess "1-MINUTE" => basis_1m => nz(b_mean, fb) float basis_cv = math.abs(bm) > 0.001 ? math.abs(b_std / bm) : 1.0 bool basis_stable = basis_cv <= 0.5 string basis_qual = basis_stable ? "STABLE" : "UNSTABLE" float _basis_delta = _rb_safe - fb bool is_divergent = b_std > 0.0 and math.abs(_basis_delta) >= b_std * 1.5 float _cb_settle = nz(d_fut, close) // prior COMEX futures settlement float cb_t1_u = _cb_settle * 1.03 float cb_t1_d = _cb_settle * 0.97 float cb_t2_u = _cb_settle * 1.06 float cb_t2_d = _cb_settle * 0.94 float cb_t3_u = _cb_settle * 1.09 float cb_t3_d = _cb_settle * 0.91 bool cb_t1_active = close > cb_t1_u or close < cb_t1_d bool cb_t2_active = close > cb_t2_u or close < cb_t2_d bool cb_t3_active = close > cb_t3_u or close < cb_t3_d string cb_tier_str = cb_t3_active ? "CB-T3 ±9%" : cb_t2_active ? "CB-T2 ±6%" : cb_t1_active ? "CB-T1 ±3%" : "CB:NORM" color cb_tier_col = cb_t3_active ? #D500F9 : cb_t2_active ? #FF1744 : cb_t1_active ? #FF9800 : #00E676 float _efp_orig = not na(_efp_fut_h4) and not na(_efp_spt_h4) ? _efp_fut_h4 - _efp_spt_h4 : nz(d_fut, close) - nz(d_spt, close) float bm_h4 = _efp_orig float fut_impl_h4 = close + bm_h4 float base_block_h4 = math.round(fut_impl_h4 / i_block) * i_block float qb_h4_u2 = base_block_h4 + (i_block * 2.0) - bm_h4 float qb_h4_u1 = base_block_h4 + i_block - bm_h4 float qb_h4_0 = base_block_h4 - bm_h4 float qb_h4_d1 = base_block_h4 - i_block - bm_h4 float qb_h4_d2 = base_block_h4 - (i_block * 2.0) - bm_h4 float basis_drift = bm - bm_h4 string basis_mode_str = math.abs(basis_drift) > b_std * 0.5 ? "DRIFT $" + str.tostring(math.abs(basis_drift),"#.##") : "STABLE" float efp_d = d_fut - d_spt // ═══════════════════════════════════════════════════════════════════════════════ // §5 SPOTEX LEVELS // ═══════════════════════════════════════════════════════════════════════════════ float implied_spot = fut_now - bm float _atm_c = math.ceil(fut_now / i_block) * i_block float _atm_p = math.floor(fut_now / i_block) * i_block float sp_c1 = _atm_c - bm float sp_c2 = (_atm_c + i_block) - bm float sp_c3 = (_atm_c + i_block * 2.0) - bm float sp_c4 = (_atm_c + i_block * 3.0) - bm float sp_p1 = _atm_p - bm float sp_p2 = (_atm_p - i_block) - bm float sp_p3 = (_atm_p - i_block * 2.0) - bm float sp_p4 = (_atm_p - i_block * 3.0) - bm float sd_u = implied_spot + p_std * i_sd_mult float sd_d = implied_spot - p_std * i_sd_mult float _pbv_anc = d_spt + efp_d float pbv_l1_u = _pbv_anc * (1.0 + i_pbv_1 / 100.0) - efp_d float pbv_l1_d = _pbv_anc * (1.0 - i_pbv_1 / 100.0) - efp_d float pbv_l2_u = _pbv_anc * (1.0 + i_pbv_2 / 100.0) - efp_d float pbv_l2_d = _pbv_anc * (1.0 - i_pbv_2 / 100.0) - efp_d float pbv_l3_u = _pbv_anc * (1.0 + i_pbv_3 / 100.0) - efp_d float pbv_l3_d = _pbv_anc * (1.0 - i_pbv_3 / 100.0) - efp_d // ═══════════════════════════════════════════════════════════════════════════════ // §6 GEX PHYSICS ENGINE + VWAP (London daily-reset fix) + ALMA // ═══════════════════════════════════════════════════════════════════════════════ bool is_lon_open = _hm == 300 var float _lv_pv = 0.0 var float _lv_v = 0.0 var bool _lon_started = false if is_new_day _lv_pv := 0.0 _lv_v := 0.0 _lon_started := false if is_lon_open or (not _lon_started and _is_lon) _lv_pv := hlc3 * volume _lv_v := volume _lon_started := true else if _lon_started _lv_pv += hlc3 * volume _lv_v += volume float lon_vwap = _lv_v > 0.0 ? _lv_pv / _lv_v : hlc3 var float _dv_pv = 0.0 var float _dv_v = 0.0 if is_new_day _dv_pv := 0.0 _dv_v := 0.0 _dv_pv += hlc3 * volume _dv_v += volume float daily_vwap = _dv_v > 0.0 ? _dv_pv / _dv_v : hlc3 float anchor = _lon_started ? lon_vwap : daily_vwap float sigma_raw = f_yz(i_vol_lb, i_vol_mult) float sigma_floor_val = nz(atr14, sigma_raw) * i_sig_floor float sigma = math.max(sigma_raw, sigma_floor_val) float sigma_pct = anchor > 0 ? sigma / anchor * 100.0 : 0.0 string sig_regime = sigma_pct < 0.8 ? "COMPRESSED" : sigma_pct < 1.5 ? "NORMAL" : sigma_pct < 2.5 ? "EXPANDING" : "EXTREME" color sig_r_col = sigma_pct < 0.8 ? #00BCD4 : sigma_pct < 1.5 ? #B0BEC5 : sigma_pct < 2.5 ? #FF9800 : #FF1744 float _g1_eff = i_sigma_mode == "GAUSSIAN" ? 1.0 : i_g1 float _g2_eff = i_sigma_mode == "GAUSSIAN" ? 2.0 : i_g2 float _g3_eff = i_sigma_mode == "GAUSSIAN" ? 3.0 : i_g3 string _prob_g1= i_sigma_mode == "GAUSSIAN" ? "68.3%" : "89.4%" string _prob_g2= i_sigma_mode == "GAUSSIAN" ? "95.5%" : "99.9%" float g1_up = anchor + sigma * _g1_eff float g1_dn = anchor - sigma * _g1_eff float g2_up = anchor + sigma * _g2_eff float g2_dn = anchor - sigma * _g2_eff float g3_up = anchor + sigma * _g3_eff float g3_dn = anchor - sigma * _g3_eff float frame_width = g1_up - g1_dn bool frame_ok = true // v30-4: frame = 2×g1×σ with σ ≥ 2×ATR14 → always ≥ 6.5 ATR; the $-tolerance test could never fail → retired float em_1sigma = gvz_v > 0.0 and not na(gvz_d) ? close * (gvz_v / 100.0) / math.sqrt(252.0) : sigma * 4.8 float em_upper = anchor + em_1sigma float em_lower = anchor - em_1sigma float em_upper_2 = anchor + em_1sigma * 2.0 float em_lower_2 = anchor - em_1sigma * 2.0 float em_upper_3 = anchor + em_1sigma * 3.0 float em_lower_3 = anchor - em_1sigma * 3.0 float yz_band_u = anchor + sigma * 1.0 float yz_band_d = anchor - sigma * 1.0 float _gvz_roc_em = gvz_v > 0.0 and gvz_v[1] > 0.0 ? gvz_v - gvz_v[1] : 0.0 float _price_roc = close > 0.0 and close[5] > 0.0 ? (close - close[5]) / close[5] * 100.0 : 0.0 bool rr_put_skew = _gvz_roc_em > 0.5 and _price_roc < -0.1 bool rr_call_skew = _gvz_roc_em < -0.5 and _price_roc > 0.1 string rr_str = rr_put_skew ? "PUT SKEW (RR-)" : rr_call_skew ? "CALL SKEW (RR+)" : "NEUTRAL" color rr_col = rr_put_skew ? color.new(#FF1744,0) : rr_call_skew ? color.new(#00E676,0) : color.new(#B0BEC5,0) float _buy_vol = close >= open ? volume : 0.0 float _sell_vol = close < open ? volume : 0.0 float _bv_ema = ta.ema(_buy_vol, 20) float _sv_ema = ta.ema(_sell_vol, 20) float _tot_ema = math.max(_bv_ema + _sv_ema, 1.0) float vpin_proxy = (_bv_ema - _sv_ema) / _tot_ema bool vpin_bull = vpin_proxy > 0.2 bool vpin_bear = vpin_proxy < -0.2 string vpin_str = vpin_bull ? "INST BUY " + str.tostring(vpin_proxy * 100,"#") + "%" : vpin_bear ? "INST SELL " + str.tostring(math.abs(vpin_proxy) * 100,"#") + "%" : "BALANCED" color vpin_col = vpin_bull ? color.new(#00E676,0) : vpin_bear ? color.new(#FF1744,0) : color.new(#B0BEC5,0) float alma_l1 = i_show_alma ? f_alma(close, i_al1_len, i_al1_offset, i_al1_sigma) : na float alma_l2 = i_show_alma ? f_alma(close, i_al2_len, i_al2_offset, i_al2_sigma) : na float alma_l3 = i_show_alma ? f_alma(close, i_al3_len, i_al3_offset, i_al3_sigma) : na bool alma_bull = not na(alma_l1) and alma_l1 > alma_l2 and alma_l2 > alma_l3 bool alma_bear = not na(alma_l1) and alma_l1 < alma_l2 and alma_l2 < alma_l3 string alma_regime = alma_bull ? "BULL" : alma_bear ? "BEAR" : "MIXED" color alma_reg_col = alma_bull ? #00FF88 : alma_bear ? #FF0044 : #B0BEC5 float qb_0 = math.round(fut_now / i_block) * i_block - bm float qb_u1 = qb_0 + i_block float qb_u2 = qb_0 + i_block * 2.0 float qb_d1 = qb_0 - i_block float qb_d2 = qb_0 - i_block * 2.0 // ═══════════════════════════════════════════════════════════════════════════════ // §5b DUAL-SYSTEM SD LEVELS // ═══════════════════════════════════════════════════════════════════════════════ float sd_phi_u = implied_spot + p_std * i_sd_mult float sd_phi_d = implied_spot - p_std * i_sd_mult float sigma_delta = gvz_v > 0.0 and not na(gvz_d) ? close * (gvz_v / 100.0) / math.sqrt(252.0) * math.sqrt(math.max(i_delta_dte, 0.1)) : sigma * 4.8 float _sd_45d_u = anchor + sigma_delta * 0.125 float _sd_45d_d = anchor - sigma_delta * 0.125 float _sd_35d_u = anchor + sigma_delta * 0.385 float _sd_35d_d = anchor - sigma_delta * 0.385 float _sd_25d_u = anchor + sigma_delta * 0.674 float _sd_25d_d = anchor - sigma_delta * 0.674 float _sd_15d_u = anchor + sigma_delta * 1.036 * i_skew_15d_c float _sd_15d_d = anchor - sigma_delta * 1.036 * i_skew_15d_p float _sd_5d_u = anchor + sigma_delta * 1.645 * i_skew_5d_c float _sd_5d_d = anchor - sigma_delta * 1.645 * i_skew_5d_p if i_sd_signal == "DELTA" sd_u := _sd_25d_u sd_d := _sd_25d_d else sd_u := sd_phi_u sd_d := sd_phi_d bool _sd_25d_u_in_frame = _sd_25d_u < g1_up and _sd_25d_u > g1_dn bool _sd_25d_d_in_frame = _sd_25d_d > g1_dn and _sd_25d_d < g1_up bool _sd_15d_u_in_frame = _sd_15d_u < g1_up and _sd_15d_u > g1_dn bool _sd_15d_d_in_frame = _sd_15d_d > g1_dn and _sd_15d_d < g1_up bool _sd_phi_u_in_frame = sd_phi_u < g1_up and sd_phi_u > g1_dn bool _sd_phi_d_in_frame = sd_phi_d > g1_dn and sd_phi_d < g1_up bool _sd_25d_u_conf = math.abs(g3_up - _sd_25d_u) <= i_tol * 2.5 bool _sd_25d_d_conf = math.abs(g3_dn - _sd_25d_d) <= i_tol * 2.5 bool _sd_phi_u_conf = math.abs(g3_up - sd_phi_u) <= i_tol * 2.5 bool _sd_phi_d_conf = math.abs(g3_dn - sd_phi_d) <= i_tol * 2.5 bool _using_delta_sig = i_sd_signal == "DELTA" bool _show_phi_sys = i_show_sd and i_show_phi bool _show_delta_sys = i_show_sd and i_show_delta_sys // ═══════════════════════════════════════════════════════════════════════════════ // §7 GVZ VOLATILITY REGIME // ═══════════════════════════════════════════════════════════════════════════════ float gvz_z = nz(gvz_z_d, 0.0) // v30-1: z-score of the daily GVZ close vs its 20-DAY mean/stdev (was 20 chart bars) bool gvz_compressed = not na(gvz_d) and gvz_v < i_gvz_norm bool gvz_normal = not na(gvz_d) and gvz_v >= i_gvz_norm and gvz_v < i_gvz_elev bool gvz_elevated = not na(gvz_d) and gvz_v >= i_gvz_elev and gvz_v < i_gvz_ext bool gvz_extreme = not na(gvz_d) and gvz_v >= i_gvz_ext bool gvz_spiking = gvz_z > 1.5 and not gvz_compressed bool gvz_crisis = gvz_z > 2.5 bool gvz_block_mr = i_gvz_en and (gvz_extreme or gvz_crisis) bool gvz_reduce_mr = i_gvz_en and (gvz_elevated or gvz_spiking) string gvz_tier = gvz_extreme ? "EXTREME" : gvz_elevated ? "ELEVATED" : gvz_normal ? "NORMAL" : "COMPRESSED" color gvz_tier_col = gvz_extreme ? #FF1744 : gvz_elevated ? #FF9800 : gvz_normal ? #B0BEC5 : #00BCD4 // ═══════════════════════════════════════════════════════════════════════════════ // §8 DXY MACRO FILTER [v19 fix: fully implemented — was stub in v18] // ═══════════════════════════════════════════════════════════════════════════════ float dxy_now = nz(dxy_raw, 100.0) var float _dxy_prev = na var float _dxy_d1 = na if is_new_day and dxy_now > 0.0 _dxy_prev := _dxy_d1 _dxy_d1 := dxy_now float _dxy_ref = nz(_dxy_prev, dxy_now) float dxy_roc = _dxy_ref > 0.0 ? (dxy_now - _dxy_ref) / _dxy_ref * 100.0 : 0.0 bool dxy_bull = i_dxy_en and dxy_roc > i_dxy_thr bool dxy_bear = i_dxy_en and dxy_roc < -i_dxy_thr bool dxy_penalise_buy = dxy_bull // DXY rising → headwind for Gold long bool dxy_penalise_sell = dxy_bear // DXY falling → headwind for Gold short color dxy_col = dxy_bull ? color.new(#FF1744,0) : dxy_bear ? color.new(#00E676,0) : color.new(#B0BEC5,0) string dxy_str = dxy_bull ? "DXY+" + str.tostring(dxy_roc,"#.##") + "% BEARISH XAU" : dxy_bear ? "DXY" + str.tostring(dxy_roc,"#.##") + "% BULLISH XAU" : "DXY NEUTRAL" // ═══════════════════════════════════════════════════════════════════════════════ // §9 MLMI COMPUTATION (k=987, momentumWindow=10, session-aware decay) // ═══════════════════════════════════════════════════════════════════════════════ float _ml_ma_q = ta.wma(close, 5) float _ml_ma_s = ta.wma(close, 20) float _ml_rsi_q = ta.wma(ta.rsi(close, 5), i_mlmi_mw) float _ml_rsi_s = ta.wma(ta.rsi(close, 20), i_mlmi_mw) bool _ml_pos = ta.crossover(_ml_ma_q, _ml_ma_s) bool _ml_neg = ta.crossunder(_ml_ma_q, _ml_ma_s) var MLMIData _mlmi_data = MLMIData.new( array.new_float(1, 0.0), array.new_float(1, 0.0), array.new_float(1, 0.0), array.new_float(1, 0.0)) if _ml_pos or _ml_neg _mlmi_data.mlmi_store(_ml_rsi_s, _ml_rsi_q) float mlmi_prediction = _mlmi_data.mlmi_predict(_ml_rsi_s, _ml_rsi_q, i_mlmi_k) float mlmi_pred_ma = ta.wma(mlmi_prediction, 20) var int _mlmi_cross_bar = -999 if _ml_pos or _ml_neg _mlmi_cross_bar := bar_index int _mlmi_age = bar_index - _mlmi_cross_bar int _mlmi_decay_win = _is_asia ? i_mlmi_d_asia : i_mlmi_d_lon bool mlmi_fresh = _mlmi_age <= _mlmi_decay_win bool mlmi_valid = _mlmi_age <= i_mlmi_expire bool mlmi_bull = mlmi_prediction > 0.0 bool mlmi_bear = mlmi_prediction < 0.0 bool mlmi_neutral = _mlmi_data.parameter1.size() < i_mlmi_k // v30-5: warm-up only (memory smaller than k); a 0 vote is no longer a free pass bool _mlmi_c_gate = not i_mlmi_gate or mlmi_neutral or (mlmi_fresh and mlmi_bull) bool _mlmi_d_gate = not i_mlmi_gate or mlmi_neutral or (mlmi_fresh and mlmi_bear) bool _mlmi_a_gate = not i_mlmi_gate or mlmi_neutral or (mlmi_valid and mlmi_bull) bool _mlmi_b_gate = not i_mlmi_gate or mlmi_neutral or (mlmi_valid and mlmi_bear) // ═══════════════════════════════════════════════════════════════════════════════ // §10 SMI COMPUTATION (K=10, D=3, EMA=3 — OB=+40, OS=-40) // ═══════════════════════════════════════════════════════════════════════════════ float _smi_hh = ta.highest(high, i_smi_k) float _smi_ll = ta.lowest(low, i_smi_k) float _smi_rng = _smi_hh - _smi_ll float _smi_rel = close - (_smi_hh + _smi_ll) / 2.0 float _smi_num = f_emaema(_smi_rel, i_smi_d) float _smi_den = f_emaema(_smi_rng, i_smi_d) float smi = _smi_den > 0.0 ? 200.0 * _smi_num / _smi_den : 0.0 float smi_ema = ta.ema(smi, i_smi_ema) bool smi_overbought = smi >= i_smi_ob bool smi_oversold = smi <= i_smi_os bool smi_bull_cross = ta.crossover(smi, smi_ema) bool smi_bear_cross = ta.crossunder(smi, smi_ema) bool _smi_g_gate = not i_mlmi_gate or smi_bull_cross or smi_oversold bool _smi_h_gate = not i_mlmi_gate or smi_bear_cross or smi_overbought // ═══════════════════════════════════════════════════════════════════════════════ // §11 QUANTALGO VOLUME INTELLIGENCE // ═══════════════════════════════════════════════════════════════════════════════ float _qa_rng = math.max(high - low, syminfo.mintick) float _qa_buy_vol = volume * ((close - low) / _qa_rng) float _qa_sell_vol = volume * ((high - close) / _qa_rng) float _qa_net_dlt = _qa_buy_vol - _qa_sell_vol float _qa_abs_dlt = math.abs(_qa_net_dlt) float _dSS = ta.percentile_linear_interpolation(_qa_abs_dlt, i_qa_short, i_qa_sm_pct) float _dSM = ta.percentile_linear_interpolation(_qa_abs_dlt, i_qa_mid, i_qa_sm_pct) float _dSL = ta.percentile_linear_interpolation(_qa_abs_dlt, i_qa_long, i_qa_sm_pct) float _dMS = ta.percentile_linear_interpolation(_qa_abs_dlt, i_qa_short, i_qa_md_pct) float _dMM = ta.percentile_linear_interpolation(_qa_abs_dlt, i_qa_mid, i_qa_md_pct) float _dML = ta.percentile_linear_interpolation(_qa_abs_dlt, i_qa_long, i_qa_md_pct) float _dBS = ta.percentile_linear_interpolation(_qa_abs_dlt, i_qa_short, i_qa_bg_pct) float _dBM = ta.percentile_linear_interpolation(_qa_abs_dlt, i_qa_mid, i_qa_bg_pct) float _dBL = ta.percentile_linear_interpolation(_qa_abs_dlt, i_qa_long, i_qa_bg_pct) bool _qa_big = f_qa_cons(_qa_abs_dlt >= _dBS, _qa_abs_dlt >= _dBM, _qa_abs_dlt >= _dBL) bool _qa_med = not _qa_big and f_qa_cons(_qa_abs_dlt >= _dMS, _qa_abs_dlt >= _dMM, _qa_abs_dlt >= _dML) bool _qa_small = not _qa_big and not _qa_med and f_qa_cons(_qa_abs_dlt >= _dSS, _qa_abs_dlt >= _dSM, _qa_abs_dlt >= _dSL) bool _qa_is_buy = _qa_net_dlt > 0.0 bool _qa_is_sell = _qa_net_dlt < 0.0 color _qa_bub_col = _qa_is_buy ? i_qa_c_buy : _qa_is_sell ? i_qa_c_sell : i_qa_c_mix bool qa_big_bull = _qa_big and _qa_is_buy bool qa_big_bear = _qa_big and _qa_is_sell bool qa_any_bull = (_qa_big or _qa_med or _qa_small) and _qa_is_buy bool qa_any_bear = (_qa_big or _qa_med or _qa_small) and _qa_is_sell bool qa_bull_3 = qa_any_bull or qa_any_bull[1] or qa_any_bull[2] bool qa_bear_3 = qa_any_bear or qa_any_bear[1] or qa_any_bear[2] bool qa_big_bull3 = qa_big_bull or qa_big_bull[1] or qa_big_bull[2] bool qa_big_bear3 = qa_big_bear or qa_big_bear[1] or qa_big_bear[2] float _qa_avg_vol = ta.sma(volume, i_qa_mid) float _qa_vol_ratio = _qa_avg_vol > 0.0 ? volume / _qa_avg_vol : 0.0 bool _qa_vis_sm = _qa_small and i_qa_show_sm bool _qa_vis_md = _qa_med and i_qa_show_md bool _qa_vis_bg = _qa_big and i_qa_show_bg bool _qa_any_vis = _qa_vis_sm or _qa_vis_md or _qa_vis_bg bool _qa_t0 = _qa_any_vis and _qa_vol_ratio < 2.5 bool _qa_t1 = _qa_any_vis and _qa_vol_ratio >= 2.5 and _qa_vol_ratio < 4.0 bool _qa_t2 = _qa_any_vis and _qa_vol_ratio >= 4.0 and _qa_vol_ratio < 6.5 bool _qa_t3 = _qa_any_vis and _qa_vol_ratio >= 6.5 and _qa_vol_ratio < 10.0 bool _qa_t4 = _qa_any_vis and _qa_vol_ratio >= 10.0 float _qa_plot_y = _qa_any_vis ? (_qa_is_sell ? high : low) : na var array