diff --git a/app/lib/features/detail/signal_detail_page.dart b/app/lib/features/detail/signal_detail_page.dart index d6c0028..b89e078 100644 --- a/app/lib/features/detail/signal_detail_page.dart +++ b/app/lib/features/detail/signal_detail_page.dart @@ -81,6 +81,7 @@ class SignalDetail { String get kindLabel => switch (kind) { 'long_ignition' => '做多起爆点', 'short_ignition' => '做空起爆点', + 'bd_resonance' => '卖出(BD共振)', _ => '量价背离', }; diff --git a/app/lib/features/home/home_page.dart b/app/lib/features/home/home_page.dart index d969a91..cd0278c 100644 --- a/app/lib/features/home/home_page.dart +++ b/app/lib/features/home/home_page.dart @@ -74,6 +74,7 @@ class NotificationItem { String get kindLabel => switch (kind) { 'long_ignition' => '做多起爆点', 'short_ignition' => '做空起爆点', + 'bd_resonance' => '卖出(BD共振)', _ => '量价背离点', }; diff --git a/app/lib/models/kline_bar.dart b/app/lib/models/kline_bar.dart index 2ebc67b..2181864 100644 --- a/app/lib/models/kline_bar.dart +++ b/app/lib/models/kline_bar.dart @@ -89,6 +89,7 @@ class SignalPoint { String get kindLabel => switch (kind) { 'long_ignition' => '做多起爆', 'short_ignition' => '做空起爆', + 'bd_resonance' => 'BD共振', _ => '', }; bool get isIgnition => kind != 'divergence'; diff --git a/server/app/algo/ignition.py b/server/app/algo/ignition.py index ebbe6ef..5bf8a2a 100644 --- a/server/app/algo/ignition.py +++ b/server/app/algo/ignition.py @@ -236,3 +236,89 @@ def _sig(bars: Sequence[dict], i: int, side: str) -> dict: "path": side, # long / short "kind": f"{side}_ignition", } + + +# ---- BD 共振(LX99 卖出信号,公式第一部分第 62-78 行) ------------------------ +# SELLCOND: MACD(12/26/9) 死叉 + 近3根内曾在DEA上方 + 第4根前DIFF<=DEA +# + 实体重心>=布林中轨 且 实体顶<=布林上轨 +# BD_SIGN: SELLCOND AND (COND_A 绿翻红 OR COND_B AA上穿MA35) + + +def _kdj_vars(bars: Sequence[dict], n: int = 27) -> tuple[list[float], list[float]]: + """S0002:VAR3/VAR4(VAR5=3*VAR3-2*VAR4 用于 RED/GREEN)。""" + m = len(bars) + c = [b["c"] for b in bars] + l = [b["l"] for b in bars] + h = [b["h"] for b in bars] + var2: list[float] = [] + for i in range(m): + llv_p = _llv(l, i - 1, n) if i >= 1 else l[i] + hhv_p = _hhv(h, i - 1, n) if i >= 1 else h[i] + den = hhv_p - llv_p + var2.append((c[i] - llv_p) / den * 100 if den != 0 else 0.0) + var3 = _tdx_sma(var2, 3, 1) + var4 = _tdx_sma(var3, 9, 1) + return var3, var4 + + +def scan_bd(bars: Sequence[dict], ind: dict | None = None) -> list[dict]: + """输入已定型 K 序列,返回 BD 共振(卖出)信号列表。""" + ind = ind or indicators(bars) + m = len(bars) + if m < 40: # EMA26/150 + 布林20 + KDJ27 热身下限 + return [] + c = [b["c"] for b in bars] + o = [b["o"] for b in bars] + vol = [b["v"] for b in bars] + aa, ma35 = ind["aa"], ind["ma35"] + + # 标准 MACD(12/26/9)——与 LX94 的 DIFF94/DEA94(17/100/9) 是两套 + e12, e26 = ema(c, 12), ema(c, 26) + diff26 = [e12[i] - e26[i] for i in range(m)] + dea26 = ema(diff26, 9) + + bb = boll(bars) + mid, upper = bb["mid"], bb["upper"] + + var3, var4 = _kdj_vars(bars) + red = [vol[i] > 0 and var3[i] * 3 - 2 * var4[i] > var4[i] for i in range(m)] + green = [vol[i] > 0 and not red[i] for i in range(m)] + + up = [aa[i] is not None and ma35[i] is not None and aa[i] > ma35[i] for i in range(m)] + dn = [aa[i] is not None and ma35[i] is not None and aa[i] < ma35[i] for i in range(m)] + + out: list[dict] = [] + for i in range(4, m): + # SELLCOND + if not _cross(dea26, diff26, i): + continue + near_above = any( + diff26[i - k] > dea26[i - k] for k in (1, 2, 3) if i - k >= 0 + ) + fourth = diff26[i - 4] <= dea26[i - 4] if i - 4 >= 0 else False + if not (near_above and fourth): + continue + center = (o[i] + c[i]) / 2 + body_top = max(o[i], c[i]) + if mid[i] is None or upper[i] is None: + continue + if not (center >= mid[i] and body_top <= upper[i]): + continue + # COND_A: 当前绿 且 前3根内有红 + cond_a = green[i] and any(red[i - k] for k in (1, 2, 3) if i - k >= 0) + # COND_B: 当前 UP 且 前3根内有 DN + cond_b = up[i] and any(dn[i - k] for k in (1, 2, 3) if i - k >= 0) + if not (cond_a or cond_b): + continue + bar = bars[i] + out.append( + { + "dt": bar["dt"], + "date": bar["dt"][:10], + "time": bar["dt"][11:], + "close": bar["c"], + "path": "bd", + "kind": "bd_resonance", + } + ) + return out diff --git a/server/app/notify/push.py b/server/app/notify/push.py index f64d07f..4be0fae 100644 --- a/server/app/notify/push.py +++ b/server/app/notify/push.py @@ -59,7 +59,7 @@ def _push_chunk(chunk: list[dict]) -> dict[int, str]: return out -_KIND_LABEL = {"long_ignition": "做多起爆点", "short_ignition": "做空起爆点"} +_KIND_LABEL = {"long_ignition": "做多起爆点", "short_ignition": "做空起爆点", "bd_resonance": "卖出(BD共振)"} def _payload(items: list[dict], rids: list[str]) -> dict: diff --git a/server/app/scanner.py b/server/app/scanner.py index 7e677ae..7658824 100644 --- a/server/app/scanner.py +++ b/server/app/scanner.py @@ -130,6 +130,7 @@ def _judge(symbol: dict, interval: str, bars: list[dict], ind: dict, cutoff: str if upto is not None: sigs = [s for s in sigs if service.sort_key(s["dt"]) > service.sort_key(upto)] sigs += ignition.scan(closed, ind, upto=None) # 起爆点:内部已做波段去重,再过 checkpoint + sigs += ignition.scan_bd(closed, ind) # BD 共振(卖出):同样按 checkpoint 过滤 if upto is not None: sigs = [s for s in sigs if service.sort_key(s["dt"]) > service.sort_key(upto)]