more elaborate RL training
This commit is contained in:
@@ -331,8 +331,39 @@ class ExtremaTrainer:
|
||||
|
||||
# Get all available price data for better extrema detection
|
||||
all_candles = list(self.context_data[symbol].candles)
|
||||
prices = [candle['close'] for candle in all_candles]
|
||||
timestamps = [candle['timestamp'] for candle in all_candles]
|
||||
prices = []
|
||||
timestamps = []
|
||||
|
||||
for i, candle in enumerate(all_candles):
|
||||
# Handle different candle formats
|
||||
if isinstance(candle, dict):
|
||||
if 'close' in candle:
|
||||
prices.append(candle['close'])
|
||||
else:
|
||||
# Fallback to other price fields
|
||||
price = candle.get('price') or candle.get('high') or candle.get('low') or candle.get('open') or 0
|
||||
prices.append(price)
|
||||
|
||||
# Handle timestamp with fallbacks
|
||||
if 'timestamp' in candle:
|
||||
timestamps.append(candle['timestamp'])
|
||||
elif 'time' in candle:
|
||||
timestamps.append(candle['time'])
|
||||
else:
|
||||
# Generate timestamp based on index if none available
|
||||
timestamps.append(datetime.now() - timedelta(minutes=len(all_candles) - i))
|
||||
else:
|
||||
# Handle non-dict candle formats (e.g., tuples, lists)
|
||||
if hasattr(candle, '__getitem__'):
|
||||
prices.append(float(candle[3])) # Assume OHLC format: [O, H, L, C]
|
||||
timestamps.append(datetime.now() - timedelta(minutes=len(all_candles) - i))
|
||||
else:
|
||||
# Skip invalid candle data
|
||||
continue
|
||||
|
||||
# Ensure we have enough data
|
||||
if len(prices) < self.window_size * 3:
|
||||
return detected
|
||||
|
||||
# Use a more sophisticated extrema detection algorithm
|
||||
window = self.window_size
|
||||
|
||||
Reference in New Issue
Block a user