Revert blue-sky projection; keep played-out setup UX

A local backtest (offline prod snapshot, 506 tickers) evaluated blue-sky
projected targets under the PRODUCTION exit (3x ATR trailing + 30d max hold,
paper_trade_service DEFAULT_EXIT_MODE="atr_trailing"). Blue-sky setups are
dilutive: the qualified book scored 328% return / Sharpe 1.84 / DD -21.0%
WITHOUT them vs 300% / 1.58 / -18.7% WITH them. They rank high on momentum by
construction, so they grab slots from S/R setups that catch bigger runs under
a trailing-stop exit (only ~2pp worse drawdown doesn't justify the lost return
and Sharpe).

Reverts the scanner/TargetGenerator measured-move projection, the stricter
projected activation gate, the frontend qualification mirror, the `projected`
type field, and the projected tests -- all backend files are now byte-identical
to the pre-blue-sky commit.

Keeps the played-out "No current setup" UX (RecommendationPanel): when price
has run past the target (played out) or through the stop (invalidated), the
panel shows a plain no-setup state instead of a stale actionable card. This is
frontend-only (reads last close + existing setup fields) and is what actually
fixes the reported stale-below-price bug -- no backend change or rescan needed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-08 22:03:25 +02:00
co-authored by Claude Opus 4.8
parent 294d935030
commit 65d2dae62a
8 changed files with 25 additions and 416 deletions
+20 -39
View File
@@ -29,7 +29,6 @@ from app.models.trade_setup import TradeSetup
from app.services.indicator_service import _extract_ohlcv, compute_atr
from app.services.price_service import query_ohlcv
from app.services.recommendation_service import (
PROJECTED_TARGET_ATR_MULTIPLE,
_risk_level_from_conflicts,
build_recommendation_snapshot,
enhance_trade_setup,
@@ -68,16 +67,6 @@ def _compute_quality_score(
return w_rr * norm_rr + w_strength * norm_strength + w_proximity * norm_proximity
def _projected_target(direction: str, entry_price: float, atr_value: float) -> float:
"""Measured-move target for a blue-sky direction (no overhead S/R).
Mirrors the projection in recommendation_service so the scanner's emission
decision and the enhanced target agree.
"""
move = PROJECTED_TARGET_ATR_MULTIPLE * atr_value
return entry_price + move if direction == "long" else entry_price - move
async def _get_dimension_scores(db: AsyncSession, ticker_id: int) -> dict[str, float]:
result = await db.execute(
select(DimensionScore).where(DimensionScore.ticker_id == ticker_id)
@@ -439,13 +428,13 @@ async def scan_ticker(
now = datetime.now(timezone.utc)
setups: list[TradeSetup] = []
stop = entry_price - (atr_value * atr_multiplier)
risk = entry_price - stop
if risk > 0:
best_candidate_rr = 0.0
best_candidate_target = 0.0
if levels_above:
if levels_above:
stop = entry_price - (atr_value * atr_multiplier)
risk = entry_price - stop
if risk > 0:
best_quality = 0.0
best_candidate_rr = 0.0
best_candidate_target = 0.0
for lv in levels_above:
reward = lv.price_level - entry_price
if reward <= 0:
@@ -459,29 +448,21 @@ async def scan_ticker(
best_quality = quality
best_candidate_rr = rr
best_candidate_target = lv.price_level
else:
# Blue-sky: no resistance overhead. Project a measured-move target so
# a breakout name still yields a setup (it faces a stricter gate).
projected = _projected_target("long", entry_price, atr_value)
projected_rr = (projected - entry_price) / risk
if projected_rr >= rr_threshold:
best_candidate_rr = projected_rr
best_candidate_target = projected
if best_candidate_rr > 0:
setups.append(TradeSetup(
ticker_id=ticker.id,
direction="long",
entry_price=round(entry_price, 4),
stop_loss=round(stop, 4),
target=round(best_candidate_target, 4),
rr_ratio=round(best_candidate_rr, 4),
composite_score=round(composite_score, 4),
detected_at=now,
momentum_percentile=momentum_percentile,
strategy_rank=strategy_rank,
volatility_percentile=volatility_percentile,
))
if best_candidate_rr > 0:
setups.append(TradeSetup(
ticker_id=ticker.id,
direction="long",
entry_price=round(entry_price, 4),
stop_loss=round(stop, 4),
target=round(best_candidate_target, 4),
rr_ratio=round(best_candidate_rr, 4),
composite_score=round(composite_score, 4),
detected_at=now,
momentum_percentile=momentum_percentile,
strategy_rank=strategy_rank,
volatility_percentile=volatility_percentile,
))
if levels_below:
stop = entry_price + (atr_value * atr_multiplier)