Isolate legacy range-grid features
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user