fix: correct boolean operations and column naming in ThreeATREMAIndicator
This commit is contained in:
parent
2103367a18
commit
b9d6243bbe
@ -31,28 +31,24 @@ class ThreeATREMAIndicator:
|
|||||||
# Calculate EMA
|
# Calculate EMA
|
||||||
ema = df['close'].ewm(span=self.ema_length, adjust=False).mean()
|
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'])
|
atr = self.calculate_atr(df['high'], df['low'], df['close'])
|
||||||
upper_band = ema + (atr * 3)
|
upper_band = ema + (atr * 3)
|
||||||
lower_band = ema - (atr * 3)
|
lower_band = ema - (atr * 3)
|
||||||
|
|
||||||
# Generate signals based on conditions:
|
# Fix signal condition with proper pandas syntax
|
||||||
# 1. Price is below EMA
|
bullish_condition = (
|
||||||
# 2. Price starts moving up from lower ATR band towards upper ATR band
|
(df['close'] < ema) &
|
||||||
condition = (
|
(df['close'].shift(1) <= lower_band.shift(1)) &
|
||||||
df['close'] < ema &
|
(df['close'] > df['close'].shift(1))
|
||||||
df['close'].shift(1) <= lower_band &
|
|
||||||
df['close'] > df['close'].shift(1)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
results = pd.DataFrame({
|
return pd.DataFrame({
|
||||||
'ema': ema,
|
'ema': ema,
|
||||||
'upper_band': upper_band,
|
'upper_band': upper_band,
|
||||||
'lower_band': lower_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:
|
def get_signals(self, df: pd.DataFrame) -> dict:
|
||||||
"""
|
"""
|
||||||
@ -73,7 +69,7 @@ class ThreeATREMAIndicator:
|
|||||||
'ema': current['ema'],
|
'ema': current['ema'],
|
||||||
'upper_band': current['upper_band'],
|
'upper_band': current['upper_band'],
|
||||||
'lower_band': current['lower_band'],
|
'lower_band': current['lower_band'],
|
||||||
'is_signal': current['signal']
|
'is_signal': current['bullish_signal']
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
return {}
|
return {}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user