A83 V4 指標轉換交付

來源:http://149.118.48.126:8080/v4-indicator-source.txt
來源大小:5587 B;來源 SHA-256:b8a0e2e1c934e3f1a05c4c6ff27f12ab2a5e277d8db227aecb85c7fb5ab3b358
交付內容:① FTNN / server.js 可用版;② 同一 script 內容轉做 K 線圖中文版。
處理原则:已睇晒來源 code;來源只提供 FLIP LABELS / DASHBOARD / ALERTS 片段,未提供完整 SuperTrend 算法,故不補造算法,僅精準轉換已提供片段並保留上游變量契約。
交付說明:兩份代碼都放喺本 HTML 檔內。① 是 JS module,供 FTNN adapter 或 server.js 接入;② 是 Pine Script K 線圖版本,提示改中文。relay 只留短 ack+pointer,唔貼全文。

① FTNN / server.js 可用版(V4 指標)

// A83 V4 指標 — FTNN / server.js 版本
// 由 http://149.118.48.126:8080/v4-indicator-source.txt (5587 B, sha256 b8a0e2e1c934e3f1a05c4c6ff27f12ab2a5e277d8db227aecb85c7fb5ab3b358)
// 精準轉換。來源片段只提供 FLIP LABELS / DASHBOARD / ALERTS;未提供完整 SuperTrend 算法,本檔不補造算法。
// 上游需先提供來源片段引用嘅狀態變量:i_labels, flip_up, flip_down, st, quality_grade, i_bull, i_bear,
// yloc, bar_index, close, i_table, barstate.islast, i_pos, s, dist, er_smooth, er_label, er_color, tc,
// vol_ratio, vol_label, vol_color, q_color, has_flipped, flip_quality, flip_grade, adaptive_factor,
// adaptive_confirm, locked_bull, age, bull_ct, bear_ct, any_flip。

const V4_ALERT_TEMPLATES = {
  long: "SuperTrend: LONG — {{ticker}} {{interval}} @ {{close}}",
  short: "SuperTrend: SHORT — {{ticker}} {{interval}} @ {{close}}",
  any: "SuperTrend: FLIP — {{ticker}} {{interval}} @ {{close}}"
};

function v4FillBar(s) {
  const filled = Math.round(s * 10);
  let bar = "";
  for (let i = 0; i < 10; i += 1) {
    bar += i < filled ? "█" : "░";
  }
  return bar;
}

function v4Position(i_pos) {
  if (i_pos === "Top Right") return "top_right";
  if (i_pos === "Top Left") return "top_left";
  if (i_pos === "Bottom Right") return "bottom_right";
  return "bottom_left";
}

/**
 * 渲染 V4 指標片段。
 * platform 需提供:labelNew, tableNew, tableCell, alertCondition。
 * FTNN 可傳入圖表 API adapter;server.js 可傳入 logger / recorder adapter。
 */
export function renderV4Indicator(state, platform) {
  const {
    i_labels, flip_up, flip_down, st, quality_grade, i_bull, i_bear,
    yloc, bar_index, close, i_table, barstate, i_pos, s,
    dist, er_smooth, er_label, er_color, tc, vol_ratio,
    vol_label, vol_color, q_color, has_flipped, flip_quality,
    flip_grade, adaptive_factor, adaptive_confirm, locked_bull,
    age, bull_ct, bear_ct, any_flip
  } = state;

  if (i_labels && flip_up) {
    platform.labelNew(bar_index, st, {
      text: "LONG [" + quality_grade + "]\n" + Number(close).toFixed(Number.MIN_VALUE),
      yloc: yloc.belowbar,
      style: "label_up",
      color: i_bull,
      textcolor: "#ffffff",
      size: "small"
    });
  }

  if (i_labels && flip_down) {
    platform.labelNew(bar_index, st, {
      text: "SHORT [" + quality_grade + "]\n" + Number(close).toFixed(Number.MIN_VALUE),
      yloc: yloc.abovebar,
      style: "label_down",
      color: i_bear,
      textcolor: "#ffffff",
      size: "small"
    });
  }

  if (i_table && barstate && barstate.islast) {
    const pos = v4Position(i_pos);
    const filled = Math.round(s * 10);
    const sbar = v4FillBar(s);
    const distance = Math.abs(close - st) / close * 100;
    const efficiencyLabel = er_smooth > 0.65 ? "TRENDING" : er_smooth > 0.40 ? "MIXED" : "CHOPPY";
    const efficiencyColor = er_smooth > 0.65 ? tc : er_smooth > 0.40 ? "orange" : "gray";
    const volRegimeLabel = vol_ratio > 1.20 ? "ELEVATED" : vol_ratio < 0.80 ? "COMPRESSED" : "NORMAL";
    const volRegimeColor = vol_ratio > 1.20 ? "orange" : vol_ratio < 0.80 ? "aqua" : "silver";
    const qualityColor = !has_flipped ? "gray" : flip_quality >= 70 ? tc : flip_quality >= 50 ? "orange" : "gray";
    const qualityText = has_flipped
      ? String(flip_quality) + " / 100 [" + flip_grade + "]"
      : "no flip yet";

    const t = platform.tableNew(pos, 2, 11, {
      bgcolor: { color: "#080808", alpha: 5 },
      border_color: { color: tc, alpha: 52 },
      border_width: 1,
      frame_color: { color: tc, alpha: 22 },
      frame_width: 2
    });

    platform.tableCell(t, 0, 0, "SUPERTREND", { text_color: "#ffffff", text_size: "small", bgcolor: { color: tc, alpha: 42 }, text_halign: "center" });
    platform.tableCell(t, 1, 0, "F:" + adaptive_factor.toFixed(2) + " C:" + adaptive_confirm.toFixed(2), { text_color: "silver", text_size: "small", bgcolor: { color: tc, alpha: 42 }, text_halign: "center" });
    platform.tableCell(t, 0, 1, "Direction", { text_color: "gray", text_size: "small" });
    platform.tableCell(t, 1, 1, locked_bull ? "LONG" : "SHORT", { text_color: tc, text_size: "small", text_halign: "center", bgcolor: { color: tc, alpha: 85 } });
    platform.tableCell(t, 0, 2, "Age", { text_color: "gray", text_size: "small" });
    platform.tableCell(t, 1, 2, String(age) + " bars", { text_color: "silver", text_size: "small", text_halign: "center" });
    platform.tableCell(t, 0, 3, "Conviction", { text_color: "gray", text_size: "small" });
    platform.tableCell(t, 1, 3, sbar + " " + Math.round(s * 100) + "%", { text_color: s > 0.5 ? tc : "gray", text_size: "tiny", text_halign: "center" });
    platform.tableCell(t, 0, 4, "Efficiency", { text_color: "gray", text_size: "small" });
    platform.tableCell(t, 1, 4, efficiencyLabel + " " + er_smooth.toFixed(2), { text_color: efficiencyColor, text_size: "small", text_halign: "center" });
    platform.tableCell(t, 0, 5, "Vol Regime", { text_color: "gray", text_size: "small" });
    platform.tableCell(t, 1, 5, volRegimeLabel + " " + vol_ratio.toFixed(2), { text_color: volRegimeColor, text_size: "small", text_halign: "center" });
    platform.tableCell(t, 0, 6, "Adapt Factor", { text_color: "gray", text_size: "small" });
    platform.tableCell(t, 1, 6, adaptive_factor.toFixed(2) + " (base " + state.i_factor.toFixed(1) + ")", { text_color: "silver", text_size: "small", text_halign: "center" });
    platform.tableCell(t, 0, 7, "Last Flip", { text_color: "gray", text_size: "small" });
    platform.tableCell(t, 1, 7, qualityText, { text_color: qualityColor, text_size: "small", text_halign: "center" });
    platform.tableCell(t, 0, 8, "Distance", { text_color: "gray", text_size: "small" });
    platform.tableCell(t, 1, 8, distance.toFixed(2) + "%", { text_color: distance > 3.0 ? "orange" : "silver", text_size: "small", text_halign: "center" });
    platform.tableCell(t, 0, 9, "Long Flips", { text_color: "gray", text_size: "small" });
    platform.tableCell(t, 1, 9, String(bull_ct), { text_color: i_bull, text_size: "small", text_halign: "center" });
    platform.tableCell(t, 0, 10, "Short Flips", { text_color: "gray", text_size: "small" });
    platform.tableCell(t, 1, 10, String(bear_ct), { text_color: i_bear, text_size: "small", text_halign: "center" });
  }

  platform.alertCondition(flip_up, "Long Signal", V4_ALERT_TEMPLATES.long);
  platform.alertCondition(flip_down, "Short Signal", V4_ALERT_TEMPLATES.short);
  platform.alertCondition(any_flip, "Any Flip", V4_ALERT_TEMPLATES.any);
}

export default renderV4Indicator;

② K 線圖中文版(同一 script 內容)

// A83 V4 指標 — K 線圖中文版
// 由 http://149.118.48.126:8080/v4-indicator-source.txt (5587 B, sha256 b8a0e2e1c934e3f1a05c4c6ff27f12ab2a5e277d8db227aecb85c7fb5ab3b358)
// 同一 script 內容轉做 K 線圖,提示改中文;保留來源片段嘅標籤、Dashboard、Alerts 邏輯。
// 來源片段未提供完整 SuperTrend 算法,本檔不補造算法;上游需先提供 st、quality_grade、flip_up 等狀態變量。

// K 線圖主線:顯示 SuperTrend 線。
plot(st, "V4 SuperTrend", color=tc, linewidth=2)

// 翻轉標籤:中文提示。
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 == "Top Right" ? position.top_right :
          i_pos == "Top Left" ? position.top_left :
          i_pos == "Bottom Right" ? 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, "SUPERTREND", text_color=color.white, text_size=size.small, bgcolor=color.new(tc, 42), text_halign=text.align_center)
    table.cell(t, 1, 0, "參數F:" + str.tostring(adaptive_factor, "#.##") + " 確認C:" + 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, "年齡", text_color=color.gray, text_size=size.small)
    table.cell(t, 1, 2, str.tostring(age) + " 根K線", 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, "做多信號", "SuperTrend:做多 — {{ticker}} {{interval}} @ {{close}}")
alertcondition(flip_down, "做空信號", "SuperTrend:做空 — {{ticker}} {{interval}} @ {{close}}")
alertcondition(any_flip, "翻轉信號", "SuperTrend:翻轉 — {{ticker}} {{interval}} @ {{close}}")
生成時間(UTC epoch):1795413407。本檔由 A83 生成,未改來源 SHA;未新增外部權限。