fix: correct boolean operations and column naming in ThreeATREMAIndicator

This commit is contained in:
Bobby (aider) 2025-02-08 08:07:03 -08:00
parent 2103367a18
commit b9d6243bbe

View File

@ -31,29 +31,25 @@ class ThreeATREMAIndicator:
# Calculate EMA
ema = df['close'].ewm(span=self.ema_length, adjust=False).mean()
# Calculate ATR
# Calculate ATR and bands
atr = self.calculate_atr(df['high'], df['low'], df['close'])
upper_band = ema + (atr * 3)
lower_band = ema - (atr * 3)
# Generate signals based on conditions:
# 1. Price is below EMA
# 2. Price starts moving up from lower ATR band towards upper ATR band
condition = (
df['close'] < ema &
df['close'].shift(1) <= lower_band &
df['close'] > df['close'].shift(1)
# Fix signal condition with proper pandas syntax
bullish_condition = (
(df['close'] < ema) &
(df['close'].shift(1) <= lower_band.shift(1)) &
(df['close'] > df['close'].shift(1))
)
results = pd.DataFrame({
return pd.DataFrame({
'ema': ema,
'upper_band': upper_band,
'lower_band': lower_band,
'signal': condition
'bullish_signal': bullish_condition # Match the column name used in screener
})
return results
def get_signals(self, df: pd.DataFrame) -> dict:
"""
Get the current trading signals based on Three ATR EMA
@ -73,7 +69,7 @@ class ThreeATREMAIndicator:
'ema': current['ema'],
'upper_band': current['upper_band'],
'lower_band': current['lower_band'],
'is_signal': current['signal']
'is_signal': current['bullish_signal']
}
else:
return {}