min pivot distance only applies to L1 pivots ,

charts minimize addons,
delete buttons WIP
This commit is contained in:
Dobromir Popov
2025-10-24 13:49:16 +03:00
parent 42bf91b735
commit b970c4ca4d
8 changed files with 532 additions and 169 deletions

View File

@@ -121,7 +121,10 @@ class WilliamsMarketStructure:
# Restore original pivot distance
self.min_pivot_distance = original_distance
logger.debug(f"Calculated {len(self.pivot_levels)} pivot levels")
logger.info(f"Calculated {len(self.pivot_levels)} pivot levels from {len(ohlcv_data)} candles")
for level_num, level_data in self.pivot_levels.items():
logger.info(f" L{level_num}: {len(level_data.pivot_points)} pivots")
return self.pivot_levels
except Exception as e:
@@ -182,7 +185,7 @@ class WilliamsMarketStructure:
)
pivots.append(pivot)
logger.debug(f"Level 1: Found {len(pivots)} pivot points")
logger.info(f"Level 1: Found {len(pivots)} pivot points from {len(df)} candles")
return pivots
except Exception as e:
@@ -197,10 +200,18 @@ class WilliamsMarketStructure:
pivot points from the previous level as if they were OHLCV candles
"""
if level - 1 not in self.pivot_levels:
logger.debug(f"Level {level}: Previous level {level-1} not found")
return []
previous_level_pivots = self.pivot_levels[level - 1].pivot_points
if len(previous_level_pivots) < self.min_pivot_distance * 2 + 1:
# For higher levels (L2+), use distance=1 to allow more pivots
# Only L1 uses the strict min_pivot_distance requirement
pivot_distance = 1
required_pivots = pivot_distance * 2 + 1 # 3 pivots minimum
if len(previous_level_pivots) < required_pivots:
logger.debug(f"Level {level}: Insufficient pivots from L{level-1} ({len(previous_level_pivots)} < {required_pivots} required)")
return []
pivots = []
@@ -210,13 +221,15 @@ class WilliamsMarketStructure:
highs = [p for p in previous_level_pivots if p.pivot_type == 'high']
lows = [p for p in previous_level_pivots if p.pivot_type == 'low']
# Find swing highs among the high pivots
for i in range(self.min_pivot_distance, len(highs) - self.min_pivot_distance):
logger.debug(f"Level {level}: Processing {len(highs)} highs and {len(lows)} lows from L{level-1}")
# Find swing highs among the high pivots (using distance=1 for L2+)
for i in range(pivot_distance, len(highs) - pivot_distance):
current_pivot = highs[i]
# Check if this high is surrounded by lower highs
is_swing_high = True
for j in range(i - self.min_pivot_distance, i + self.min_pivot_distance + 1):
for j in range(i - pivot_distance, i + pivot_distance + 1):
if j != i and j < len(highs) and highs[j].price >= current_pivot.price:
is_swing_high = False
break
@@ -234,12 +247,12 @@ class WilliamsMarketStructure:
pivots.append(pivot)
# Find swing lows among the low pivots
for i in range(self.min_pivot_distance, len(lows) - self.min_pivot_distance):
for i in range(pivot_distance, len(lows) - pivot_distance):
current_pivot = lows[i]
# Check if this low is surrounded by higher lows
is_swing_low = True
for j in range(i - self.min_pivot_distance, i + self.min_pivot_distance + 1):
for j in range(i - pivot_distance, i + pivot_distance + 1):
if j != i and j < len(lows) and lows[j].price <= current_pivot.price:
is_swing_low = False
break
@@ -259,7 +272,7 @@ class WilliamsMarketStructure:
# Sort pivots by timestamp
pivots.sort(key=lambda x: x.timestamp)
logger.debug(f"Level {level}: Found {len(pivots)} pivot points")
logger.info(f"Level {level}: Found {len(pivots)} pivot points (from {len(highs)} highs, {len(lows)} lows)")
return pivots
except Exception as e: