fix: Define missing variables and import necessary functions in t_atr_ema.py
This commit is contained in:
parent
41537c1021
commit
422e11e4bf
@ -3,13 +3,16 @@ import os
|
|||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from db.db_connection import create_client
|
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
|
from indicators.three_atr_ema import ThreeATREMAIndicator
|
||||||
|
|
||||||
def check_atr_ema_bullish_signal(df: pd.DataFrame) -> bool:
|
def check_atr_ema_bullish_signal(df: pd.DataFrame) -> bool:
|
||||||
"""Check for bullish signal based on ATR EMA indicator"""
|
"""Check for bullish signal based on ATR EMA indicator"""
|
||||||
# Get latest values from DataFrame
|
# Get latest values from DataFrame
|
||||||
last_price = df.iloc[-1]
|
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"\nSunnyBands Indicators:")
|
||||||
print(f"DMA: ${last_bands['dma']:.2f}")
|
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]
|
last_price = df.iloc[-1]
|
||||||
|
|
||||||
# Check if price is below EMA and has started moving up
|
# Check if price is below EMA and has started moving up
|
||||||
|
ema = results['ema'].iloc[-1]
|
||||||
|
lower_band = results['lower_band'].iloc[-1]
|
||||||
|
|
||||||
return (
|
return (
|
||||||
last_price['close'] < ema &
|
last_price['close'] < ema and
|
||||||
last_price['close'].shift(1) <= lower_band &
|
last_price['close'].shift(1) <= lower_band and
|
||||||
last_price['close'] > last_price['close'].shift(1)
|
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()
|
interval = get_interval_choice()
|
||||||
|
|
||||||
end_date = datetime.now()
|
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
|
start_date = end_date - timedelta(days=1) # Get last trading day
|
||||||
|
|
||||||
client = create_client()
|
client = create_client()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user