本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
// =============================================================================
// QUANTUM PULSE: DUAL-ENGINE REGIME & STRUCTURE RADAR (QP-V1 — EXACT RC6.1 PARITY)
// =============================================================================
// Why this file exists:
// 1. 100% EXACT SIGNAL PARITY WITH THE VERSION YOU LOVED (`RC6.1`):
// In `RC6.2`, turning ON the new `Suppress Counter-Trend Sweeps During Strong Trends`
// filter (`strong_bull_drive` / `strong_bear_drive`) blocked the exact `SWP-DN` and
// `SWP-UP` climax reversal signals that caught the tops and bottoms in your NQ1! video!
// This file restores the EXACT 100% unthrottled `RC6.1` signal math by default
// (while keeping the zero-volume 30s BTC fallback so 30s BTC also gets full signals).
// 2. COMPLETELY DISTINCT INDICATOR & VARIABLE NAMESPACE (`QP-V1`):
// Every indicator title, shorttitle, input group, plot title, and internal variable
// has been given a unique namespace (`qp_...`) so TradingView NEVER meshes, overwrites,
// or collides with your original `Alpha Agent` or `AA RC6` scripts.
// =============================================================================
indicator("Quantum Pulse: NQ & BTC Structural Radar [V1-Pure]", shorttitle="QP RADAR V1", overlay=true, max_lines_count=500, max_labels_count=500, max_boxes_count=500, max_bars_back=5000)
// --- 1. CORE AV-CUSUM VOLATILITY ENGINE INPUTS ---
string qp_grp_cusum = "1. Quantum Pulse — AV-CUSUM Volatility Engine"
string qp_tf_mode = input.string("Native Chart Timeframe (Recommended)", "CUSUM Timeframe Mode", options=["Native Chart Timeframe (Recommended)", "Locked 5-Minute HTF (Step Once Per 5m Bar)"], group=qp_grp_cusum)
float qp_gamma = input.float(2.0, "Regime Sensitivity (Gamma)", minval=1.1, maxval=10.0, step=0.1, group=qp_grp_cusum)
int qp_N_base = input.int(288, "Baseline Median Window (Bars)", minval=50, maxval=1000, group=qp_grp_cusum)
int qp_L_lag = input.int(24, "Baseline Lag Buffer (Bars)", minval=1, maxval=288, group=qp_grp_cusum)
float qp_q_cap = input.float(0.999, "Outlier Winsorization Quantile", minval=0.95, maxval=0.9999, step=0.001, group=qp_grp_cusum)
int qp_reset_lock = input.int(24, "Post-Break Cooldown (Bars)", minval=1, maxval=288, group=qp_grp_cusum)
float qp_h_thresh = input.float(5.0, "Break Alarm Threshold (h)", minval=0.5, maxval=30.0, step=0.25, group=qp_grp_cusum)
bool qp_diurnal_adj = input.bool(false, "Session-Aware Diurnal Baseline (Optional NQ 09:30 Filter)", group=qp_grp_cusum)
// --- 2. VOLATILITY RIBBON & HUD INPUTS ---
string qp_grp_vis = "2. Quantum Pulse — Ribbon & HUD Visuals"
int qp_center_len = input.int(8, "Ribbon Center EMA Length", minval=1, maxval=100, group=qp_grp_vis)
bool qp_use_sqrt = input.bool(true, "Root-Scale Basis-Point Ribbon (Fixes 0.0 bps Bug)", group=qp_grp_vis)
float qp_std_mult = input.float(1.75, "Root-Scale Ribbon Multiplier", minval=0.2, maxval=10.0, step=0.05, group=qp_grp_vis)
float qp_legacy_mult = input.float(100.0, "Legacy Variance Multiplier (if Root-Scale OFF)", minval=1.0, maxval=1000.0, group=qp_grp_vis)
float qp_squeeze_amt = input.float(0.30, "Building Compression Ratio", minval=0.0, maxval=0.9, step=0.05, group=qp_grp_vis)
float qp_break_exp = input.float(1.50, "Volatile Expansion Ratio", minval=1.0, maxval=5.0, step=0.1, group=qp_grp_vis)
bool qp_show_tech = input.bool(true, "Show Bottom-Right Technical HUD", group=qp_grp_vis)
bool qp_show_bg = input.bool(true, "Show Vertical Regime Background Shading", group=qp_grp_vis)
// --- CONSTANTS & PALETTE ---
float QP_LN2 = math.log(2.0)
float QP_Z_CAP = -math.log(1.0 - qp_q_cap)
float QP_DRIFT = -math.log(qp_gamma)
float QP_GAIN = 1.0 - 1.0 / qp_gamma
color qp_c_bg = color.new(#05080F, 15)
color qp_c_border = color.new(#00E5FF, 60)
color qp_c_cyan = #00E5FF
color qp_c_magenta = #FF00FF
color qp_c_amber = #FFB300
color qp_c_white = #FFFFFF
color qp_c_muted = #8A93A6
// --- MODULE 1: AV-CUSUM VOLATILITY ENGINE ---
bool qp_use_htf_5m = qp_tf_mode == "Locked 5-Minute HTF (Step Once Per 5m Bar)"
f_qp_htf_metrics() =>
float lr = math.log(high / math.max(low, 1e-12))
float y = lr * lr
float m = ta.median(y[qp_L_lag], qp_N_base)
float mf = ta.median(y[math.max(1, qp_L_lag / 4)], math.max(12, qp_N_base / 8))
[y, m, mf, time]
[qp_htf_Y, qp_htf_med, qp_htf_med_fast, qp_htf_time] = request.security(syminfo.tickerid, "5", f_qp_htf_metrics(), lookahead=barmerge.lookahead_off)
float qp_chart_lr = math.log(high / math.max(low, 1e-12))
float qp_chart_Y = qp_chart_lr * qp_chart_lr
float qp_chart_med = ta.median(qp_chart_Y[qp_L_lag], qp_N_base)
float qp_chart_med_fast = ta.median(qp_chart_Y[math.max(1, qp_L_lag / 4)], math.max(12, qp_N_base / 8))
float qp_Y_t = qp_use_htf_5m ? qp_htf_Y : qp_chart_Y
float qp_median_lagged = qp_use_htf_5m ? qp_htf_med : qp_chart_med
float qp_session_fast = qp_use_htf_5m ? qp_htf_med_fast : qp_chart_med_fast
bool qp_is_new_step = qp_use_htf_5m ? (ta.change(qp_htf_time) != 0) : true
float qp_eff_med = qp_diurnal_adj ? math.max(qp_median_lagged, 0.65 * qp_session_fast) : qp_median_lagged
float qp_sigma_hat_t = qp_eff_med / QP_LN2
bool qp_warmup_ok = not na(qp_sigma_hat_t) and qp_sigma_hat_t > 0.0
float qp_Z_t = qp_warmup_ok ? (qp_Y_t / qp_sigma_hat_t) : na
float qp_Z_tilde_t = na(qp_Z_t) ? na : math.min(qp_Z_t, QP_Z_CAP)
var float qp_S_committed = 0.0
var float qp_last_break_S = na
var int qp_lock_steps = 0
bool qp_this_bar_break = false
if barstate.isconfirmed and qp_is_new_step
if qp_lock_steps > 0
qp_lock_steps -= 1
qp_S_committed := 0.0
else if not na(qp_Z_tilde_t)
float qp_new_S = math.max(0.0, qp_S_committed + QP_DRIFT + QP_GAIN * qp_Z_tilde_t)
if qp_new_S > qp_h_thresh
qp_this_bar_break := true
qp_last_break_S := qp_new_S
qp_lock_steps := qp_reset_lock
qp_S_committed := 0.0
else
qp_S_committed := qp_new_S
float qp_S_live = na(qp_Z_tilde_t) ? na : (qp_this_bar_break ? qp_last_break_S : qp_S_committed)
float qp_pressure = (na(qp_S_live) or qp_h_thresh <= 0.0) ? na : (qp_S_live / qp_h_thresh)
bool qp_in_refractory = qp_lock_steps > 0 and not qp_this_bar_break
bool qp_in_squeeze = not qp_in_refractory and not qp_this_bar_break and not na(qp_pressure) and qp_pressure >= 0.30
bool qp_in_calm = not qp_in_refractory and not qp_in_squeeze and not qp_this_bar_break and not na(qp_pressure)
bool qp_in_warmup = na(qp_pressure)
// --- STATE MAPPING ---
string qp_state_txt = "INITIALIZING"
color qp_state_col = qp_c_muted
if qp_in_warmup
qp_state_txt := "LOADING..."
else if qp_this_bar_break
qp_state_txt := "REGIME BREAK"
qp_state_col := qp_c_magenta
else if qp_in_calm
qp_state_txt := "CALM"
qp_state_col := qp_c_cyan
else if qp_in_squeeze
qp_state_txt := "BUILDING"
qp_state_col := qp_c_amber
else if qp_in_refractory
qp_state_txt := "VOLATILE"
qp_state_col := qp_c_magenta
string qp_charge_txt = not qp_in_warmup ? (str.tostring(math.min(qp_pressure * 100.0, 100.0), "#.#") + " / 100") : "--"
string qp_status_txt = qp_in_warmup ? "SCROLL LEFT FOR DATA" : (qp_use_htf_5m ? "5M HTF SYNC (" + timeframe.period + ")" : "NATIVE (" + timeframe.period + ")")
color qp_status_col = qp_in_warmup ? qp_c_muted : qp_c_cyan
// --- RIBBON VISUALS ---
float qp_center = ta.ema(close, qp_center_len)
float qp_root_sigma = na(qp_sigma_hat_t) ? na : math.sqrt(qp_sigma_hat_t)
float qp_env_base_width = qp_use_sqrt ? (qp_root_sigma * qp_std_mult) : (qp_sigma_hat_t * qp_legacy_mult)
float qp_state_scale = 1.0
if qp_in_refractory or qp_this_bar_break
qp_state_scale := qp_break_exp
else if qp_in_squeeze
qp_state_scale := 1.0 - qp_squeeze_amt * math.min(qp_pressure, 1.0)
float qp_width_log = na(qp_env_base_width) ? na : (qp_env_base_width * qp_state_scale)
float qp_upper_band = na(qp_width_log) ? na : qp_center * math.exp( qp_width_log)
float qp_lower_band = na(qp_width_log) ? na : qp_center * math.exp(-qp_width_log)
color qp_band_color = color.new(qp_in_refractory or qp_this_bar_break ? qp_c_magenta : qp_in_squeeze ? qp_c_amber : qp_c_cyan, 70)
qp_p_up = plot(qp_upper_band, "QP Upper Volatility Band", color=qp_band_color, linewidth=2)
qp_p_lo = plot(qp_lower_band, "QP Lower Volatility Band", color=qp_band_color, linewidth=2)
fill(qp_p_up, qp_p_lo, color=qp_band_color, title="QP Ribbon Fill")
bgcolor(qp_show_bg ? (qp_in_refractory ? color.new(qp_c_magenta, 92) : qp_in_squeeze ? color.new(qp_c_amber, 92) : na) : na, title="QP Regime Shading")
if qp_this_bar_break
label.new(
x=bar_index, y=high,
text="VOLATILITY\nBREAK",
xloc=xloc.bar_index, yloc=yloc.abovebar,
style=label.style_label_down,
color=color.new(qp_c_magenta, 8),
textcolor=qp_c_white, size=size.tiny,
tooltip="QUANTUM PULSE VOLATILITY BREAK — Cumulative squared log-range CUSUM breached threshold h.\n" +
"Peak CUSUM: " + str.tostring(qp_last_break_S, "#.##") + " / h: " + str.tostring(qp_h_thresh, "#.##")
)
// --- TOP-RIGHT HUD ---
var table qp_hud = table.new(position.top_right, 2, 5, border_width=1, border_color=qp_c_border, bgcolor=qp_c_bg)
if barstate.islast
table.cell(qp_hud, 0, 0, "QUANTUM PULSE", text_color=qp_c_cyan, text_size=size.small, text_halign=text.align_left)
table.cell(qp_hud, 1, 0, "RADAR V1-PURE", text_color=qp_c_muted, text_size=size.small, text_halign=text.align_right)
table.cell(qp_hud, 0, 1, "STATE", text_color=qp_c_muted, text_size=size.small, text_halign=text.align_left)
table.cell(qp_hud, 1, 1, qp_state_txt, text_color=qp_state_col, text_size=size.small, text_halign=text.align_right)
table.cell(qp_hud, 0, 2, "CHARGE", text_color=qp_c_muted, text_size=size.small, text_halign=text.align_left)
table.cell(qp_hud, 1, 2, qp_charge_txt, text_color=qp_in_squeeze or qp_in_refractory or qp_this_bar_break ? qp_state_col : qp_c_muted, text_size=size.small, text_halign=text.align_right)
table.cell(qp_hud, 0, 3, "DIRECTION", text_color=qp_c_muted, text_size=size.small, text_halign=text.align_left)
table.cell(qp_hud, 1, 3, "NOT ASSESSED", text_color=qp_c_muted, text_size=size.small, text_halign=text.align_right)
table.cell(qp_hud, 0, 4, "STATUS", text_color=qp_c_muted, text_size=size.small, text_halign=text.align_left)
table.cell(qp_hud, 1, 4, qp_status_txt, text_color=qp_status_col, text_size=size.small, text_halign=text.align_right)
// --- BOTTOM-RIGHT TECHNICAL HUD ---
var table qp_tech = table.new(position.bottom_right, 2, 4, border_width=1, border_color=qp_c_muted, bgcolor=qp_c_bg)
if barstate.islast
if qp_show_tech
float qp_disp_vol_bps = na(qp_sigma_hat_t) ? na : (qp_use_sqrt ? qp_root_sigma * 10000.0 : qp_sigma_hat_t * 10000.0)
table.cell(qp_tech, 0, 0, "CUSUM (S_t/h)", text_color=qp_c_muted, text_size=size.small, text_halign=text.align_left)
table.cell(qp_tech, 1, 0, na(qp_S_live) ? "n/a" : str.tostring(qp_S_live, "#.##") + " / " + str.tostring(qp_h_thresh, "#.##"), text_color=qp_c_white, text_size=size.small, text_halign=text.align_right)
table.cell(qp_tech, 0, 1, "BASELINE VOL", text_color=qp_c_muted, text_size=size.small, text_halign=text.align_left)
table.cell(qp_tech, 1, 1, na(qp_disp_vol_bps) ? "n/a" : str.tostring(qp_disp_vol_bps, "#.##") + " bps", text_color=qp_c_white, text_size=size.small, text_halign=text.align_right)
table.cell(qp_tech, 0, 2, "ENVELOPE", text_color=qp_c_muted, text_size=size.small, text_halign=text.align_left)
table.cell(qp_tech, 1, 2, na(qp_width_log) ? "n/a" : str.tostring(qp_width_log * 10000.0, "#.#") + " bps", text_color=qp_c_white, text_size=size.small, text_halign=text.align_right)
table.cell(qp_tech, 0, 3, "THRESHOLD", text_color=qp_c_muted, text_size=size.small, text_halign=text.align_left)
table.cell(qp_tech, 1, 3, str.tostring(qp_h_thresh, "#.##"), text_color=qp_c_white, text_size=size.small, text_halign=text.align_right)
else
table.clear(qp_tech, 0, 0, 1, 3)
bool qp_enter_squeeze = qp_in_squeeze and not qp_in_squeeze[1]
alertcondition(qp_this_bar_break, title="QP V1 | Volatility Regime Break", message="Quantum Pulse V1: Volatility Break confirmed on {{ticker}} {{interval}}.")
alertcondition(qp_enter_squeeze, title="QP V1 | CUSUM Entering Accumulation", message="Quantum Pulse V1: CUSUM charge crossed 30% on {{ticker}} {{interval}}.")
// =============================================================================
// 3. STRUCTURAL EXECUTION EVENTS (EXACT RC6.1 LOGIC + ZERO-VOLUME FALLBACK)
// =============================================================================
string qp_grp_exec = "3. Quantum Pulse — Structural Execution Events"
bool qp_exec_enable = input.bool(true, "Enable Structural Event Markers", group=qp_grp_exec)
bool qp_exec_marks = input.bool(true, "Show SWP & BRK Chart Markers", group=qp_grp_exec)
bool qp_exec_dash = input.bool(true, "Show Bottom-Left Execution HUD", group=qp_grp_exec)
bool qp_vol_fallback = input.bool(true, "Zero-Volume Fallback (Uses True Range if Volume is Missing on 30s BTC)", group=qp_grp_exec, tooltip="Does NOT change NQ1! at all (NQ1! has real volume). Only activates if a feed reports `na` volume.")
bool qp_trend_filter = input.bool(false, "Experimental: Suppress Counter-Trend Sweeps (DEFAULT OFF — Keep OFF for RC6.1 Parity)", group=qp_grp_exec, tooltip="Keep OFF to get the exact same SWP-UP and SWP-DN climax signals from your NQ1! video.")
float qp_max_swp_er = input.float(0.45, "Max ER If Experimental Sweep Filter is ON", minval=0.15, maxval=1.0, step=0.05, group=qp_grp_exec)
int qp_struct_len = input.int(20, "Prior Structural Range Lookback (bars)", minval=5, maxval=100, group=qp_grp_exec)
int qp_er_len = input.int(8, "Kaufman Efficiency Ratio Window (bars)", minval=2, maxval=50, group=qp_grp_exec)
float qp_swp_buf = input.float(0.08, "Sweep Excursion Depth (ATR units)", minval=0.0, maxval=1.0, step=0.01, group=qp_grp_exec)
float qp_brk_buf = input.float(0.06, "Breakout Displacement Margin (ATR units)", minval=0.0, maxval=1.0, step=0.01, group=qp_grp_exec)
float qp_min_rvol = input.float(0.90, "Sweep Minimum Relative Volume (RVOL)", minval=0.0, maxval=5.0, step=0.05, group=qp_grp_exec)
float qp_burst_rvol = input.float(1.20, "Displacement Minimum Relative Volume (RVOL)", minval=0.0, maxval=5.0, step=0.05, group=qp_grp_exec)
int qp_exec_cool = input.int(3, "Per-Family Cooldown (bars)", minval=0, maxval=50, group=qp_grp_exec)
float qp_atr = ta.atr(14)
float qp_tr = ta.tr(true)
float qp_tr_base = ta.sma(qp_tr, 20)
float qp_rtr = (not na(qp_tr_base) and qp_tr_base > 0) ? (qp_tr / qp_tr_base) : na
float qp_vbase = ta.sma(volume, 20)
bool qp_vol_valid = not na(volume) and not na(qp_vbase) and qp_vbase > 0
bool qp_using_rtr = not qp_vol_valid and qp_vol_fallback and not na(qp_rtr)
float qp_rvol = qp_vol_valid ? (volume / qp_vbase) : (qp_using_rtr ? qp_rtr : na)
bool qp_part_ok = qp_vol_valid or qp_using_rtr
float qp_span = math.max(high - low, syminfo.mintick)
float qp_body = math.abs(close - open) / qp_span
float qp_close_loc = (close - low) / qp_span
float qp_prev_high = ta.highest(high[1], qp_struct_len)
float qp_prev_low = ta.lowest(low[1], qp_struct_len)
float qp_abs_move = math.abs(ta.change(close))
float qp_noise = ta.sma(qp_abs_move, qp_er_len) * qp_er_len
float qp_er = (not na(qp_noise) and qp_noise > 0) ? (math.abs(close - close[qp_er_len]) / qp_noise) : na
float qp_guard_atr = qp_atr[1]
bool qp_ready = not na(qp_prev_high) and not na(qp_prev_low) and not na(qp_guard_atr) and qp_guard_atr > 0 and qp_part_ok and not na(qp_er)
bool qp_block_short_swp = qp_trend_filter and (qp_er >= qp_max_swp_er) and (close > qp_center) and (qp_center > nz(qp_center[qp_er_len], qp_center))
bool qp_block_long_swp = qp_trend_filter and (qp_er >= qp_max_swp_er) and (close < qp_center) and (qp_center < nz(qp_center[qp_er_len], qp_center))
bool qp_raw_swp_long = qp_ready and not qp_block_long_swp and low < qp_prev_low - qp_swp_buf * qp_guard_atr and close > qp_prev_low and close > open and qp_close_loc >= 0.65 and qp_body >= 0.25 and qp_rvol >= qp_min_rvol
bool qp_raw_swp_short = qp_ready and not qp_block_short_swp and high > qp_prev_high + qp_swp_buf * qp_guard_atr and close < qp_prev_high and close < open and qp_close_loc <= 0.35 and qp_body >= 0.25 and qp_rvol >= qp_min_rvol
bool qp_raw_brk_long = qp_ready and close > qp_prev_high + qp_brk_buf * qp_guard_atr and close > open and qp_close_loc >= 0.70 and qp_body >= 0.50 and qp_er >= 0.25 and qp_rvol >= qp_burst_rvol
bool qp_raw_brk_short = qp_ready and close < qp_prev_low - qp_brk_buf * qp_guard_atr and close < open and qp_close_loc <= 0.30 and qp_body >= 0.50 and qp_er >= 0.25 and qp_rvol >= qp_burst_rvol
var int qp_last_swp_bar = na
var int qp_last_brk_bar = na
bool qp_swp_long = false
bool qp_swp_short = false
bool qp_brk_long = false
bool qp_brk_short = false
bool qp_swp_allowed = na(qp_last_swp_bar) or (bar_index - qp_last_swp_bar > qp_exec_cool)
bool qp_brk_allowed = na(qp_last_brk_bar) or (bar_index - qp_last_brk_bar > qp_exec_cool)
if barstate.isconfirmed
if qp_swp_allowed
qp_swp_long := qp_raw_swp_long and not qp_raw_swp_short
qp_swp_short := qp_raw_swp_short and not qp_raw_swp_long
if qp_swp_long or qp_swp_short
qp_last_swp_bar := bar_index
if qp_brk_allowed
qp_brk_long := qp_raw_brk_long and not qp_raw_brk_short and not qp_swp_long
qp_brk_short := qp_raw_brk_short and not qp_raw_brk_long and not qp_swp_short
if qp_brk_long or qp_brk_short
qp_last_brk_bar := bar_index
plotshape(qp_exec_enable and qp_exec_marks and qp_swp_long, title="QP | SWP-UP (Sweep Reclaim)", style=shape.labelup, location=location.belowbar, color=#00E5FF, text="SWP-UP", textcolor=#05080F, size=size.tiny)
plotshape(qp_exec_enable and qp_exec_marks and qp_swp_short, title="QP | SWP-DN (Sweep Reject)", style=shape.labeldown, location=location.abovebar, color=#FF00FF, text="SWP-DN", textcolor=color.white, size=size.tiny)
plotshape(qp_exec_enable and qp_exec_marks and qp_brk_long, title="QP | BRK-UP (Upside Breakout)", style=shape.triangleup, location=location.belowbar, color=#00E5FF, text="BRK-UP", textcolor=#00E5FF, size=size.tiny)
plotshape(qp_exec_enable and qp_exec_marks and qp_brk_short, title="QP | BRK-DN (Downside Breakdown)", style=shape.triangledown, location=location.abovebar, color=#FF00FF, text="BRK-DN", textcolor=#FF00FF, size=size.tiny)
plot(qp_exec_enable ? qp_er : na, title="QP | Efficiency Ratio ER(8)", display=display.data_window)
plot(qp_exec_enable ? qp_rvol : na, title="QP | Relative Participation", display=display.data_window)
var int qp_cnt_swp = 0
var int qp_cnt_brk = 0
var string qp_last_evt_txt = "NONE YET"
var int qp_last_evt_bar = na
var color qp_last_evt_col = #8A93A6
if barstate.isconfirmed
if qp_swp_long or qp_swp_short
qp_cnt_swp += 1
if qp_brk_long or qp_brk_short
qp_cnt_brk += 1
if qp_swp_long
qp_last_evt_txt := "SWP-UP · LOW RECLAIMED"
qp_last_evt_bar := bar_index
qp_last_evt_col := #00E5FF
else if qp_swp_short
qp_last_evt_txt := "SWP-DN · HIGH REJECTED"
qp_last_evt_bar := bar_index
qp_last_evt_col := #FF00FF
else if qp_brk_long
qp_last_evt_txt := "BRK-UP · DISPLACEMENT"
qp_last_evt_bar := bar_index
qp_last_evt_col := #00E5FF
else if qp_brk_short
qp_last_evt_txt := "BRK-DN · DISPLACEMENT"
qp_last_evt_bar := bar_index
qp_last_evt_col := #FF00FF
var table qp_exec_hud = table.new(position.bottom_left, 2, 5, border_width=1, border_color=color.new(#00E5FF, 75), bgcolor=color.new(#05080F, 12))
if barstate.islast
if qp_exec_dash
string qp_run_txt = qp_exec_enable ? ("ON · CHART " + timeframe.period) : "OFF · DISABLED"
string qp_last_txt = qp_exec_enable ? qp_last_evt_txt : "DISABLED"
string qp_age_txt = na(qp_last_evt_bar) ? "NO CONFIRMED EVENT" : (str.tostring(bar_index - qp_last_evt_bar) + " bars ago")
string qp_part_lbl = qp_using_rtr ? "ER(8) / RTR(20)" : "ER(8) / RVOL(20)"
table.cell(qp_exec_hud, 0, 0, "QUANTUM PULSE", text_color=#00E5FF, text_size=size.small)
table.cell(qp_exec_hud, 1, 0, "STRUCTURAL EVENTS", text_color=color.white, text_size=size.small)
table.cell(qp_exec_hud, 0, 1, "ENGINE", text_color=#8A93A6, text_size=size.tiny)
table.cell(qp_exec_hud, 1, 1, qp_run_txt, text_color=qp_exec_enable ? #00E5FF : #FFB300, text_size=size.small)
table.cell(qp_exec_hud, 0, 2, "LAST EVENT", text_color=#8A93A6, text_size=size.tiny)
table.cell(qp_exec_hud, 1, 2, qp_last_txt + " · " + qp_age_txt, text_color=qp_exec_enable ? qp_last_evt_col : #8A93A6, text_size=size.tiny)
table.cell(qp_exec_hud, 0, 3, qp_part_lbl, text_color=#8A93A6, text_size=size.tiny)
table.cell(qp_exec_hud, 1, 3, (na(qp_er) ? "n/a" : str.tostring(qp_er, "#.##")) + " / " + (na(qp_rvol) ? "n/a" : str.tostring(qp_rvol, "#.##")), text_color=color.white, text_size=size.tiny)
table.cell(qp_exec_hud, 0, 4, "SESSION TOTALS", text_color=#8A93A6, text_size=size.tiny)
table.cell(qp_exec_hud, 1, 4, str.tostring(qp_cnt_swp) + " SWP / " + str.tostring(qp_cnt_brk) + " BRK", text_color=color.white, text_size=size.tiny)
else
table.clear(qp_exec_hud, 0, 0, 1, 4)