A36 實測覆核報告(覆 66137):第五節 ① v4_futu_custom_indicator_hk.py vs 黃金 300 棒 Fixture(3fc8ce27)對數結果
一針見血總結論(區分「數值計算層」與「富途客戶端繪圖/文字表達層」):
- 核對樣本指紋:直接自已上載之
A36_66108_V4_SUPERTREND_FUTU_HK_EXACT_AND_OPT.html(sha256=b4b6020bf461c624235e2760e4b713ec85f950a9c69d6da9be6b93f5af11f992)<pre id="c-ftnn-py"> 抽取 v4_futu_custom_indicator_hk.py(11,270 B,sha256=b10f8f3b3df124cb…),對黃金基準檔 A36_66087_V4_UPSTREAM_PINE_AND_300BAR_FIXTURE.html(sha256=3fc8ce27376174ac65f611770d8d4b205cb358620c59de8dfbf4d4e995f31887)300 棒語料執行富途 ftool / Series 模擬器逐點驗算。
- ① 計算層與訊號時機 =
0 diff(100% 相同):
- 黃金 Fixture 全部 14 個檢查點(
bar 13, 14, 25, 50, 75, 100, 125, 150, 175, 200, 225, 250, 275, 299):st、erSmooth、volRatio、adaptiveFactor、adaptiveConfirm、lockedBull、s% 全數 diff = 0.0(雙精度逐 bit 一致)!
- 全量 300 支陰陽燭(
0..299):暖機棒 0..12 同為 NaN(nan_mismatch = 0);整數與方向序列(當前方向, 持續燭數, 趨勢強度Pct, 確認燭數, 上次質素分, 造好/造淡訊號次數, 趨勢效率ER)全 300 棒 max_abs_diff = 0.0;連續浮點 st 全 300 棒最大尾差僅 3.638e-12(IEEE-754 雙精度末位 1 ULP,因 50 項顯式迴圈累加 vs Python Neumaier sum(),有效數字 15 位全同)。
- 全部 2 次翻轉標籤:觸發棒號(
bar 158 轉淡、bar 240 轉好)、錨點價格 y(23303.4148781909、21707.835103156493)及評級([A],質素分 74 與 82)0 diff!
- 最新棒
bar 299(expected_latest 全部 12 項數值):st=22848.45383843578、age=59、convictionPct=99、erSmooth=1.0、volRatio=1.0031761482309627、adaptiveFactor=3.5111165188083695、adaptiveConfirm=1、flipQuality=82、distancePct=0.9144079400650804、bull=1 / bear=1 全數 0 diff!
- ② 富途牛牛客戶端繪圖與文字表達層 = 有 7 項明確差異(因香港中文字眼改動及富途自編指標 API 限制,詳見第二節逐項清單)。
一、14 個黃金檢查點(3fc8ce27 expected_checkpoints)逐點實測對照表
| Bar | Golden st | FTNN 超級趨勢線 | |diff| |
erSmooth (金/富) | volRatio (金/富) | adaptiveFactor (金/富) |
confirm | lockedBull | 強度% |
13 | 22172.9025000000 | 22172.9025000000 | 0.00e+00 | 0.937500 / 0.937500 | 1.000000 / 1.000000 | 3.500000 / 3.500000 | 1 / 1 | True / True | 48% / 48% |
14 | 22198.6437500000 | 22198.6437500000 | 0.00e+00 | 0.968750 / 0.968750 | 1.000000 / 1.000000 | 3.500000 / 3.500000 | 1 / 1 | True / True | 50% / 50% |
25 | 22373.8404292041 | 22373.8404292041 | 0.00e+00 | 0.999985 / 0.999985 | 1.000000 / 1.000000 | 3.500000 / 3.500000 | 1 / 1 | True / True | 63% / 63% |
50 | 22668.2192686903 | 22668.2192686903 | 0.00e+00 | 1.000000 / 1.000000 | 1.000000 / 1.000000 | 3.500000 / 3.500000 | 1 / 1 | True / True | 90% / 90% |
75 | 23043.9042255097 | 23043.9042255097 | 0.00e+00 | 1.000000 / 1.000000 | 0.945839 / 0.945839 | 3.310435 / 3.310435 | 1 / 1 | True / True | 100% / 100% |
100 | 23084.7241285318 | 23084.7241285318 | 0.00e+00 | 0.215041 / 0.215041 | 1.063237 / 1.063237 | 3.721330 / 3.721330 | 4 / 4 | True / True | 73% / 73% |
125 | 23084.7241285318 | 23084.7241285318 | 0.00e+00 | 0.264232 / 0.264232 | 1.064061 / 1.064061 | 3.724212 / 3.724212 | 3 / 3 | True / True | 74% / 74% |
150 | 23084.7241285318 | 23084.7241285318 | 0.00e+00 | 0.118822 / 0.118822 | 1.044196 / 1.044196 | 3.654688 / 3.654688 | 4 / 4 | True / True | 69% / 69% |
175 | 23029.6628164639 | 23029.6628164639 | 0.00e+00 | 0.999998 / 0.999998 | 1.320839 / 1.320839 | 4.622937 / 4.622937 | 1 / 1 | False / False | 53% / 53% |
200 | 22378.0042548306 | 22378.0042548306 | 0.00e+00 | 1.000000 / 1.000000 | 1.093657 / 1.093657 | 3.827801 / 3.827801 | 1 / 1 | False / False | 80% / 80% |
225 | 21867.4222078757 | 21867.4222078757 | 0.00e+00 | 0.193138 / 0.193138 | 0.912121 / 0.912121 | 3.192424 / 3.192424 | 4 / 4 | False / False | 72% / 72% |
250 | 21911.0048360600 | 21911.0048360600 | 0.00e+00 | 1.000000 / 1.000000 | 0.747649 / 0.747649 | 2.625000 / 2.625000 | 1 / 1 | True / True | 46% / 46% |
275 | 22373.2787463035 | 22373.2787463035 | 0.00e+00 | 1.000000 / 1.000000 | 0.862198 / 0.862198 | 3.017691 / 3.017691 | 1 / 1 | True / True | 73% / 73% |
299 | 22848.4538384358 | 22848.4538384358 | 0.00e+00 | 1.000000 / 1.000000 | 1.003176 / 1.003176 | 3.511117 / 3.511117 | 1 / 1 | True / True | 99% / 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!")