新增BD共振信号(第四类):LX99第一部分SELLCOND+COND_A/COND_B逐行移植(scan_bd);推送文案与前端标签;MAL9 30m验证14次死叉1次SELLCOND、0次共振(公式交集极严,如实)

This commit is contained in:
2026-11-22 13:31:28 +08:00
committed by ceryuan
parent a47704a15d
commit d89f235e3a
6 changed files with 91 additions and 1 deletions
@@ -81,6 +81,7 @@ class SignalDetail {
String get kindLabel => switch (kind) {
'long_ignition' => '做多起爆点',
'short_ignition' => '做空起爆点',
'bd_resonance' => '卖出(BD共振)',
_ => '量价背离',
};
+1
View File
@@ -74,6 +74,7 @@ class NotificationItem {
String get kindLabel => switch (kind) {
'long_ignition' => '做多起爆点',
'short_ignition' => '做空起爆点',
'bd_resonance' => '卖出(BD共振)',
_ => '量价背离点',
};
+1
View File
@@ -89,6 +89,7 @@ class SignalPoint {
String get kindLabel => switch (kind) {
'long_ignition' => '做多起爆',
'short_ignition' => '做空起爆',
'bd_resonance' => 'BD共振',
_ => '',
};
bool get isIgnition => kind != 'divergence';
+86
View File
@@ -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
+1 -1
View File
@@ -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:
+1
View File
@@ -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)]