diff --git a/src/screener/t_atr_ema.py b/src/screener/t_atr_ema.py index 67534fe..ec8a35c 100644 --- a/src/screener/t_atr_ema.py +++ b/src/screener/t_atr_ema.py @@ -3,13 +3,16 @@ import os from datetime import datetime, timedelta import pandas as pd from db.db_connection import create_client +from trading.position_calculator import PositionCalculator +from screener.t_sunnyband import get_stock_data from indicators.three_atr_ema import ThreeATREMAIndicator def check_atr_ema_bullish_signal(df: pd.DataFrame) -> bool: """Check for bullish signal based on ATR EMA indicator""" # Get latest values from DataFrame last_price = df.iloc[-1] - last_bands = results.iloc[-1] # You need to calculate results first + results = indicator.calculate(df) + last_bands = results.iloc[-1] print(f"\nSunnyBands Indicators:") print(f"DMA: ${last_bands['dma']:.2f}") @@ -23,9 +26,12 @@ def check_atr_ema_buy_condition(df: pd.DataFrame) -> bool: last_price = df.iloc[-1] # Check if price is below EMA and has started moving up + ema = results['ema'].iloc[-1] + lower_band = results['lower_band'].iloc[-1] + return ( - last_price['close'] < ema & - last_price['close'].shift(1) <= lower_band & + last_price['close'] < ema and + last_price['close'].shift(1) <= lower_band and last_price['close'] > last_price['close'].shift(1) ) @@ -36,6 +42,8 @@ def run_atr_ema_scanner(min_price: float, max_price: float, min_volume: int, por interval = get_interval_choice() end_date = datetime.now() + start_ts = int(start_date.timestamp() * 1000000000) + end_ts = int(end_date.timestamp() * 1000000000) start_date = end_date - timedelta(days=1) # Get last trading day client = create_client()