Apex Effort vs. Result & Absorption

DarkPoolCrypto · study · 379 行 · 点赞 19 · TradingView 原页

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

Pine Script

// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © DarkPoolCrypto
 
//@version=6
indicator("Apex Effort vs. Result & Absorption [DarkPoolCrypto]", shorttitle="Apex E/R", overlay=true, max_boxes_count=500, max_lines_count=500, max_labels_count=500)
 
// ════════════════════════════════════════════════════════════════════════════
// 1. SYSTEM CONFIGURATION & INPUTS
// ════════════════════════════════════════════════════════════════════════════
 
// --- Efficiency Baseline & Regime ---
string grp_base   = "Efficiency Baseline & Regime"
int    len_base   = input.int(34, "Efficiency Baseline Length", minval=5, group=grp_base, tooltip="Lookback period for the Volume-Weighted Efficiency Baseline.")
int    len_ker    = input.int(14, "Fractal Efficiency (KER) Length", minval=3, group=grp_base, tooltip="Lookback period for the Kaufman Efficiency Ratio, measuring directional trend efficiency versus sideways chop.")
float  atr_mult   = input.float(1.6, "Equilibrium Channel Multiplier", minval=0.2, step=0.1, group=grp_base, tooltip="Width of the ATR volatility regime channel around the baseline.")
 
// --- Effort vs. Result (Wyckoff Absorption Engine) ---
string grp_er     = "Effort vs. Result (Absorption Engine)"
bool   conf_only  = input.bool(true, "Confirm Signals on Bar Close Only", group=grp_er, tooltip="When enabled, Absorption zones, Retest Defenses, and Initiative Breakouts only commit on a confirmed bar close, eliminating intrabar signal instability.")
int    len_er     = input.int(20, "Relative Volume & Spread Lookback", minval=5, group=grp_er, tooltip="Lookback period used to normalize Volume (Effort) and Candle Spread (Result).")
int    swing_len  = input.int(5, "Structural Extreme Lookback", minval=2, group=grp_er, tooltip="Requires Absorption anomalies to occur at or beyond the lowest low / highest high of the last N bars.")
float  vol_thresh = input.float(1.4, "High Effort (Volume) Threshold", minval=1.0, step=0.1, group=grp_er, tooltip="Minimum multiple of average volume required to classify a bar as High Effort (1.4 = 140% of average volume).")
float  abs_ratio  = input.float(1.8, "Wick-Weighted Absorption Ratio", minval=1.1, step=0.1, group=grp_er, tooltip="Sensitivity for detecting Absorption (Relative Effort * Wick Rejection Ratio / Relative Body Result). Higher values filter for more extreme anomalies.")
string min_grade  = input.string("All (A, B, C)", "Minimum Absorption Grade", options=["All (A, B, C)", "A & B Only", "A-Grade Only"], group=grp_er, tooltip="Filter absorption signals by confluence grade:\nA-Grade: Aligned with Regime + KER >= 0.30\nB-Grade: Aligned with Regime OR KER >= 0.30\nC-Grade: Isolated / Counter-trend anomaly.")
bool   show_brk   = input.bool(true, "Show Initiative Breakouts", group=grp_er, tooltip="Highlights confirmed directional candles where High Volume (Effort) produces Wide Body Spread (Result) breaking out of the Equilibrium Channel.")
 
// --- Absorption Zone & Retest Management ---
string grp_zones  = "Unmitigated Absorption Zones"
bool   show_zones = input.bool(true, "Project Absorption Zones", group=grp_zones, tooltip="Projects horizontal wick absorption zones from confirmed anomaly bars until price closes beyond them.")
bool   show_rt    = input.bool(true, "Show Zone Retest Defenses (DEF)", group=grp_zones, tooltip="Plots a DEF marker when price pulls back into an unmitigated Absorption Zone and rejects out of it.")
string rt_mode    = input.string("First Defense Only", "Retest Signal Frequency", options=["First Defense Only", "Fresh Touch After Exit", "All Defenses"], group=grp_zones, tooltip="'First Defense Only' plots only the very first successful defense per zone to prevent signal clustering. 'Fresh Touch After Exit' requires price to leave the zone completely before re-arming.")
int    max_zones  = input.int(6, "Max Active Zones Per Side", minval=1, maxval=30, group=grp_zones, tooltip="Maximum number of unmitigated Bullish and Bearish absorption zones tracked at one time.")
bool   keep_mit   = input.bool(false, "Keep Mitigated Zones on Chart", group=grp_zones, tooltip="When enabled, zones broken by price remain visible in historical bars up to the exact candle that mitigated them.")
 
// --- Visual Interface ---
string grp_vis    = "Visual Interface"
color  c_bull     = input.color(#00E676, "Bullish Regime Color", group=grp_vis, tooltip="Primary color for Bullish Regime and Initiative Breakouts.")
color  c_bear     = input.color(#FF1744, "Bearish Regime Color", group=grp_vis, tooltip="Primary color for Bearish Regime and Initiative Breakouts.")
color  c_abs_bull = input.color(#00B0FF, "Demand Absorption Color", group=grp_vis, tooltip="Color for Bullish Demand Absorption zones, markers, and bars.")
color  c_abs_bear = input.color(#FF9100, "Supply Absorption Color", group=grp_vis, tooltip="Color for Bearish Supply Absorption zones, markers, and bars.")
color  c_neu      = input.color(#78909C, "Neutral / Mitigated Color", group=grp_vis, tooltip="Color for neutral consolidation and mitigated historical zones.")
color  c_text     = input.color(#FFFFFF, "Text Color", group=grp_vis, tooltip="Text color for labels and HUD table cells.")
bool   color_bars = input.bool(true, "Color Candles by Effort/Regime", group=grp_vis, tooltip="Colors candles based on regime state while highlighting absorption candles in distinct colors.")
int    cloud_trans= input.int(84, "Channel Fill Transparency", minval=0, maxval=100, group=grp_vis, tooltip="Transparency of the Equilibrium Channel fill (0 = solid, 100 = invisible).")
int    zone_trans = input.int(80, "Absorption Zone Transparency", minval=0, maxval=100, group=grp_vis, tooltip="Transparency of the unmitigated Absorption Zone boxes.")
 
// --- Analytics HUD ---
string grp_hud    = "Analytics HUD"
bool   show_hud   = input.bool(true, "Show Live HUD", group=grp_hud, tooltip="Displays the real-time Effort vs. Result telemetry table.")
string hud_pos    = input.string("Top Right", "HUD Position", options=["Top Right", "Bottom Right", "Top Left", "Bottom Left"], group=grp_hud, tooltip="Select which corner of the chart the HUD is anchored to.")
string hud_sz     = input.string("Small", "HUD Text Size", options=["Tiny", "Small", "Normal"], group=grp_hud, tooltip="Text size inside the HUD.")
color  hud_bg     = input.color(color.new(#0D1117, 15), "HUD Background", group=grp_hud, tooltip="Background color and transparency of the HUD table.")
 
// ════════════════════════════════════════════════════════════════════════════
// 2. CORE EFFORT VS. RESULT & FRACTAL EFFICIENCY MATHEMATICS
// ════════════════════════════════════════════════════════════════════════════
 
// --- Pre-calculate All Stateful Series (Guarantees Zero Pine v6 Warnings) ---
bool  has_vol     = not na(volume) and volume > 0
float vol_sma     = ta.sma(volume, len_er)
float atr_er      = ta.atr(len_er)
float atr_main    = ta.atr(len_base)
float vwma_val    = ta.vwma(close, len_base)
float hma_val     = ta.hma(close, len_base)
float lowest_sw   = ta.lowest(low, swing_len)[1]
float highest_sw  = ta.highest(high, swing_len)[1]
 
// --- Bar Confirmation Gate ---
bool bar_ready    = not conf_only or barstate.isconfirmed
 
// --- Kaufman Fractal Efficiency Ratio (KER) ---
float net_change  = math.abs(close - nz(close[len_ker], close))
float sum_changes = math.sum(math.abs(close - nz(close[1], close)), len_ker)
float ker_val     = sum_changes > 0 ? (net_change / sum_changes) : 0.0
 
// --- Candle Anatomy & Wick Ratios ---
float bar_range   = math.max(high - low, syminfo.mintick)
float body_top    = math.max(open, close)
float body_bot    = math.min(open, close)
float body_size   = body_top - body_bot
float upper_wick  = high - body_top
float lower_wick  = body_bot - low
float lw_ratio    = lower_wick / bar_range
float uw_ratio    = upper_wick / bar_range
 
// --- Relative Effort (Volume or Explicit Range Proxy Fallback) ---
float rel_effort  = has_vol and vol_sma > 0 ? (volume / vol_sma) : (bar_range / math.max(atr_er, syminfo.mintick))
 
// --- Relative Result (Normalized Net Body Displacement) ---
float body_atr    = atr_er > 0 ? (body_size / atr_er) : 1.0
float safe_result = math.max(body_atr, 0.15)
 
// --- Wick-Weighted Effort-to-Result Absorption Scores ---
// Incorporates rejecting wick proportion directly into the anomaly score
float er_raw      = rel_effort / safe_result
float er_bull_idx = (rel_effort * (1.0 + lw_ratio)) / safe_result
float er_bear_idx = (rel_effort * (1.0 + uw_ratio)) / safe_result
 
// --- Volume-Weighted Efficiency Baseline & Equilibrium Channel ---
float base_raw    = has_vol ? math.avg(vwma_val, hma_val) : hma_val
float upper_band  = base_raw + (atr_main * atr_mult)
float lower_band  = base_raw - (atr_main * atr_mult)
 
// --- Regime State Machine (Confirmed Hysteresis) ---
var int regime = 0
if close > upper_band
    regime := 1
else if close < lower_band
    regime := -1
 
// --- Detecting Raw Absorption Anomalies ---
bool is_high_effort = rel_effort >= vol_thresh
bool bull_wick_dom  = (lower_wick > upper_wick and lw_ratio >= 0.35) or (close > open and body_size <= bar_range * 0.30 and lw_ratio >= 0.25)
bool bear_wick_dom  = (upper_wick > lower_wick and uw_ratio >= 0.35) or (close < open and body_size <= bar_range * 0.30 and uw_ratio >= 0.25)
 
bool raw_bull_abs   = is_high_effort and er_bull_idx >= abs_ratio and bull_wick_dom and low <= lowest_sw
bool raw_bear_abs   = is_high_effort and er_bear_idx >= abs_ratio and bear_wick_dom and high >= highest_sw
 
// --- Signal Quality Classification (A, B, C Grading) ---
// A-Grade: Aligned with established Regime AND Trending Efficiency (KER >= 0.30)
// B-Grade: Aligned with either established Regime OR Trending Efficiency
// C-Grade: Counter-trend / isolated stopping volume anomaly
string bull_grade = (regime == 1 and ker_val >= 0.30) ? "A" : (regime == 1 or ker_val >= 0.30) ? "B" : "C"
string bear_grade = (regime == -1 and ker_val >= 0.30) ? "A" : (regime == -1 or ker_val >= 0.30) ? "B" : "C"
 
bool pass_bull_grade = min_grade == "All (A, B, C)" or (min_grade == "A & B Only" and bull_grade != "C") or (min_grade == "A-Grade Only" and bull_grade == "A")
bool pass_bear_grade = min_grade == "All (A, B, C)" or (min_grade == "A & B Only" and bear_grade != "C") or (min_grade == "A-Grade Only" and bear_grade == "A")
 
bool bull_abs = bar_ready and raw_bull_abs and pass_bull_grade
bool bear_abs = bar_ready and raw_bear_abs and pass_bear_grade
 
// --- Detecting True Initiative Breakouts (Strictly Validated Candle Direction) ---
bool init_bull = bar_ready and show_brk and is_high_effort and close > open and body_atr >= 1.20 and close > upper_band and close[1] <= upper_band[1]
bool init_bear = bar_ready and show_brk and is_high_effort and close < open and body_atr >= 1.20 and close < lower_band and close[1] >= lower_band[1]
 
// ════════════════════════════════════════════════════════════════════════════
// 3. UNMITIGATED ABSORPTION ZONES & STATEFUL RETEST ENGINE
// ════════════════════════════════════════════════════════════════════════════
 
var array<box>   bull_boxes  = array.new<box>()
var array<label> bull_labels = array.new<label>()
var array<bool>  bull_tested = array.new<bool>()
 
var array<box>   bear_boxes  = array.new<box>()
var array<label> bear_labels = array.new<label>()
var array<bool>  bear_tested = array.new<bool>()
 
// Helper Function: Cap Active Array Size (FIFO Always Deletes Unmitigated Orphans)
clean_zone_arrays(array<box> b_arr, array<label> lb_arr, array<bool> t_arr, int max_lim) =>
    while array.size(b_arr) > max_lim
        box   old_b  = array.shift(b_arr)
        label old_lb = array.shift(lb_arr)
        array.shift(t_arr)
        // Always delete FIFO-evicted active zones so unmitigated boxes never orphan on chart
        box.delete(old_b)
        label.delete(old_lb)
 
// Create Confirmed Bullish Demand Absorption Zone
if bull_abs and show_zones
    float z_bot = low
    float z_top = math.max(body_bot, low + (bar_range * 0.25))
    string lbl_t = "Demand Abs [" + bull_grade + "] (" + str.tostring(z_bot, format.mintick) + ")"
    box   nb    = box.new(bar_index, z_top, bar_index + 5, z_bot, border_color=color.new(c_abs_bull, 35), bgcolor=color.new(c_abs_bull, zone_trans))
    label nlb   = label.new(bar_index + 5, z_bot, lbl_t, color=color.new(c_abs_bull, 100), textcolor=c_abs_bull, style=label.style_label_left, size=size.tiny)
    array.push(bull_boxes, nb)
    array.push(bull_labels, nlb)
    array.push(bull_tested, false)
    clean_zone_arrays(bull_boxes, bull_labels, bull_tested, max_zones)
 
// Create Confirmed Bearish Supply Absorption Zone
if bear_abs and show_zones
    float z_top = high
    float z_bot = math.min(body_top, high - (bar_range * 0.25))
    string lbl_t = "Supply Abs [" + bear_grade + "] (" + str.tostring(z_top, format.mintick) + ")"
    box   nb    = box.new(bar_index, z_top, bar_index + 5, z_bot, border_color=color.new(c_abs_bear, 35), bgcolor=color.new(c_abs_bear, zone_trans))
    label nlb   = label.new(bar_index + 5, z_top, lbl_t, color=color.new(c_abs_bear, 100), textcolor=c_abs_bear, style=label.style_label_left, size=size.tiny)
    array.push(bear_boxes, nb)
    array.push(bear_labels, nlb)
    array.push(bear_tested, false)
    clean_zone_arrays(bear_boxes, bear_labels, bear_tested, max_zones)
 
// Track Retests on Current Bar
bool retest_bull = false
bool retest_bear = false
 
// Bar-by-Bar Zone Extension, Stateful Retest Detection & Mitigation
if show_zones
    // Manage Active Bullish Demand Absorption Zones
    if array.size(bull_boxes) > 0
        for i = array.size(bull_boxes) - 1 to 0
            box   b        = array.get(bull_boxes, i)
            label lb       = array.get(bull_labels, i)
            bool  was_test = array.get(bull_tested, i)
            float z_top    = box.get_top(b)
            float z_bot    = box.get_bottom(b)
            int   start    = box.get_left(b)
 
            if bar_index > start
                // Mitigated only when a confirmed bar closes strictly below the Demand Absorption low
                if bar_ready and close < z_bot
                    if keep_mit
                        box.set_right(b, bar_index)
                        box.set_bgcolor(b, color.new(c_neu, 92))
                        box.set_border_color(b, color.new(c_neu, 75))
                        box.set_border_style(b, line.style_dotted)
                    else
                        box.delete(b)
                    label.delete(lb)
                    array.remove(bull_boxes, i)
                    array.remove(bull_labels, i)
                    array.remove(bull_tested, i)
                else
                    box.set_right(b, bar_index + 6)
                    label.set_x(lb, bar_index + 6)
 
                    // Reset tested flag if price completely clears the zone and mode is "Fresh Touch After Exit"
                    if rt_mode == "Fresh Touch After Exit" and low > z_top
                        was_test := false
                        array.set(bull_tested, i, false)
 
                    // Detect Confirmed Bullish Zone Defense
                    bool can_fire = rt_mode == "All Defenses" or not was_test
                    if bar_ready and can_fire and low <= z_top and close > z_top and close > open
                        retest_bull := true
                        array.set(bull_tested, i, true)
 
    // Manage Active Bearish Supply Absorption Zones
    if array.size(bear_boxes) > 0
        for i = array.size(bear_boxes) - 1 to 0
            box   b        = array.get(bear_boxes, i)
            label lb       = array.get(bear_labels, i)
            bool  was_test = array.get(bear_tested, i)
            float z_top    = box.get_top(b)
            float z_bot    = box.get_bottom(b)
            int   start    = box.get_left(b)
 
            if bar_index > start
                // Mitigated only when a confirmed bar closes strictly above the Supply Absorption high
                if bar_ready and close > z_top
                    if keep_mit
                        box.set_right(b, bar_index)
                        box.set_bgcolor(b, color.new(c_neu, 92))
                        box.set_border_color(b, color.new(c_neu, 75))
                        box.set_border_style(b, line.style_dotted)
                    else
                        box.delete(b)
                    label.delete(lb)
                    array.remove(bear_boxes, i)
                    array.remove(bear_labels, i)
                    array.remove(bear_tested, i)
                else
                    box.set_right(b, bar_index + 6)
                    label.set_x(lb, bar_index + 6)
 
                    // Reset tested flag if price completely clears the zone and mode is "Fresh Touch After Exit"
                    if rt_mode == "Fresh Touch After Exit" and high < z_bot
                        was_test := false
                        array.set(bear_tested, i, false)
 
                    // Detect Confirmed Bearish Zone Defense
                    bool can_fire = rt_mode == "All Defenses" or not was_test
                    if bar_ready and can_fire and high >= z_bot and close < z_bot and close < open
                        retest_bear := true
                        array.set(bear_tested, i, true)
 
// ════════════════════════════════════════════════════════════════════════════
// 4. PLOTTING & VISUALS
// ════════════════════════════════════════════════════════════════════════════
 
// Plot Efficiency Baseline & Equilibrium Channel
color reg_col = regime == 1 ? c_bull : regime == -1 ? c_bear : c_neu
p_base = plot(base_raw, "Efficiency Baseline", color=color.new(reg_col, 15), linewidth=2)
p_up   = plot(upper_band, "Upper Equilibrium Band", color=color.new(reg_col, 65), linewidth=1)
p_dn   = plot(lower_band, "Lower Equilibrium Band", color=color.new(reg_col, 65), linewidth=1)
fill(p_up, p_dn, color=color.new(reg_col, cloud_trans), title="Equilibrium Regime Cloud")
 
// Plot Graded Absorption Diamonds (A, B, C)
plotshape(bull_abs and bull_grade == "A", "Bullish Absorption (Grade A)", shape.diamond, location.belowbar, c_abs_bull, 0, "ABS-A", c_abs_bull, size=size.tiny)
plotshape(bull_abs and bull_grade == "B", "Bullish Absorption (Grade B)", shape.diamond, location.belowbar, c_abs_bull, 0, "ABS-B", c_abs_bull, size=size.tiny)
plotshape(bull_abs and bull_grade == "C", "Bullish Absorption (Grade C)", shape.diamond, location.belowbar, c_abs_bull, 0, "ABS-C", c_abs_bull, size=size.tiny)
 
plotshape(bear_abs and bear_grade == "A", "Bearish Absorption (Grade A)", shape.diamond, location.abovebar, c_abs_bear, 0, "ABS-A", c_abs_bear, size=size.tiny)
plotshape(bear_abs and bear_grade == "B", "Bearish Absorption (Grade B)", shape.diamond, location.abovebar, c_abs_bear, 0, "ABS-B", c_abs_bear, size=size.tiny)
plotshape(bear_abs and bear_grade == "C", "Bearish Absorption (Grade C)", shape.diamond, location.abovebar, c_abs_bear, 0, "ABS-C", c_abs_bear, size=size.tiny)
 
// Plot Zone Defense Retest Signals
plotshape(show_rt and retest_bull and not bull_abs, "Demand Zone Retest Defense", shape.triangleup, location.belowbar, c_abs_bull, 0, "DEF", c_text, size=size.tiny)
plotshape(show_rt and retest_bear and not bear_abs, "Supply Zone Retest Defense", shape.triangledown, location.abovebar, c_abs_bear, 0, "DEF", c_text, size=size.tiny)
 
// Plot Initiative Breakouts
plotshape(init_bull, "Bullish Initiative Breakout", shape.labelup, location.belowbar, c_bull, 0, "INIT", c_text, size=size.small)
plotshape(init_bear, "Bearish Initiative Breakout", shape.labeldown, location.abovebar, c_bear, 0, "INIT", c_text, size=size.small)
 
// Candle Coloring
color bar_c = bull_abs ? c_abs_bull : bear_abs ? c_abs_bear : reg_col
barcolor(color_bars ? bar_c : na, title="Effort/Regime Candle Color")
 
// ════════════════════════════════════════════════════════════════════════════
// 5. LIVE TELEMETRY HUD WITH HOVER TOOLTIPS
// ════════════════════════════════════════════════════════════════════════════
 
pos_hud = switch hud_pos
    "Top Right"    => position.top_right
    "Top Left"     => position.top_left
    "Bottom Right" => position.bottom_right
    => position.bottom_left
 
var table hud = table.new(pos_hud, 2, 7, bgcolor=hud_bg, border_width=1, border_color=color.new(c_neu, 60))
 
if show_hud and barstate.islast
    sz = switch hud_sz
        "Tiny"  => size.tiny
        "Small" => size.small
        => size.normal
 
    // Header Status (Explicitly shows whether current bar is Provisional or Confirmed)
    string status_txt = barstate.isconfirmed ? "CONFIRMED" : "LIVE (PROV)"
    string status_tip = barstate.isconfirmed ? "Current bar is closed and signals are locked." : "Intrabar telemetry is updating in real-time.\nSignals lock on candle close when 'Confirm Signals on Bar Close Only' is enabled."
    table.cell(hud, 0, 0, "APEX EFFORT / RESULT", text_color=c_text, bgcolor=color.new(reg_col, 25), text_size=sz, text_halign=text.align_left, tooltip="Wyckoff Effort vs. Result & Absorption Engine V2\nHover over any row for exact mathematical telemetry.")
    table.cell(hud, 1, 0, status_txt, text_color=c_text, bgcolor=color.new(reg_col, 25), text_size=sz, text_halign=text.align_right, tooltip=status_tip)
 
    // 1. Regime State (Distinguishes Active Impulse vs. Pullback Inside Channel)
    string reg_sub = (regime == 1 and close > upper_band) ? "BULL (IMPULSE)" : (regime == 1) ? "BULL (PULLBACK)" : (regime == -1 and close < lower_band) ? "BEAR (IMPULSE)" : (regime == -1) ? "BEAR (PULLBACK)" : "NEUTRAL"
    string reg_tip = "Established Regime: " + (regime == 1 ? "Bullish" : regime == -1 ? "Bearish" : "Neutral") + "\nEfficiency Baseline (" + str.tostring(len_base) + "): " + str.tostring(base_raw, format.mintick) + "\nUpper Band: " + str.tostring(upper_band, format.mintick) + "\nLower Band: " + str.tostring(lower_band, format.mintick)
    table.cell(hud, 0, 1, "Regime State", text_color=c_text, text_size=sz, text_halign=text.align_left, tooltip=reg_tip)
    table.cell(hud, 1, 1, reg_sub, text_color=reg_col, text_size=sz, text_halign=text.align_right, tooltip=reg_tip)
 
    // 2. Fractal Efficiency (KER)
    string ker_state = ker_val >= 0.40 ? "TRENDING (" + str.tostring(math.round(ker_val * 100)) + "%)" : ker_val <= 0.20 ? "CHOP (" + str.tostring(math.round(ker_val * 100)) + "%)" : "MODERATE (" + str.tostring(math.round(ker_val * 100)) + "%)"
    color  ker_col   = ker_val >= 0.40 ? c_bull : ker_val <= 0.20 ? c_abs_bear : c_neu
    string ker_tip   = "Kaufman Fractal Efficiency Ratio (" + str.tostring(len_ker) + " bars): " + str.tostring(math.round(ker_val, 3)) + "\nMeasures directional displacement vs. bar-to-bar noise (100% = straight line, 0% = pure chop)."
    table.cell(hud, 0, 2, "Trend Efficiency", text_color=c_text, text_size=sz, text_halign=text.align_left, tooltip=ker_tip)
    table.cell(hud, 1, 2, ker_state, text_color=ker_col, text_size=sz, text_halign=text.align_right, tooltip=ker_tip)
 
    // 3. Relative Effort (Explicitly Differentiates Volume vs. Range Proxy)
    string eff_lbl = has_vol ? "Rel. Effort (Vol)" : "Rel. Effort (Range)"
    string eff_txt = str.tostring(math.round(rel_effort, 2)) + (has_vol ? "x Vol" : "x ATR")
    color  eff_col = rel_effort >= vol_thresh ? c_bull : c_neu
    string eff_tip = has_vol ? "Mode: Real Volume Feed\nCurrent Volume: " + str.tostring(volume, format.volume) + "\n" + str.tostring(len_er) + "-Bar SMA: " + str.tostring(vol_sma, format.volume) + "\nHigh Effort Threshold: " + str.tostring(vol_thresh) + "x" : "Mode: Non-Volume Range Fallback (Bar Range / ATR)\nUsed automatically when symbol lacks volume data."
    table.cell(hud, 0, 3, eff_lbl, text_color=c_text, text_size=sz, text_halign=text.align_left, tooltip=eff_tip)
    table.cell(hud, 1, 3, eff_txt, text_color=eff_col, text_size=sz, text_halign=text.align_right, tooltip=eff_tip)
 
    // 4. Relative Result (Spread Progress & Wick Rejection)
    string res_txt = str.tostring(math.round(body_atr, 2)) + "x ATR"
    color  res_col = body_atr >= 1.2 ? c_bull : body_atr <= 0.5 ? c_abs_bear : c_neu
    string res_tip = "Net Candle Body Displacement vs. " + str.tostring(len_er) + "-Bar ATR.\nLower Wick Ratio: " + str.tostring(math.round(lw_ratio * 100)) + "%\nUpper Wick Ratio: " + str.tostring(math.round(uw_ratio * 100)) + "%"
    table.cell(hud, 0, 4, "Rel. Result (Body)", text_color=c_text, text_size=sz, text_halign=text.align_left, tooltip=res_tip)
    table.cell(hud, 1, 4, res_txt, text_color=res_col, text_size=sz, text_halign=text.align_right, tooltip=res_tip)
 
    // 5. E/R Anomaly State (Shows Active or Provisional Status)
    float  active_er = lower_wick >= upper_wick ? er_bull_idx : er_bear_idx
    string bar_state = bull_abs ? "DEMAND ABS [" + bull_grade + "]" : bear_abs ? "SUPPLY ABS [" + bear_grade + "]" : (raw_bull_abs or raw_bear_abs) ? "PROV. ABSORPTION" : (retest_bull or retest_bear) ? "ZONE DEFENSE" : (init_bull or init_bear) ? "INITIATIVE DRIVE" : "NORMAL FLOW"
    color  state_col = bull_abs ? c_abs_bull : bear_abs ? c_abs_bear : (raw_bull_abs or raw_bear_abs) ? c_neu : (retest_bull or retest_bear) ? c_abs_bull : (init_bull or init_bear) ? c_bull : c_neu
    string state_tip = "Wick-Weighted E/R Score: " + str.tostring(math.round(active_er, 2)) + "\nRaw Body E/R Score: " + str.tostring(math.round(er_raw, 2)) + "\nThreshold: " + str.tostring(abs_ratio)
    table.cell(hud, 0, 5, "Bar Activity", text_color=c_text, text_size=sz, text_halign=text.align_left, tooltip=state_tip)
    table.cell(hud, 1, 5, bar_state, text_color=state_col, text_size=sz, text_halign=text.align_right, tooltip=state_tip)
 
    // 6. Active Unmitigated Absorption Zones
    int    d_zones = array.size(bull_boxes)
    int    s_zones = array.size(bear_boxes)
    string z_txt   = str.tostring(d_zones) + " Dem / " + str.tostring(s_zones) + " Sup"
    string z_tip   = "Active Unmitigated Demand Absorption Zones: " + str.tostring(d_zones) + "\nActive Unmitigated Supply Absorption Zones: " + str.tostring(s_zones)
    table.cell(hud, 0, 6, "Active Abs. Zones", text_color=c_text, text_size=sz, text_halign=text.align_left, tooltip=z_tip)
    table.cell(hud, 1, 6, z_txt, text_color=c_text, text_size=sz, text_halign=text.align_right, tooltip=z_tip)
else if not show_hud and barstate.islast
    table.clear(hud, 0, 0, 1, 6)
 
// ════════════════════════════════════════════════════════════════════════════
// 6. ALERTS (CONFIRMED SIGNALS)
// ════════════════════════════════════════════════════════════════════════════
 
alertcondition(bull_abs, "Confirmed Bullish Demand Absorption", "Confirmed Demand Absorption anomaly on {{ticker}} ({{interval}})")
alertcondition(bear_abs, "Confirmed Bearish Supply Absorption", "Confirmed Supply Absorption anomaly on {{ticker}} ({{interval}})")
alertcondition(bull_abs and bull_grade == "A", "Grade-A Bullish Demand Absorption", "High-Confluence Grade-A Demand Absorption on {{ticker}} ({{interval}})")
alertcondition(bear_abs and bear_grade == "A", "Grade-A Bearish Supply Absorption", "High-Confluence Grade-A Supply Absorption on {{ticker}} ({{interval}})")
alertcondition(retest_bull, "Confirmed Demand Zone Defense", "Confirmed Bullish defense of an active Demand Absorption Zone on {{ticker}} ({{interval}})")
alertcondition(retest_bear, "Confirmed Supply Zone Defense", "Confirmed Bearish defense of an active Supply Absorption Zone on {{ticker}} ({{interval}})")
alertcondition(init_bull, "Confirmed Bullish Initiative Breakout", "Confirmed High-Effort Bullish Initiative Breakout on {{ticker}} ({{interval}})")
alertcondition(init_bear, "Confirmed Bearish Initiative Breakout", "Confirmed High-Effort Bearish Initiative Breakout on {{ticker}} ({{interval}})")

← 返回列表