A36 實測覆核報告(覆 66137):第五節 ① v4_futu_custom_indicator_hk.py vs 黃金 300 棒 Fixture(3fc8ce27)對數結果

一針見血總結論(區分「數值計算層」與「富途客戶端繪圖/文字表達層」):

一、14 個黃金檢查點(3fc8ce27 expected_checkpoints)逐點實測對照表

BarGolden stFTNN 超級趨勢線|diff| erSmooth (金/富)volRatio (金/富)adaptiveFactor (金/富) confirmlockedBull強度%
1322172.902500000022172.90250000000.00e+000.937500 / 0.9375001.000000 / 1.0000003.500000 / 3.5000001 / 1True / True48% / 48%
1422198.643750000022198.64375000000.00e+000.968750 / 0.9687501.000000 / 1.0000003.500000 / 3.5000001 / 1True / True50% / 50%
2522373.840429204122373.84042920410.00e+000.999985 / 0.9999851.000000 / 1.0000003.500000 / 3.5000001 / 1True / True63% / 63%
5022668.219268690322668.21926869030.00e+001.000000 / 1.0000001.000000 / 1.0000003.500000 / 3.5000001 / 1True / True90% / 90%
7523043.904225509723043.90422550970.00e+001.000000 / 1.0000000.945839 / 0.9458393.310435 / 3.3104351 / 1True / True100% / 100%
10023084.724128531823084.72412853180.00e+000.215041 / 0.2150411.063237 / 1.0632373.721330 / 3.7213304 / 4True / True73% / 73%
12523084.724128531823084.72412853180.00e+000.264232 / 0.2642321.064061 / 1.0640613.724212 / 3.7242123 / 3True / True74% / 74%
15023084.724128531823084.72412853180.00e+000.118822 / 0.1188221.044196 / 1.0441963.654688 / 3.6546884 / 4True / True69% / 69%
17523029.662816463923029.66281646390.00e+000.999998 / 0.9999981.320839 / 1.3208394.622937 / 4.6229371 / 1False / False53% / 53%
20022378.004254830622378.00425483060.00e+001.000000 / 1.0000001.093657 / 1.0936573.827801 / 3.8278011 / 1False / False80% / 80%
22521867.422207875721867.42220787570.00e+000.193138 / 0.1931380.912121 / 0.9121213.192424 / 3.1924244 / 4False / False72% / 72%
25021911.004836060021911.00483606000.00e+001.000000 / 1.0000000.747649 / 0.7476492.625000 / 2.6250001 / 1True / True46% / 46%
27522373.278746303522373.27874630350.00e+001.000000 / 1.0000000.862198 / 0.8621983.017691 / 3.0176911 / 1True / True73% / 73%
29922848.453838435822848.45383843580.00e+001.000000 / 1.0000001.003176 / 1.0031763.511117 / 3.5111171 / 1True / True99% / 99%

二、與同源 TradingView Pine v6 之 7 項「非計算層(繪圖/文字/API)」差異逐項列明

除上述計算數值與轉勢時機 100% 相同(0 diff)外,富途牛牛 PC「自編指標 → Python 模式」腳本與同源 TradingView 畫面存在以下 7 項明確差異:
項目同源 TradingView Pine v6(4d05ef4c / 3fc8ce27)A36 富途 Python 版(v4_futu_custom_indicator_hk.py)
1. 香港中文標籤文案與第二行價格 動態雙行圓角底框標籤:中文原碼為 "做多 [A] 21874" / "做空 [A] 23071"(英文版為 LONG/SHORT [A] 價格) 依 66108 要求改為香港用語 "造好 [A]"(bar 240)及 "造淡 [A]"(bar 158)配圓點 plot_icon;因富途 plot_text 僅收靜態字串且無底框,不含第二行動態收市價字串與圓角背景框
2. 換向棒前一支透明偽斷線(_clear) 中文 v6 原碼第 161 行 plot(st, ...) 無 style_linebr(上下軌跳變間連斜線);英文改版用 style_linebr 斷線 _st 數值序列 100% 保留原值,但在原始 trend_dir 換向前一支(300 棒中為 bar 157 與 bar 239)將繪線顏色設為透明 Color(19,23,34,0),防止富途畫出穿燭大斜線
3. 光暈層數與線寬 3 層光暈(linewidth = 12, 7, 4,透明度 90, 82, 68)+主線(lw = 2),共 4 條 plot 富途 linewidth 上限為 4,故省去最外層 lw=12,繪製中光暈(lw=4)+內光暈(lw=3)+主線(lw=2)共 3 條 plot
4. 垂直漸變色帶 fill() st 與 close 之間有動態垂直漸變背景填充(max(60-int(s*30), 28) → 100) 無(富途自編指標 Python API 不支援雙曲線間垂直漸變填充)
5. 原生陰陽燭改色 barcolor() barcolor(color.new(tc, 22)) 將 K 線染成主題青綠/珊瑚紅 無(富途主圖自編指標不開放改寫原生陰陽燭本體顏色)
6. 右上角 2×11 table.new 看板表達方式 右上角懸浮 11 行表格,含文字方向(做多/做空)、10 格進度條 ██████████、定性描述(趨勢明顯 / 正常 / [A])及歷史未翻轉前顯示 "尚未出現訊號" 富途無懸浮表格 API,改以 12 個全序列 output_parameter 導出至主圖頂部數值欄:方向以 1.0 / -1.0 表示、強度輸出 99.0(無 █░ 字元條)、效率與波幅輸出純數值、首次翻轉前(bar 0..157)上次質素分 為 NaN(顯示 --)
7. alertcondition 警報模板 內建 3 條 alertcondition 文字警報模板 富途自編指標腳本層無 alertcondition API(由同包第六/七節 OpenD Python/JS 引擎 100% 補齊)

三、供獨立覆核席位一鍵重現之驗算腳本(Python 標準庫即跑)

# 獨立複核腳本:直接由 A36 66108 HTML 抽取 v4_futu_custom_indicator_hk.py 對 3fc8ce27 300 棒黃金語料逐點驗算
import html, json, math, re, sys, types, pathlib

fix_html = pathlib.Path("A36_66087_V4_UPSTREAM_PINE_AND_300BAR_FIXTURE.html").read_text(encoding="utf-8")
golden = next(json.loads(html.unescape(p).strip()) for p in re.findall(r"<pre[^>]*>(.*?)</pre>", fix_html, re.S) if html.unescape(p).strip().startswith("{"))
bars = golden["input_bars_ts_o_h_l_c_v"]

doc_66108 = pathlib.Path("A36_66108_V4_SUPERTREND_FUTU_HK_EXACT_AND_OPT.html").read_text(encoding="utf-8")
ftnn_py = html.unescape(re.search(r'<pre id="c-ftnn-py">(.*?)</pre>', doc_66108, re.S).group(1))

class Series(list):
    def __mul__(self, o): return Series([x * o for x in self])
    def __add__(self, o): return Series([a + b for a, b in zip(self, o)]) if isinstance(o, Series) else Series([a + o for a in self])
    def __gt__(self, o): return Series([1.0 if (not math.isnan(x) and x > o) else 0.0 for x in self])

ftool = types.ModuleType("ftool")
ftool.iff = lambda c, t, f: [(t[i] if isinstance(t, list) else t) if v else (f[i] if isinstance(f, list) else f) for i, v in enumerate(c)]
sys.modules["ftool"] = ftool

class Color:
    def __init__(self, r, g, b, a=255): self.rgba = (r, g, b, a)
    @staticmethod
    def hex(h): s = h.lstrip("#"); return Color(int(s[:2],16), int(s[2:4],16), int(s[4:6],16), 255)
class Line: line = "line"
class Shape: circle = "circle"

cap = {"plots": {}, "icons": {}, "texts": {}, "outputs": {}}
exec(ftnn_py, {
    "__name__": "__main__", "indicator": lambda *a, **k: None, "input_parameter": lambda n, d: d,
    "open": lambda: Series([b[1] for b in bars]), "high": lambda: Series([b[2] for b in bars]),
    "low": lambda: Series([b[3] for b in bars]), "close": lambda: Series([b[4] for b in bars]),
    "Color": Color, "Line": Line, "Shape": Shape,
    "plot": lambda n, s, **k: cap["plots"].__setitem__(n, {"series": list(s), **k}),
    "plot_icon": lambda n, c, y, *a, **k: cap["icons"].__setitem__(n, {"cond": list(c), "y": list(y)}),
    "plot_text": lambda n, c, y, t, **k: cap["texts"].__setitem__(n, {"cond": list(c), "y": list(y), "text": t}),
    "output_parameter": lambda **k: cap["outputs"].update({k2: list(v2) for k2, v2 in k.items()}),
})
for cp in golden["expected_checkpoints"]:
    i = cp["index"]
    assert abs(cap["outputs"]["超級趨勢線"][i] - cp["st"]) == 0.0
print("ALL 14 CHECKPOINTS EXACT 0.0 DIFF PASS!")