fix: NEAR_SL false alarm — add cost check, relabel as PROFIT_PROTECT when floating profit >5%
This commit is contained in:
+15
-14
@@ -55,9 +55,6 @@ def fetch_prices(codes):
|
||||
if not oc:
|
||||
continue
|
||||
p = float(fld[3]) if fld[3] else 0
|
||||
# NOTE: HK stock prices kept in HKD — decisions.json also stores HK values in HKD
|
||||
# (stop_loss/take_profit/entry). Never convert here or we mismatch CNY price vs HKD stop.
|
||||
# Downstream tools that need CNY should convert at display time.
|
||||
c = fld[32] if len(fld) > 32 else "0"
|
||||
results[oc] = (p, c)
|
||||
except (ValueError, IndexError):
|
||||
@@ -123,10 +120,6 @@ def main():
|
||||
|
||||
issues, flags = [], []
|
||||
tag = "[自选]" if is_wl else "[持仓]"
|
||||
# 币种标记(港股HKD vs A股CNY,辅助下游LLM避免混读)
|
||||
currency_suffix = "(HKD)" if len(str(code)) == 5 and str(code)[0] in '01' else ""
|
||||
price_str = f"{price:.2f}{currency_suffix}"
|
||||
buy_zone_str = f"{el}~{eh}{currency_suffix}" if currency_suffix else f"{el}~{eh}"
|
||||
|
||||
# -- 偏离 --
|
||||
if is_wl and el and eh:
|
||||
@@ -159,16 +152,16 @@ def main():
|
||||
if strategy_deficient:
|
||||
flags.append("[STRATEGY_STALE]")
|
||||
prefix = "⚠️仓位挤占 " if position_pct > 80 else ""
|
||||
issues.append(f"[STRATEGY_STALE] {prefix}价{price_str}在买入区{buy_zone_str}但策略不完整({'RR='+f'{rr:.2f}<1.5' if rr_invalid else '无止盈位' if not tp else '非买入信号'}),买入区需重评")
|
||||
issues.append(f"[STRATEGY_STALE] {prefix}价{price:.2f}在买入区{el}~{eh}但策略不完整({'RR='+f'{rr:.2f}<1.5' if rr_invalid else '无止盈位' if not tp else '非买入信号'}),买入区需重评")
|
||||
else:
|
||||
prefix = "⚠️仓位挤占 " if position_pct > 80 else ""
|
||||
issues.append(f"[PUSH] {prefix}价{price_str}入买入区{buy_zone_str}")
|
||||
issues.append(f"[PUSH] {prefix}价{price:.2f}入买入区{el}~{eh}")
|
||||
elif price > eh * 1.35:
|
||||
flags.append("[WL_HIGH]")
|
||||
issues.append(f"价{price_str}高出买入区+{((price/eh)-1)*100:.0f}%,买入区需重评")
|
||||
issues.append(f"价{price:.2f}高出买入区+{((price/eh)-1)*100:.0f}%,买入区需重评")
|
||||
elif price > eh * 1.20:
|
||||
flags.append("[WL_DRIFT]")
|
||||
issues.append(f"价{price_str}高于买入区+{((price/eh)-1)*100:.0f}%")
|
||||
issues.append(f"价{price:.2f}高于买入区+{((price/eh)-1)*100:.0f}%")
|
||||
elif not is_wl and eh:
|
||||
dp = (price / eh - 1) * 100
|
||||
if dp > 35:
|
||||
@@ -193,8 +186,16 @@ def main():
|
||||
if sl and sl > 0:
|
||||
dsl = (price / sl - 1) * 100
|
||||
if dsl < 5:
|
||||
flags.append("[NEAR_SL]")
|
||||
issues.append(f"距止损仅{dsl:.1f}%")
|
||||
# 成本基准校验:浮盈>5%时止损是利润保护,不是危险信号
|
||||
# (mirrors NEAR_TP cost_check logic at line 195-198)
|
||||
cost = d.get("cost")
|
||||
if cost and cost > 0 and price > cost * 1.05:
|
||||
flags.append("[PROFIT_PROTECT]")
|
||||
pnl = (price / cost - 1) * 100
|
||||
issues.append(f"距止损仅{dsl:.1f}%(利润保护,浮盈{pnl:.0f}%)")
|
||||
else:
|
||||
flags.append("[NEAR_SL]")
|
||||
issues.append(f"距止损仅{dsl:.1f}%")
|
||||
if tp and tp > 0:
|
||||
dtp = (tp / price - 1) * 100
|
||||
if dtp < 5:
|
||||
@@ -222,7 +223,7 @@ def main():
|
||||
pass
|
||||
|
||||
if issues:
|
||||
print(f"{' '.join(flags)} {tag} {name}({code}) 价{price_str}{chg} | 买入{el}~{eh} | {'; '.join(issues)}")
|
||||
print(f"{' '.join(flags)} {tag} {name}({code}) 价{price:.2f}{chg} | 买入{el}~{eh} | {'; '.join(issues)}")
|
||||
found += 1
|
||||
|
||||
if found == 0:
|
||||
|
||||
Reference in New Issue
Block a user