Isolate legacy range-grid features

This commit is contained in:
2026-07-13 07:57:52 +02:00
parent 37836f8824
commit f7c2e35e29
7 changed files with 223 additions and 40 deletions
+13 -13
View File
@@ -144,6 +144,8 @@ SR_RESEARCH_VARIANTS = {
"legacy_geometry_neutral",
"legacy_pivots_only",
"legacy_traffic_grid_only",
"legacy_range_grid_touch",
"legacy_range_grid_neutral",
}
@@ -158,18 +160,7 @@ def _sr_research_variant() -> str:
def _apply_zone_strength_variant(zone_levels: list[Any], sr_variant: str) -> list[Any]:
"""Apply post-cluster research controls without changing zone geometry."""
if sr_variant == "legacy_geometry_neutral":
# Neutrality must be enforced after the shared zone cluster: its legacy
# sum mode can otherwise turn two 50-strength constituents back into a
# 100-strength target and silently invalidate the ablation.
for level in zone_levels:
level.strength = 50
return zone_levels
def _apply_zone_strength_variant(zone_levels: list[Any], sr_variant: str) -> list[Any]:
"""Apply post-cluster research controls without changing zone geometry."""
if sr_variant == "legacy_geometry_neutral":
if sr_variant in {"legacy_geometry_neutral", "legacy_range_grid_neutral"}:
# Neutrality must be enforced after the shared zone cluster: its legacy
# sum mode can otherwise turn two 50-strength constituents back into a
# 100-strength target and silently invalidate the ablation.
@@ -310,6 +301,16 @@ def _window_setups(
detected_levels = detect_sr_levels_legacy(
highs, lows, closes, volumes, include_pivots=False
)
elif sr_variant in {"legacy_range_grid_touch", "legacy_range_grid_neutral"}:
detected_levels = detect_sr_levels_legacy(
highs,
lows,
closes,
volumes,
include_pivots=False,
neutral_strength=sr_variant == "legacy_range_grid_neutral",
explicit_range_grid=True,
)
elif detector_variant in {"production_control", "rr_aligned_control"}:
detected_levels = detect_sr_levels_legacy(highs, lows, closes, volumes)
else:
@@ -351,7 +352,6 @@ def _window_setups(
strength_mode=zone_strength_mode,
)
zone_levels = _apply_zone_strength_variant(zone_levels, sr_variant)
zone_levels = _apply_zone_strength_variant(zone_levels, sr_variant)
targets = target_generator.generate_targets(direction, entry, stop, zone_levels, atr)
if not targets:
fallback_k = _atr_target_fallback_k()
+35 -1
View File
@@ -394,6 +394,34 @@ def _legacy_volume_profile_nodes(
return hvn + lvn
def _legacy_range_grid_nodes(
highs: list[float],
lows: list[float],
closes: list[float],
num_bins: int = 20,
) -> list[float]:
"""Return every deployed grid center without the irrelevant volume pass.
The legacy profile returns both its above-average (HVN) and below-average
(LVN) bins. Their union is therefore the complete range grid except for the
rare bin whose traffic equals the average exactly. This explicit helper
isolates that geometry from the misleading volume-profile label.
"""
if len(closes) < 20:
raise ValidationError(
f"Range grid requires at least 20 bars, got {len(closes)}"
)
price_min = min(lows)
price_max = max(highs)
if price_max == price_min:
price_max = price_min + 1.0
bin_width = (price_max - price_min) / num_bins
return [
round(price_min + (i + 0.5) * bin_width, 4)
for i in range(num_bins)
]
def detect_sr_levels_legacy(
highs: list[float],
lows: list[float],
@@ -404,6 +432,7 @@ def detect_sr_levels_legacy(
include_volume_profile: bool = True,
include_pivots: bool = True,
neutral_strength: bool = False,
explicit_range_grid: bool = False,
) -> list[dict]:
"""Deployed detector plus source-isolation controls for local research.
@@ -417,7 +446,12 @@ def detect_sr_levels_legacy(
candidates: list[tuple[float, str]] = []
if include_volume_profile:
try:
for price in _legacy_volume_profile_nodes(highs, lows, closes, volumes):
nodes = (
_legacy_range_grid_nodes(highs, lows, closes)
if explicit_range_grid
else _legacy_volume_profile_nodes(highs, lows, closes, volumes)
)
for price in nodes:
candidates.append((float(price), "volume_profile"))
except ValidationError:
pass