A12 V4 超級趨勢(v6 中文版)三份交付(回應 66108)

來源

v4-supertrend-zh-v6.txt,sha256 4d05ef4c07db64570a4c073697507235a4a144e10b47f8c81716b83d79aad1bb,A12 已下載並核對一致。

① Futu 對應版(計算引擎)

純 Python 計算核心,輸出每根 K 的 st、翻轉、品質、信念分數。計算段與上游 SuperTrendy 相同,已在 300 棒 fixture(3fc8ce27)上對數:14 個檢查點與兩個翻轉標籤全部一致。Futu 的接入格式未有規格,由 A25 負責 FTNN 接口,A12 未接入任何運行環境。引擎 SHA256:fae6aa26b4ab6cf05ffc2c7f95dc253f208161397f17e23925d4e7c68d3a2bfb

#!/usr/bin/env python3
"""
A12 引擎(v6 繁中版計算核心):計算段與上游 SuperTrendy v5 相同(已逐段人工核對),純 Python。
來源:v4-supertrend-zh-v6.txt(sha 4d05ef4c…)。
只移植指標計算核心(不含繪圖)。逐行對照 SuperTrendy_upstream.pine。
用法:python3 v4_port_a12.py  (讀 fixture_300bar.json 並對數)
"""
import json
import math
from pathlib import Path
import sys

HERE = Path(__file__).resolve().parent
FIXTURE = HERE.parent / "v4" / "fixture_300bar.json"


def pine_round(x):
    # Pine math.round:半數遠離零
    return int(math.floor(abs(x) + 0.5)) * (1 if x >= 0 else -1)


def rma(values, n):
    out = [None] * len(values)
    acc = None
    for i, v in enumerate(values):
        if v is None:
            continue
        if acc is None:
            window = values[max(0, i - n + 1): i + 1]
            if i >= n - 1 and all(w is not None for w in window):
                acc = sum(window) / n
                out[i] = acc
            continue
        acc = (acc * (n - 1) + v) / n
        out[i] = acc
    return out


def ema(values, n):
    out = [None] * len(values)
    alpha = 2.0 / (n + 1)
    acc = None
    for i, v in enumerate(values):
        if v is None:
            continue
        if acc is None:
            window = values[max(0, i - n + 1): i + 1]
            if i >= n - 1 and all(w is not None for w in window):
                acc = sum(window) / n
                out[i] = acc
            continue
        acc = alpha * v + (1 - alpha) * acc
        out[i] = acc
    return out


def sma(values, n):
    out = [None] * len(values)
    for i in range(n - 1, len(values)):
        w = values[i - n + 1: i + 1]
        if any(x is None for x in w):
            continue
        out[i] = sum(w) / n
    return out


def percentrank(values, n):
    # Pine ta.percentrank:前 n 根(不含當前)中 <= 當前值 的百分比
    out = [None] * len(values)
    for i in range(len(values)):
        if i < n or values[i] is None:
            continue
        prev = values[i - n: i]
        if any(x is None for x in prev):
            continue
        cnt = sum(1 for x in prev if x <= values[i])
        out[i] = 100.0 * cnt / n
    return out


def run(bars, params):
    atr_len = params["atrLen"]
    base_factor = params["baseFactor"]
    er_len = params["erLen"]
    confirm_base = params["confirmBars"]
    vol_sma_len = params["volSmaLen"]
    er_ema_len = params["erEmaLen"]
    roc_len = params["rocLen"]

    n = len(bars)
    ts = [b[0] for b in bars]
    op = [b[1] for b in bars]
    hi = [b[2] for b in bars]
    lo = [b[3] for b in bars]
    cl = [b[4] for b in bars]

    # ta.atr = RMA(TR, len);TR 首根 = high-low
    tr = []
    for i in range(n):
        if i == 0:
            tr.append(hi[i] - lo[i])
        else:
            tr.append(max(hi[i] - lo[i], abs(hi[i] - cl[i - 1]), abs(lo[i] - cl[i - 1])))
    atr = rma(tr, atr_len)

    # Kaufman ER
    er = [0.0] * n
    for i in range(n):
        if i < er_len:
            er[i] = 0.0
            continue
        net = abs(cl[i] - cl[i - er_len])
        path = sum(abs(cl[i - k] - cl[i - k - 1]) for k in range(er_len))
        er[i] = net / path if path > 0 else 0.0
    er_smooth = ema(er, er_ema_len)

    atr_base = sma(atr, vol_sma_len)
    vol_ratio = [1.0] * n
    for i in range(n):
        if atr[i] is None or atr_base[i] is None:
            continue
        vol_ratio[i] = atr[i] / atr_base[i] if atr_base[i] > 0 else 1.0
    vol_regime = [None if v is None else max(min(v, 1.40), 0.75) for v in vol_ratio]
    adaptive_factor = [None if vr is None else base_factor * vr for vr in vol_regime]

    adaptive_confirm = [None] * n
    for i in range(n):
        e = er_smooth[i]
        if e is None:
            continue
        if e < 0.25:
            adaptive_confirm[i] = max(confirm_base + 2, 4)
        elif e < 0.45:
            adaptive_confirm[i] = confirm_base + 1
        elif e < 0.65:
            adaptive_confirm[i] = confirm_base
        else:
            adaptive_confirm[i] = max(confirm_base - 1, 1)

    # Flip quality
    roc = [None] * n
    for i in range(roc_len, n):
        roc[i] = 100.0 * (cl[i] - cl[i - roc_len]) / cl[i - roc_len] if cl[i - roc_len] != 0 else 0.0
    quality_pct = [0] * n
    quality_grade = ["C"] * n
    for i in range(n):
        if er_smooth[i] is None or atr[i] is None or roc[i] is None:
            continue
        price_mom_pct = abs(roc[i])
        atr_pct = atr[i] / cl[i] * 100 if cl[i] > 0 else 0.0
        mom_norm = min(price_mom_pct / (atr_pct * 2), 1.0) if atr_pct > 0 else 0.0
        vol_score = max(1.0 - abs(1.0 - vol_ratio[i]), 0.0)
        raw = er_smooth[i] * 0.50 + vol_score * 0.30 + mom_norm * 0.20
        q = pine_round(raw * 100)
        quality_pct[i] = q
        quality_grade[i] = "A" if q >= 70 else ("B" if q >= 50 else "C")

    atr_pctrank = percentrank(atr, 100)

    # Manual SuperTrend
    upper_band = [None] * n
    lower_band = [None] * n
    trend_dir = [1] * n
    st = [None] * n
    bull = [True] * n
    for i in range(n):
        if atr[i] is None or adaptive_factor[i] is None:
            continue
        hl2 = (hi[i] + lo[i]) / 2
        ub = hl2 + adaptive_factor[i] * atr[i]
        lb = hl2 - adaptive_factor[i] * atr[i]
        pu = upper_band[i - 1] if i > 0 else None
        pl = lower_band[i - 1] if i > 0 else None
        if pu is None:
            upper_band[i] = ub
        else:
            upper_band[i] = ub if (ub < pu or (i > 0 and cl[i - 1] > pu)) else pu
        if pl is None:
            lower_band[i] = lb
        else:
            lower_band[i] = lb if (lb > pl or (i > 0 and cl[i - 1] < pl)) else pl
        if i == 0:
            trend_dir[i] = 1
        else:
            prev_td = trend_dir[i - 1]
            if prev_td == 1:
                trend_dir[i] = -1 if cl[i] < lower_band[i] else 1
            else:
                trend_dir[i] = 1 if cl[i] > upper_band[i] else -1
        st[i] = lower_band[i] if trend_dir[i] == 1 else upper_band[i]
        bull[i] = trend_dir[i] == 1

    # Confirmation filter + conviction
    out = []
    locked_bull = None
    streak = 0
    bull_ct = 0
    bear_ct = 0
    age = 0
    flip_quality = 0
    for i in range(n):
        if st[i] is None or adaptive_confirm[i] is None:
            # Pine:age 每根棒都遞增(any_flip 為 false),即使 st 仍為 na
            age = age + 1
            out.append(None)
            continue
        if locked_bull is None:
            locked_bull = bull[i]
        streak = 0 if bull[i] == locked_bull else streak + 1
        flip_up = streak >= adaptive_confirm[i] and bull[i]
        flip_down = streak >= adaptive_confirm[i] and (not bull[i])
        any_flip = flip_up or flip_down
        if any_flip:
            locked_bull = bull[i]
        if flip_up:
            bull_ct += 1
        if flip_down:
            bear_ct += 1
        if any_flip:
            flip_quality = quality_pct[i]
        age = 0 if any_flip else age + 1
        s_time = min(age / 60.0, 1.0)
        s = s_time * 0.65 + er_smooth[i] * 0.35
        out.append({
            "index": i,
            "ts": ts[i],
            "st": st[i],
            "erSmooth": er_smooth[i],
            "volRatio": vol_ratio[i],
            "adaptiveFactor": adaptive_factor[i],
            "adaptiveConfirm": adaptive_confirm[i],
            "lockedBull": locked_bull,
            "qualityPct": quality_pct[i],
            "qualityGrade": quality_grade[i],
            "s": s,
            "flipUp": flip_up,
            "flipDown": flip_down,
            "close": cl[i],
            "age": age,
            "bullCt": bull_ct,
            "bearCt": bear_ct,
            "convictionPct": pine_round(s * 100),
            "atrPctRank": atr_pctrank[i],
            "flipQuality": flip_quality,
        })
    return out


def compare(res, fixture):
    exp_cp = fixture["expected_checkpoints"]
    report = {"checkpoints": [], "max_abs_diff_st": 0.0}
    fields = {"st": "st", "erSmooth": "erSmooth", "volRatio": "volRatio",
              "adaptiveFactor": "adaptiveFactor", "adaptiveConfirm": "adaptiveConfirm",
              "lockedBull": "lockedBull", "qualityPct": "qualityPct",
              "qualityGrade": "qualityGrade", "s": "s"}
    for cp in exp_cp:
        i = cp["index"]
        mine = res[i]
        row = {"index": i, "ok": True, "diffs": {}}
        for ek, mk in fields.items():
            if ek not in cp:
                continue
            e = cp[ek]
            m = mine[mk]
            if isinstance(e, bool) or isinstance(e, str):
                good = (e == m)
                if not good:
                    row["ok"] = False
                row["diffs"][ek] = (e, m)
            else:
                d = abs(float(e) - float(m))
                row["diffs"][ek] = d
                if ek == "st":
                    report["max_abs_diff_st"] = max(report["max_abs_diff_st"], d)
                if d > 1e-6:
                    row["ok"] = False
        report["checkpoints"].append(row)
    report["all_ok"] = all(r["ok"] for r in report["checkpoints"])
    return report


def main():
    fixture = json.loads(FIXTURE.read_text(encoding="utf-8"))
    res = run(fixture["input_bars_ts_o_h_l_c_v"], fixture["params"])
    rep = compare(res, fixture)
    print("checkpoints:", len(rep["checkpoints"]), "all_ok:", rep["all_ok"],
          "max_abs_diff_st:", rep["max_abs_diff_st"])
    for r in rep["checkpoints"]:
        print(r["index"], "ok" if r["ok"] else "MISMATCH", r["diffs"])
    last = res[-1]
    print("latest:", {k: last[k] for k in ("st", "close", "age", "convictionPct", "erSmooth", "lockedBull", "qualityPct", "qualityGrade", "bullCt", "bearCt")})
    print("expected_latest:", {k: fixture["expected_latest"].get(k) for k in ("st", "close", "age", "convictionPct", "erSmooth", "direction")})
    labels = [(i, r["flipUp"], r["flipDown"], r["qualityGrade"], r["qualityPct"]) for i, r in enumerate(res) if r and (r["flipUp"] or r["flipDown"])]
    print("my flips:", labels)
    print("expected labels:", [(l["barIndex"], l["direction"], l["grade"], l["quality"]) for l in fixture["expected_labels"]])


if __name__ == "__main__":
    main()

② 香港中文字眼版(Pine v6)

只改字串字面值:做空→沽空(共 5 行),例如標籤「沽空 [A]」、儀表板「沽空訊號次數」、警報「沽空訊號」。SHA256:3364fa636d9b1e298f18c45736750b1517bcb8b404c6d9514b48e1afbe2dda3b

// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TheRealDrip2Rip
// Translated to Traditional Chinese
//@version=6
indicator("超級趨勢 (自適應版)", overlay=true, max_labels_count=500)

// ═══════════════════════════════════════════════════════════════
//   輸入設定 (INPUTS)
// ═══════════════════════════════════════════════════════════════
g1 = "計算核心"
i_len     = input.int  (14,  "ATR 週期",         minval=1,           group=g1)
i_factor  = input.float(3.5, "基礎倍數",        step=0.1, minval=1, group=g1, tooltip="基礎乘數。會根據即時的波動率狀態自動進行縮放。")
i_er_len  = input.int  (10,  "ER 週期",          minval=3, maxval=20, group=g1, tooltip="考夫曼效率係數(Kaufman ER)回溯期。用於衡量價格是處於單邊趨勢還是震盪洗盤。")
i_confirm = input.int  (2,   "確認K線數 (基礎)", minval=1, maxval=5, group=g1, tooltip="基礎確認K線數。當 ER 低(震盪洗盤)時會自動增加以過濾雜訊,當 ER 高(明顯趨勢)時會自動減少。")

g2 = "視覺設定"
i_glow    = input.bool(true,  "發光光暈",      group=g2)
i_shade   = input.bool(true,  "漸層背景",      group=g2)
i_candles = input.bool(true,  "K線著色",       group=g2)
i_labels  = input.bool(true,  "多空訊號標籤",  group=g2)
i_table   = input.bool(true,  "數據看板",      group=g2)

g3 = "顏色設定"
i_bull = input.color(#26a69a, "做多 (Bull)", group=g3)
i_bear = input.color(#ef5350, "沽空 (Bear)", group=g3)

g4 = "數據看板"
i_pos = input.string("右上", "顯示位置", options=["右上","左上","右下","左下"], group=g4)

// ═══════════════════════════════════════════════════════════════
//   自適應層 (ADAPTIVE LAYER)
// ═══════════════════════════════════════════════════════════════
atr = ta.atr(i_len)

// ── 1. 考夫曼效率係數 (KAUFMAN EFFICIENCY RATIO) ──────────────────
// 淨價格位移 除以 總行走距離。
// 完美的單邊趨勢得分為 1.0。
// 上衝下洗但原地踏步的市場得分接近 0.0。
net_move   = math.abs(close - close[i_er_len])
var float total_path = 0.0
total_path := 0.0
for i = 0 to i_er_len - 1
    total_path += math.abs(close[i] - close[i + 1])
er        = total_path > 0 ? net_move / total_path : 0.0
er_smooth = ta.ema(er, 3)

// ── 2. 波動率狀態 (VOLATILITY REGIME) ────────────────────────
// 當前 ATR 與其 50 根 K 線平均基準的比例。
// > 1.2 : 波動劇烈,乘數放大
// < 0.8 : 波動壓縮,乘數縮小
// 將比例限制在 0.75 - 1.40 之間,用於縮放下方的乘數。
atr_baseline = ta.sma(atr, 50)
vol_ratio    = atr_baseline > 0 ? atr / atr_baseline : 1.0
vol_regime   = math.max(math.min(vol_ratio, 1.40), 0.75)

// ── 3. 自適應乘數 (ADAPTIVE FACTOR) ──────────────────────────
// 超級趨勢的乘數由波動率狀態來決定縮放。
// 當波動率升高時,軌道變寬;當波動率受到壓縮時,軌道收緊。
adaptive_factor = i_factor * vol_regime

// ── 4. ER驅動的自適應確認機制 (ER-DRIVEN ADAPTIVE CONFIRMATION) ──
// 低 ER (震盪):在確認反轉之前需要更多根K線。
// 高 ER (趨勢):需要較少根K線。
adaptive_confirm = er_smooth < 0.25 ? math.max(i_confirm + 2, 4) :
                   er_smooth < 0.45 ? i_confirm + 1               :
                   er_smooth < 0.65 ? i_confirm                   :
                                      math.max(i_confirm - 1, 1)

// ── 5. 反轉訊號品質評分 (0–100) ──────────────────────────────
// 在每次多空翻轉時計算。包含三個加權組件:
//   50% — 效率 (ER): 市場真的在走趨勢嗎?
//   30% — 波動率正常度: 波動率是否處於健康範圍? (在 vol_ratio=1.0 時達峰值,極端時下降)
//   20% — 5根K線動能: 翻轉時價格是否真的在移動?
//
// 分數越高表示翻轉發生在越乾淨的市場條件下。
// 等級:A = 70分及以上,B = 50到69分,C = 50分以下。
price_mom_pct = math.abs(ta.roc(close, 5))
atr_pct       = close > 0 ? atr / close * 100 : 0.0
mom_norm      = atr_pct > 0 ? math.min(price_mom_pct / (atr_pct * 2), 1.0) : 0.0
vol_score     = math.max(1.0 - math.abs(1.0 - vol_ratio), 0.0)
quality_raw   = er_smooth * 0.50 + vol_score * 0.30 + mom_norm * 0.20
quality_pct   = math.round(quality_raw * 100)
quality_grade = quality_pct >= 70 ? "A" :quality_pct >= 50 ? "B" : "C"

// ═══════════════════════════════════════════════════════════════
//   手動計算超級趨勢 (配合自適應乘數)
//   因為 ta.supertrend() 只接受簡單的浮點數,所以我們手動
//   實現相同的演算法,以接收我們的動態時間序列乘數。
// ═══════════════════════════════════════════════════════════════
upper_basic = hl2 + adaptive_factor * atr
lower_basic = hl2 - adaptive_factor * atr

var float upper_band = na
var float lower_band = na

upper_band := na(upper_band[1]) ? upper_basic : (upper_basic < upper_band[1] or close[1] > upper_band[1] ? upper_basic : upper_band[1])
lower_band := na(lower_band[1]) ? lower_basic : (lower_basic > lower_band[1] or close[1] < lower_band[1] ? lower_basic : lower_band[1])

var int trend_dir = 1
trend_dir := na(trend_dir[1]) ? 1 : trend_dir[1] ==  1 ? (close < lower_band ? -1 :  1) :(close > upper_band  ?  1 : -1)

st   = trend_dir ==  1 ? lower_band : upper_band
bull = trend_dir ==  1

// ═══════════════════════════════════════════════════════════════
//   確認過濾器 (CONFIRMATION FILTER)
// ═══════════════════════════════════════════════════════════════
var bool locked_bull = bull
var int  streak      = 0

streak    := bull == locked_bull ? 0 : streak + 1
flip_up    = streak >= adaptive_confirm and bull
flip_down  = streak >= adaptive_confirm and not bull
any_flip   = flip_up or flip_down

if any_flip
    locked_bull := bull

tc = locked_bull ? i_bull : i_bear

// 在多空翻轉瞬間捕捉品質分數,供數據看板使用
var int  flip_quality = 0
var bool has_flipped  = false

if any_flip
    flip_quality := quality_pct
    has_flipped  := true

flip_grade = flip_quality >= 70 ? "A" : flip_quality >= 50 ? "B" : "C"

// ═══════════════════════════════════════════════════════════════
//   趨勢強度/確信度 (CONVICTION)
//   融合了時間(K線數)和效率(ER),因此一個 30 根 K 線的乾淨趨勢
//   得分會高過一個 60 根 K 線的震盪洗盤。兩個維度都很重要。
// ═══════════════════════════════════════════════════════════════
var int age = 0
age := any_flip ? 0 : age + 1

s_time = math.min(age / 60.0, 1.0)
s      = s_time * 0.65 + er_smooth * 0.35

var int bull_ct = 0
var int bear_ct = 0

if flip_up
    bull_ct += 1
if flip_down
    bear_ct += 1

// ═══════════════════════════════════════════════════════════════
//   光暈與線條 (GLOW + LINE)
// ═══════════════════════════════════════════════════════════════
// 堆疊三層線條,最寬也最淡的在最下面,讓線條帶有柔和的光暈效果。
plot(i_glow ? st : na, "外圍光暈", color.new(tc, 90), linewidth=12, editable=false)
plot(i_glow ? st : na, "中間光暈",   color.new(tc, 82), linewidth=7,  editable=false)
plot(i_glow ? st : na, "內部光暈", color.new(tc, 68), linewidth=4,  editable=false)
plot(st, "超級趨勢線", tc, linewidth=2)

// ═══════════════════════════════════════════════════════════════
//   漸層著色背景 (GRADIENT SHADING)
//   連續的漸層:靠近超級趨勢線處顏色最深,到價格處漸隱為透明。
//   趨勢確信度越高,線條處的顏色越深。
// ═══════════════════════════════════════════════════════════════
boost     = int(s * 30)
c_line    = color.new(tc, math.max(60 - boost, 28))
c_price   = color.new(tc, 100)
st_on_top = st >= close
top_val   = math.max(st, close)
bot_val   = math.min(st, close)

p_close = plot(close, display=display.none, editable=false)
p_st    = plot(st,    display=display.none, editable=false)

fill(p_close, p_st, i_shade ? top_val : na, i_shade ? bot_val : na, st_on_top ? c_line : c_price, st_on_top ? c_price : c_line, title="漸層背景")

// ═══════════════════════════════════════════════════════════════
//   K線著色 (CANDLES)
// ═══════════════════════════════════════════════════════════════
barcolor(i_candles ? color.new(tc, 22) : na)

// ═══════════════════════════════════════════════════════════════
//   反轉訊號標籤 (FLIP LABELS)
//   顯示方向、品質等級以及當前價格。
// ═══════════════════════════════════════════════════════════════
if i_labels and flip_up
    label.new(bar_index, st, text      = "做多  [" + quality_grade + "]\n" + str.tostring(close, format.mintick), yloc      = yloc.belowbar, style     = label.style_label_up,color     = color.new(i_bull, 8), textcolor = color.white, size      = size.small)

if i_labels and flip_down
    label.new(bar_index, st, text      = "沽空  [" + quality_grade + "]\n" + str.tostring(close, format.mintick),  yloc      = yloc.abovebar,style     = label.style_label_down, color     = color.new(i_bear, 8), textcolor = color.white,size      = size.small)

// ═══════════════════════════════════════════════════════════════
//   數據看板 (DASHBOARD)
// ═══════════════════════════════════════════════════════════════
if i_table and barstate.islast
    pos = i_pos == "右上" ? position.top_right    :
          i_pos == "左上" ? position.top_left     :
          i_pos == "右下" ? position.bottom_right :
          position.bottom_left
          
    int    filled = int(math.round(s * 10))
    string sbar   = ""
    for i = 0 to 9
        sbar += i < filled ? "█" : "░"
        
    dist = math.abs(close - st) / close * 100
    
    er_label  = er_smooth > 0.65 ? "趨勢明顯" : er_smooth > 0.40 ? "多空交戰"    : "震盪洗盤"
    er_color  = er_smooth > 0.65 ? tc         : er_smooth > 0.40 ? color.orange : color.gray
    
    vol_label = vol_ratio > 1.20 ? "波動劇烈"   : vol_ratio < 0.80 ? "波動壓縮" : "正常"
    vol_color = vol_ratio > 1.20 ? color.orange  : vol_ratio < 0.80 ? color.aqua    : color.silver
    
    q_color   = not has_flipped ? color.gray : flip_quality >= 70 ? tc : flip_quality >= 50 ? color.orange : color.gray
    q_text    = has_flipped ? str.tostring(flip_quality) + " / 100  [" + flip_grade + "]" : "尚未出現訊號"
    
    t = table.new(pos, 2, 11,bgcolor      = color.new(#080808, 5),border_color = color.new(tc, 52), border_width = 1,frame_color  = color.new(tc, 22),frame_width  = 2)
    
    table.cell(t, 0, 0, "自適應超級趨勢", text_color=color.white, text_size=size.small, bgcolor=color.new(tc, 42), text_halign=text.align_center)
    table.cell(t, 1, 0, "倍數:" + str.tostring(adaptive_factor, "#.##") + "  確認:" + str.tostring(adaptive_confirm),text_color=color.silver, text_size=size.small,bgcolor=color.new(tc, 42), text_halign=text.align_center)
    
    table.cell(t, 0, 1, "當前方向",   text_color=color.gray, text_size=size.small)
    table.cell(t, 1, 1, locked_bull ? "做多" : "沽空",text_color=tc, text_size=size.small, text_halign=text.align_center, bgcolor=color.new(tc, 85))
    
    table.cell(t, 0, 2, "持續K線數",  text_color=color.gray, text_size=size.small)
    table.cell(t, 1, 2, str.tostring(age) + " 根",text_color=color.silver, text_size=size.small, text_halign=text.align_center)
    
    table.cell(t, 0, 3, "趨勢強度",  text_color=color.gray, text_size=size.small)
    table.cell(t, 1, 3, sbar + "  " + str.tostring(math.round(s * 100)) + "%", text_color=s > 0.5 ? tc : color.gray,text_size=size.tiny, text_halign=text.align_center)
    
    table.cell(t, 0, 4, "趨勢效率",  text_color=color.gray, text_size=size.small)
    table.cell(t, 1, 4, er_label + "  " + str.tostring(er_smooth, "#.##"),text_color=er_color, text_size=size.small, text_halign=text.align_center)
    
    table.cell(t, 0, 5, "波動率狀態",  text_color=color.gray, text_size=size.small)
    table.cell(t, 1, 5, vol_label + "  " + str.tostring(vol_ratio, "#.##"),text_color=vol_color, text_size=size.small, text_halign=text.align_center)
    
    table.cell(t, 0, 6, "自適應倍數",text_color=color.gray, text_size=size.small)
    table.cell(t, 1, 6, str.tostring(adaptive_factor, "#.##") + "  (基礎 " + str.tostring(i_factor, "#.#") + ")",text_color=color.silver, text_size=size.small, text_halign=text.align_center)
    
    table.cell(t, 0, 7, "上次訊號品質",   text_color=color.gray, text_size=size.small)
    table.cell(t, 1, 7, q_text, text_color=q_color, text_size=size.small, text_halign=text.align_center)
    
    table.cell(t, 0, 8, "距離趨勢線",    text_color=color.gray, text_size=size.small)
    table.cell(t, 1, 8, str.tostring(dist, "#.##") + "%", text_color=dist > 3.0 ? color.orange : color.silver, text_size=size.small, text_halign=text.align_center)
    
    table.cell(t, 0, 9, "做多訊號次數",  text_color=color.gray, text_size=size.small)
    table.cell(t, 1, 9, str.tostring(bull_ct), text_color=i_bull, text_size=size.small, text_halign=text.align_center)
    
    table.cell(t, 0, 10, "沽空訊號次數", text_color=color.gray, text_size=size.small)
    table.cell(t, 1, 10, str.tostring(bear_ct),text_color=i_bear, text_size=size.small, text_halign=text.align_center)

// ═══════════════════════════════════════════════════════════════
//   警報設定 (ALERTS)
// ═══════════════════════════════════════════════════════════════
alertcondition(flip_up,   "做多訊號",  "超級趨勢: 做多 — {{ticker}} {{interval}} @ {{close}}")
alertcondition(flip_down, "沽空訊號", "超級趨勢: 沽空 — {{ticker}} {{interval}} @ {{close}}")
alertcondition(any_flip,  "任何多空翻轉", "超級趨勢: 翻轉 — {{ticker}} {{interval}} @ {{close}}")

③ 與原碼輸出是否 100% 相同

三、未核實