PASS
300 棒黃金 fixture131 assertions;max absolute diff = 0.0。
158 / 240
轉勢棒造淡 A 級 bar 158;造好 A 級 bar 240,與 fixture 相同。
23
FTNN Sequence 輸出plot/output_parameter 全部保留 Sequence 容器。
未驗
FTNN GUI/TV runtime本沙盒冇舊 Server GUI;唔以 stub 或 fixture 冒充實機。
1. 結論與誠實邊界
- 已驗:ATR Wilder RMA、ER+EMA3、ATR/SMA50 波幅比、adaptive factor/confirm、upper/lower/dir 遞歸、streak 確認、品質分、age/conviction、翻轉棒與計數;fixture 131 項全綠。
- 已修:移除 A36 舊版禁用嘅
math標準庫;只保留手冊允許嘅from ftool import iff。用float("nan")+x != x處理 NA。 - 型別策略:由
close() * 0.0建立可寫 Sequence,scalar state 逐棒推進,再把 Sequence 直接交plot*/output_parameter;避免把 list 當文件化 Sequence。 - 視覺差異:FTNN 手冊 API 無 Pine 漸層
fill、barcolor、table、alertcondition及動態標籤第二行 close;外圍光暈 linewidth 由 Pine 12 降至 FTNN 上限 9。線值/事件值不受影響。 - 未聲稱:未喺 FTNN GUI 套用;未取得同商品/週期/inputs 嘅 TradingView runtime 全序列。Fixture 0 diff ≠ TV 實盤 100% 認證。
2. 來源與證據 Manifest
| 檔案 | Bytes | SHA-256 |
|---|---|---|
A88_V4_SUPERTREND_FTNN_HK.py | 12,391 | 4e876f16a8ae5334e38fbd7c58d32d9245b50434b5db9bd13637116aa0c46fe6 |
test_a88_v4_ftnn.py | 9,354 | 5108fa5ac3b78431bc64a2fde81d772d7d4d3a0b4d483a0db6d5fd11c3eca94a |
a88_v4_test.json | 747 | 984b4f64045334b0d44e972a59eaa62a85c358173a79296e89f10b0ceee79d13 |
v4-supertrend-zh-v6.txt | 16,808 | 4d05ef4c07db64570a4c073697507235a4a144e10b47f8c81716b83d79aad1bb |
ftnn-indicator-manual.md | 192,120 | 92a3c0814c2c8508a858bf744d03a10468627647ba8738b736522ad9bfe5d279 |
v4_300bar_golden_fixture.json | 41,035 | 959dc7aa37d0a4724b3111b501e570b4e4b6e744ecbd90093bccf2d7dc2d68ca |
Pin 65288:Manual bc2100f62697…、Entry 346ab1bd1e3b…、Template 5f1c86ab03e4… 已另外於 0600 resume log 核對。此交付無 credential、session key、enrollment code、SSH key 或個人資料。
3. Pine → FTNN 對照
| Pine 行為 | FTNN 實作 | 狀態 |
|---|---|---|
ta.atr(14) | TR+Wilder RMA,14 支 SMA 種植 | fixture 0 diff |
ta.ema(er,3) | alpha=0.5 oldest→newest | fixture 0 diff |
upper_band[1]/trend_dir[1] | scalar upper/lower/dir state;唔寫回輸出 Sequence 歷史 | fixture 0 diff |
locked_bull+streak | scalar confirmation state | bars 158/240 match |
| 三層 glow+主線 | FTNN 四層 plot;12px→9px | 數值同;外觀限制 |
| 動態 label+close | 靜態「造好/造淡 [A/B/C]」+事件 Sequence | 棒位同;文字第二行不同 |
| table/alerts/fill/barcolor | output_parameter 23 序列;無原生對等渲染 | 明示差異 |
4. 驗證結果
{
"status": "PASS",
"candidate": "A88_V4_SUPERTREND_FTNN_HK.py",
"fixture": "A36_V4_300BAR_MULTI_REGIME_FIXTURE_v1",
"bars": 300,
"static_gate": {
"imports": [
[
"ftool",
[
"iff"
]
]
],
"ast_nodes": 2527
},
"verification": {
"assertions": 131,
"max_abs_diff": 0.0,
"up_labels": [
240
],
"down_labels": [
158
]
},
"output_sequences": 23,
"plot_calls": 12,
"limitations": [
"FTNN GUI application not run in this sandbox",
"TradingView runtime parity not independently observed",
"Pine gradient fill, barcolor, table, alertcondition, and dynamic close text are not representable by the documented FTNN plotting API"
]
}
完整 FTNN 候選源碼 — A88_V4_SUPERTREND_FTNN_HK.py
# -*- coding: utf-8 -*-
"""A88 V4 自適應超級趨勢 — FTNN 自編指標 Python 模式(香港中文版)。
計算基準:v4-supertrend-zh-v6.txt
SHA-256: 4d05ef4c07db64570a4c073697507235a4a144e10b47f8c81716b83d79aad1bb
FTNN 手冊:ftnn-indicator-manual.md
SHA-256: 92a3c0814c2c8508a858bf744d03a10468627647ba8738b736522ad9bfe5d279
限制聲明:數值核心、翻轉棒與 A/B/C 級按釘住 300 棒 fixture 對數;FTNN 原生
繪圖無 Pine 漸層 fill、barcolor、table、alertcondition,同動態標籤第二行收市價,
所以視覺層唔聲稱 100% 等同 TradingView。必須在 FTNN GUI 實際套用後先確認平台
接受可寫 Sequence;本檔不把本地 stub 驗證冒充 GUI 驗收。
"""
indicator(
"A88V4HK",
"V4 自適應超級趨勢(香港版)",
True,
"ATR+考夫曼效率比率+波幅狀態+確認過濾;香港造好/造淡標籤",
)
ATR週期 = input_parameter("ATR週期", 14)
基本倍數 = input_parameter("基本倍數", 3.5)
效率週期 = input_parameter("效率比率週期", 10)
基本確認燭數 = input_parameter("基本確認陰陽燭數", 2)
顯示光暈 = input_parameter("顯示發光光暈(1開/0關)", 1)
# ftool 係 FTNN 手冊列明可用嘅富途模組;無標準庫/第三方 import。
from ftool import iff
_NAN = float("nan")
def _is_na(value):
return value != value
if __name__ == "__main__":
收 = close()
開 = open()
高 = high()
低 = low()
數量 = int(收.size)
atr_len = int(ATR週期)
if atr_len < 1:
atr_len = 1
factor = float(基本倍數)
er_len = int(效率週期)
if er_len < 1:
er_len = 1
confirm_base = int(基本確認燭數)
if confirm_base < 1:
confirm_base = 1
glow_on = int(顯示光暈) != 0
# 1) TR 與 Pine ta.atr 等價 Wilder RMA;首個 ATR 用 atr_len 支 TR SMA 種植。
tr_seq = 收 * 0.0
atr_seq = 收 * 0.0
for i in range(數量):
tr_seq[i] = 高[i] - 低[i]
atr_seq[i] = _NAN
if i > 0:
tr_a = 高[i] - 低[i]
tr_b = abs(高[i] - 收[i - 1])
tr_c = abs(低[i] - 收[i - 1])
tr_now = tr_a
if tr_b > tr_now:
tr_now = tr_b
if tr_c > tr_now:
tr_now = tr_c
tr_seq[i] = tr_now
if 數量 >= atr_len:
seed = 0.0
for i in range(atr_len):
seed = seed + tr_seq[i]
atr_seq[atr_len - 1] = seed / atr_len
for i in range(atr_len, 數量):
atr_seq[i] = (atr_seq[i - 1] * (atr_len - 1) + tr_seq[i]) / atr_len
# 2) Kaufman ER 與 Pine ta.ema(er, 3)。暖機 er 為 0,alpha=0.5。
er_seq = 收 * 0.0
er_smooth_seq = 收 * 0.0
er_seed = 0.0
for i in range(數量):
if i >= er_len:
net_move = abs(收[i] - 收[i - er_len])
total_path = 0.0
for k in range(er_len):
total_path = total_path + abs(收[i - k] - 收[i - k - 1])
er_seq[i] = net_move / total_path if total_path > 0.0 else 0.0
else:
er_seq[i] = 0.0
if i < 3:
er_seed = er_seed + er_seq[i]
er_smooth_seq[i] = er_seed / (i + 1)
else:
er_smooth_seq[i] = er_seq[i] * 0.5 + er_smooth_seq[i - 1] * 0.5
# 3) 所有輸出沿用富途 Sequence 容器;遞歸狀態只用 scalar oldest→newest 推進。
st_seq = 收 * 0.0
glow_seq = 收 * 0.0
locked_dir_seq = 收 * 0.0
adaptive_factor_seq = 收 * 0.0
adaptive_confirm_seq = 收 * 0.0
age_seq = 收 * 0.0
conviction_seq = 收 * 0.0
conviction_pct_seq = 收 * 0.0
vol_ratio_seq = 收 * 0.0
quality_now_seq = 收 * 0.0
flip_quality_seq = 收 * 0.0
has_flipped_seq = 收 * 0.0
distance_pct_seq = 收 * 0.0
bull_count_seq = 收 * 0.0
bear_count_seq = 收 * 0.0
flip_up_seq = 收 * 0.0
flip_down_seq = 收 * 0.0
up_a_seq = 收 * 0.0
up_b_seq = 收 * 0.0
up_c_seq = 收 * 0.0
down_a_seq = 收 * 0.0
down_b_seq = 收 * 0.0
down_c_seq = 收 * 0.0
upper_band = _NAN
lower_band = _NAN
trend_dir = 1
locked_bull = True
streak = 0
flip_quality = 0
has_flipped = False
age = 0
bull_count = 0
bear_count = 0
for i in range(數量):
flip_up_seq[i] = 0.0
flip_down_seq[i] = 0.0
up_a_seq[i] = 0.0
up_b_seq[i] = 0.0
up_c_seq[i] = 0.0
down_a_seq[i] = 0.0
down_b_seq[i] = 0.0
down_c_seq[i] = 0.0
hl2 = (高[i] + 低[i]) * 0.5
atr_now = atr_seq[i]
er_smooth = er_smooth_seq[i]
# Pine ta.sma(atr, 50):首個完整窗係 index atr_len+48(14週期時為62)。
vol_ratio = 1.0
if i >= atr_len + 48:
atr_sum50 = 0.0
for k in range(i - 49, i + 1):
atr_sum50 = atr_sum50 + atr_seq[k]
atr_base50 = atr_sum50 / 50.0
if atr_base50 > 0.0:
vol_ratio = atr_now / atr_base50
vol_regime = vol_ratio
if vol_regime > 1.40:
vol_regime = 1.40
if vol_regime < 0.75:
vol_regime = 0.75
adaptive_factor = factor * vol_regime
if er_smooth < 0.25:
adaptive_confirm = confirm_base + 2
if adaptive_confirm < 4:
adaptive_confirm = 4
elif er_smooth < 0.45:
adaptive_confirm = confirm_base + 1
elif er_smooth < 0.65:
adaptive_confirm = confirm_base
else:
adaptive_confirm = confirm_base - 1
if adaptive_confirm < 1:
adaptive_confirm = 1
momentum_pct = 0.0
if i >= 5 and 收[i - 5] != 0.0:
momentum_pct = abs((收[i] - 收[i - 5]) / 收[i - 5] * 100.0)
atr_pct = atr_now / 收[i] * 100.0 if (not _is_na(atr_now) and 收[i] > 0.0) else 0.0
momentum_norm = 0.0
if atr_pct > 0.0:
momentum_norm = momentum_pct / (atr_pct * 2.0)
if momentum_norm > 1.0:
momentum_norm = 1.0
vol_score = 1.0 - abs(1.0 - vol_ratio)
if vol_score < 0.0:
vol_score = 0.0
quality_raw = er_smooth * 0.50 + vol_score * 0.30 + momentum_norm * 0.20
quality_pct = int(quality_raw * 100.0 + 0.5)
prev_upper = upper_band
prev_lower = lower_band
prev_dir = trend_dir
if not _is_na(atr_now):
upper_basic = hl2 + adaptive_factor * atr_now
lower_basic = hl2 - adaptive_factor * atr_now
prev_close = 收[i - 1] if i > 0 else 收[i]
if _is_na(prev_upper) or upper_basic < prev_upper or prev_close > prev_upper:
upper_band = upper_basic
else:
upper_band = prev_upper
if _is_na(prev_lower) or lower_basic > prev_lower or prev_close < prev_lower:
lower_band = lower_basic
else:
lower_band = prev_lower
if i == 0 or _is_na(prev_upper):
trend_dir = 1
elif prev_dir == 1:
trend_dir = -1 if 收[i] < lower_band else 1
else:
trend_dir = 1 if 收[i] > upper_band else -1
st_now = lower_band if trend_dir == 1 else upper_band
bull = trend_dir == 1
if i == 0:
locked_bull = bull
streak = 0
else:
streak = 0 if bull == locked_bull else 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
flip_quality = quality_pct
has_flipped = True
if flip_up:
bull_count = bull_count + 1
flip_up_seq[i] = 1.0
if quality_pct >= 70:
up_a_seq[i] = 1.0
elif quality_pct >= 50:
up_b_seq[i] = 1.0
else:
up_c_seq[i] = 1.0
if flip_down:
bear_count = bear_count + 1
flip_down_seq[i] = 1.0
if quality_pct >= 70:
down_a_seq[i] = 1.0
elif quality_pct >= 50:
down_b_seq[i] = 1.0
else:
down_c_seq[i] = 1.0
age = 1 if i == 0 else (0 if any_flip else age + 1)
time_score = age / 60.0 if age < 60 else 1.0
conviction = time_score * 0.65 + er_smooth * 0.35
st_seq[i] = st_now
glow_seq[i] = st_now if glow_on else _NAN
locked_dir_seq[i] = 1.0 if locked_bull else -1.0
adaptive_factor_seq[i] = adaptive_factor
adaptive_confirm_seq[i] = float(adaptive_confirm)
age_seq[i] = float(age)
conviction_seq[i] = conviction
conviction_pct_seq[i] = float(int(conviction * 100.0 + 0.5))
vol_ratio_seq[i] = vol_ratio
quality_now_seq[i] = float(quality_pct)
flip_quality_seq[i] = float(flip_quality)
has_flipped_seq[i] = 1.0 if has_flipped else 0.0
distance_pct_seq[i] = abs(收[i] - st_now) / abs(收[i]) * 100.0 if (not _is_na(st_now) and 收[i] != 0.0) else 0.0
bull_count_seq[i] = float(bull_count)
bear_count_seq[i] = float(bear_count)
# 4) FTNN 原生可做嘅四層線。Pine 最闊12超過 FTNN 手冊上限9,故用9;數值不變。
bull_outer = Color.rgb(38, 166, 154, 26)
bear_outer = Color.rgb(239, 83, 80, 26)
bull_middle = Color.rgb(38, 166, 154, 46)
bear_middle = Color.rgb(239, 83, 80, 46)
bull_inner = Color.rgb(38, 166, 154, 82)
bear_inner = Color.rgb(239, 83, 80, 82)
bull_main = Color.rgb(38, 166, 154, 255)
bear_main = Color.rgb(239, 83, 80, 255)
plot("外圍光暈", glow_seq, color=iff(locked_dir_seq > 0, bull_outer, bear_outer), style=Line.line, linewidth=9)
plot("中間光暈", glow_seq, color=iff(locked_dir_seq > 0, bull_middle, bear_middle), style=Line.line, linewidth=7)
plot("內部光暈", glow_seq, color=iff(locked_dir_seq > 0, bull_inner, bear_inner), style=Line.line, linewidth=4)
plot("超級趨勢線", st_seq, color=iff(locked_dir_seq > 0, bull_main, bear_main), style=Line.line, linewidth=2)
# 5) 香港中文訊號;FTNN plot_text 文字係靜態,無 Pine 動態第二行 close。
up_signal = (up_a_seq + up_b_seq + up_c_seq) > 0.5
down_signal = (down_a_seq + down_b_seq + down_c_seq) > 0.5
plot_icon("造好點", up_signal, st_seq, Shape.circle, Color.hex("#26A69A"), 2, 0, 0)
plot_icon("造淡點", down_signal, st_seq, Shape.circle, Color.hex("#EF5350"), 2, 0, 0)
plot_text("造好A", up_a_seq > 0.5, st_seq, "造好 [A]", color=Color.hex("#26A69A"), size=2, offseth=0, offsetv=-22)
plot_text("造好B", up_b_seq > 0.5, st_seq, "造好 [B]", color=Color.hex("#26A69A"), size=2, offseth=0, offsetv=-22)
plot_text("造好C", up_c_seq > 0.5, st_seq, "造好 [C]", color=Color.hex("#26A69A"), size=2, offseth=0, offsetv=-22)
plot_text("造淡A", down_a_seq > 0.5, st_seq, "造淡 [A]", color=Color.hex("#EF5350"), size=2, offseth=0, offsetv=22)
plot_text("造淡B", down_b_seq > 0.5, st_seq, "造淡 [B]", color=Color.hex("#EF5350"), size=2, offseth=0, offsetv=22)
plot_text("造淡C", down_c_seq > 0.5, st_seq, "造淡 [C]", color=Color.hex("#EF5350"), size=2, offseth=0, offsetv=22)
# 6) 數值與事件輸出;方便 fixture/server.js/FTNN 實盤逐棒核對。
output_parameter(
超級趨勢線=st_seq,
當前方向=locked_dir_seq,
持續燭數=age_seq,
趨勢信念=conviction_seq,
趨勢強度Pct=conviction_pct_seq,
趨勢效率ER=er_smooth_seq,
波幅比率=vol_ratio_seq,
自適應倍數=adaptive_factor_seq,
確認燭數=adaptive_confirm_seq,
即時質素分=quality_now_seq,
上次質素分=flip_quality_seq,
已有轉勢=has_flipped_seq,
偏離趨勢線Pct=distance_pct_seq,
造好訊號次數=bull_count_seq,
造淡訊號次數=bear_count_seq,
造好事件=flip_up_seq,
造淡事件=flip_down_seq,
造好A=up_a_seq,
造好B=up_b_seq,
造好C=up_c_seq,
造淡A=down_a_seq,
造淡B=down_b_seq,
造淡C=down_c_seq,
)
完整隔離測試 — test_a88_v4_ftnn.py
#!/usr/bin/env python3
"""Isolated FTNN API stub + golden-fixture checks for A88 V4 candidate."""
from __future__ import annotations
import ast
import json
import math
import sys
import types
from pathlib import Path
ROOT = Path(__file__).resolve().parent
CANDIDATE = ROOT / "A88_V4_SUPERTREND_FTNN_HK.py"
FIXTURE = ROOT / "v4_300bar_golden_fixture.json"
class FakeSequence:
def __init__(self, values):
self.data = list(values)
@property
def size(self):
return len(self.data)
@property
def values(self):
return list(self.data)
def __len__(self):
return len(self.data)
def __getitem__(self, index):
return self.data[index]
def __setitem__(self, index, value):
self.data[index] = value
def _binary(self, other, op):
if isinstance(other, FakeSequence):
if len(self) != len(other):
raise ValueError("sequence length mismatch")
return FakeSequence(op(a, b) for a, b in zip(self.data, other.data))
return FakeSequence(op(a, other) for a in self.data)
def __mul__(self, other):
return self._binary(other, lambda a, b: a * b)
def __rmul__(self, other):
return self.__mul__(other)
def __add__(self, other):
return self._binary(other, lambda a, b: a + b)
def __radd__(self, other):
return self.__add__(other)
def __gt__(self, other):
return self._binary(other, lambda a, b: a > b)
class Color:
@staticmethod
def rgb(r, g, b, a=255):
return ("rgba", r, g, b, a)
@staticmethod
def hex(value):
return ("hex", value)
class Line:
line = "line"
class Shape:
circle = "circle"
def iff(condition, yes, no):
if isinstance(condition, FakeSequence):
n = len(condition)
y = yes.data if isinstance(yes, FakeSequence) else [yes] * n
z = no.data if isinstance(no, FakeSequence) else [no] * n
return FakeSequence(y[i] if condition.data[i] else z[i] for i in range(n))
return yes if condition else no
def assert_close(actual, expected, label, tolerance=1e-9):
if math.isnan(expected):
assert math.isnan(actual), f"{label}: expected NaN, got {actual}"
return 0.0
diff = abs(float(actual) - float(expected))
assert diff <= tolerance, f"{label}: {actual} != {expected} (diff={diff})"
return diff
def static_gate(source):
tree = ast.parse(source, filename=str(CANDIDATE))
imports = []
for node in ast.walk(tree):
if isinstance(node, ast.Import):
imports.extend(alias.name for alias in node.names)
elif isinstance(node, ast.ImportFrom):
imports.append((node.module, tuple(alias.name for alias in node.names)))
assert imports == [("ftool", ("iff",))], f"unexpected imports: {imports}"
forbidden = ("math.", "collections", "dataclasses", "typing", "from __future__")
for token in forbidden:
assert token not in source, f"forbidden token present: {token}"
assert "close().values" not in source, "candidate unexpectedly converts platform Sequence to list"
assert "收 * 0.0" in source, "candidate does not preserve FTNN Sequence containers"
return {"imports": imports, "ast_nodes": sum(1 for _ in ast.walk(tree))}
def run_candidate(fixture):
bars = fixture["input_bars_ts_o_h_l_c_v"]
opens = FakeSequence(row[1] for row in bars)
highs = FakeSequence(row[2] for row in bars)
lows = FakeSequence(row[3] for row in bars)
closes = FakeSequence(row[4] for row in bars)
outputs = {}
plots = []
ftool = types.ModuleType("ftool")
ftool.iff = iff
old_ftool = sys.modules.get("ftool")
sys.modules["ftool"] = ftool
def indicator(*_args, **_kwargs):
return None
def input_parameter(_title, default):
return default
def plot(name, x, **kwargs):
assert isinstance(x, FakeSequence), f"plot {name} did not receive Sequence"
plots.append(("plot", name, x, kwargs))
def plot_icon(name, condition, y, *_args, **_kwargs):
assert isinstance(condition, FakeSequence) and isinstance(y, FakeSequence)
plots.append(("icon", name, condition, y))
def plot_text(name, condition, y, text, **_kwargs):
assert isinstance(condition, FakeSequence) and isinstance(y, FakeSequence)
plots.append(("text", name, condition, y, text))
def output_parameter(**kwargs):
for name, value in kwargs.items():
assert isinstance(value, FakeSequence), f"output {name} did not receive Sequence"
outputs.update(kwargs)
env = {
"__name__": "__main__",
"indicator": indicator,
"input_parameter": input_parameter,
"open": lambda: opens,
"high": lambda: highs,
"low": lambda: lows,
"close": lambda: closes,
"plot": plot,
"plot_icon": plot_icon,
"plot_text": plot_text,
"output_parameter": output_parameter,
"Color": Color,
"Line": Line,
"Shape": Shape,
}
try:
exec(compile(CANDIDATE.read_text(encoding="utf-8"), str(CANDIDATE), "exec"), env)
finally:
if old_ftool is None:
del sys.modules["ftool"]
else:
sys.modules["ftool"] = old_ftool
return outputs, plots
def verify(outputs, fixture):
checks = 0
max_diff = 0.0
mapping = {
"st": "超級趨勢線",
"erSmooth": "趨勢效率ER",
"volRatio": "波幅比率",
"adaptiveFactor": "自適應倍數",
"adaptiveConfirm": "確認燭數",
"qualityPct": "即時質素分",
"s": "趨勢信念",
}
for checkpoint in fixture["expected_checkpoints"]:
index = checkpoint["index"]
for expected_name, output_name in mapping.items():
max_diff = max(max_diff, assert_close(outputs[output_name][index], checkpoint[expected_name], f"checkpoint {index} {expected_name}"))
checks += 1
actual_bull = outputs["當前方向"][index] > 0
assert actual_bull is checkpoint["lockedBull"], f"checkpoint {index} lockedBull mismatch"
checks += 1
expected_labels = fixture["expected_labels"]
up_indexes = [i for i, value in enumerate(outputs["造好事件"].data) if value > 0.5]
down_indexes = [i for i, value in enumerate(outputs["造淡事件"].data) if value > 0.5]
expected_up = [item["barIndex"] for item in expected_labels if item["direction"] == "LONG"]
expected_down = [item["barIndex"] for item in expected_labels if item["direction"] == "SHORT"]
assert up_indexes == expected_up, f"LONG label bars {up_indexes} != {expected_up}"
assert down_indexes == expected_down, f"SHORT label bars {down_indexes} != {expected_down}"
checks += 2
for item in expected_labels:
index = item["barIndex"]
assert int(outputs["上次質素分"][index]) == item["quality"]
if item["direction"] == "LONG":
grade = "A" if outputs["造好A"][index] else "B" if outputs["造好B"][index] else "C"
else:
grade = "A" if outputs["造淡A"][index] else "B" if outputs["造淡B"][index] else "C"
assert grade == item["grade"]
checks += 2
latest = fixture["expected_latest"]
last = len(fixture["input_bars_ts_o_h_l_c_v"]) - 1
latest_pairs = {
"超級趨勢線": latest["st"],
"持續燭數": latest["age"],
"趨勢強度Pct": latest["convictionPct"],
"趨勢效率ER": latest["erSmooth"],
"波幅比率": latest["volRatio"],
"自適應倍數": latest["adaptiveFactor"],
"確認燭數": latest["adaptiveConfirm"],
"上次質素分": latest["flipQuality"],
"偏離趨勢線Pct": latest["distancePct"],
"造好訊號次數": latest["bullFlips"],
"造淡訊號次數": latest["bearFlips"],
}
for output_name, expected in latest_pairs.items():
max_diff = max(max_diff, assert_close(outputs[output_name][last], expected, f"latest {output_name}"))
checks += 1
assert (outputs["當前方向"][last] > 0) is (latest["direction"] == "LONG")
assert (outputs["已有轉勢"][last] > 0) is latest["hasFlipped"]
checks += 2
return {"assertions": checks, "max_abs_diff": max_diff, "up_labels": up_indexes, "down_labels": down_indexes}
def main():
source = CANDIDATE.read_text(encoding="utf-8")
fixture = json.loads(FIXTURE.read_text(encoding="utf-8"))
static = static_gate(source)
outputs, plots = run_candidate(fixture)
result = verify(outputs, fixture)
print(json.dumps({
"status": "PASS",
"candidate": CANDIDATE.name,
"fixture": fixture["fixture_name"],
"bars": len(fixture["input_bars_ts_o_h_l_c_v"]),
"static_gate": static,
"verification": result,
"output_sequences": len(outputs),
"plot_calls": len(plots),
"limitations": [
"FTNN GUI application not run in this sandbox",
"TradingView runtime parity not independently observed",
"Pine gradient fill, barcolor, table, alertcondition, and dynamic close text are not representable by the documented FTNN plotting API",
],
}, ensure_ascii=False, indent=2))
if __name__ == "__main__":
main()
5. 實機驗收步驟
- 在 FTNN「自編指標 → Python」貼入完整候選;先看編輯器 error count,唔好將「0 error」當已套用。
- 按「應用」,確認主圖出現超級趨勢線及造好/造淡點;若平台拒絕 Sequence item assignment,記低精確錯誤字面及行號,停止估修。
- 用同一 300 棒 OHLC fixture/同參數核對 23 個 output_parameter 序列;最低核 bar 13、62、158、240、299。
- 另以同商品、週期、inputs 同步匯出 TradingView runtime 值,逐 timestamp 比較;只有實際全序列 0 diff 先可宣稱 TV 100%。
- 視覺只驗 FTNN 可表示部分;Pine 專屬漸層/table/alert 差異保持明示,唔用截圖主觀「似」代替數值對數。
6. 版本紀錄
第 1 版(初版) · 2026-11-23 · 來源 seq 66057/66108/66148–66156/66199/66206/66218。
修正咗:A36 舊候選標準庫 import、未文件化 Color constructor、list 輸出型別不確定性;加入 Sequence-native 輸出、完整 fixture gate 與誠實視覺差異表。之前版本:無。
修正咗:A36 舊候選標準庫 import、未文件化 Color constructor、list 輸出型別不確定性;加入 Sequence-native 輸出、完整 fixture gate 與誠實視覺差異表。之前版本:無。