diff --git a/src/screener/t_atr_ema_v2.py b/src/screener/t_atr_ema_v2.py index 51b933b..36c7da1 100644 --- a/src/screener/t_atr_ema_v2.py +++ b/src/screener/t_atr_ema_v2.py @@ -138,29 +138,48 @@ def run_atr_ema_target_scanner(min_price: float, max_price: float, min_volume: i # Make a clean copy for indicator calculation calc_df = df.copy() + # Make a clean copy for indicator calculation + calc_df = df.copy() + + # Resample to daily data if we have intraday + if interval != "daily": + calc_df = calc_df.resample('D', on='date').agg({ + 'open': 'first', + 'high': 'max', + 'low': 'min', + 'close': 'last', + 'volume': 'sum' + }).dropna() + + # Ensure minimum data points after resampling + if len(calc_df) < 50: + print(f"⚠️ {ticker}: Insufficient data points after resampling ({len(calc_df)})") + continue + # Calculate indicator with validated data try: results = indicator.calculate(calc_df) if results.empty: print(f"⚠️ {ticker}: No valid indicator results") continue + + # Get the last two rows for signal checking + last_row = results.iloc[-1] + prev_row = results.iloc[-2] + + bullish_entry = ( + last_row["close"] < last_row["ema"] and + prev_row["close"] <= prev_row["lower_band"] and + last_row["close"] > prev_row["close"] + ) + except Exception as e: - print(f"⚠️ {ticker}: Error calculating indicator:") + print(f"⚠️ {ticker}: Error in indicator calculation:") print(f"Error details: {str(e)}") print(f"Data shape: {calc_df.shape}") print(f"Sample data:\n{calc_df.head()}") continue - results = indicator.calculate(df) - last_row = results.iloc[-1] - prev_row = results.iloc[-2] - - bullish_entry = ( - last_row["close"] < last_row["ema"] and - prev_row["close"] <= prev_row["lower_band"] and - last_row["close"] > prev_row["close"] - ) - if bullish_entry: entry_price = last_row["close"] target_1 = entry_price * 1.10 # 10% profit