Feat: Add target and stop loss calculation to candlestick signals

This commit is contained in:
Bobby (aider) 2025-02-19 22:26:25 -08:00
parent cbac015a5a
commit 96b4d951b4

View File

@ -73,10 +73,21 @@ def check_entry_signal(df: pd.DataFrame, selected_patterns: list = None) -> list
found_patterns.append(CANDLESTICK_PATTERNS[pattern_name]['description'])
if found_patterns:
# Calculate basic target and stop levels using recent price action
current_price = df.iloc[i]['close']
recent_low = df.iloc[max(0, i-5):i+1]['low'].min() # Look back 5 bars for stop
atr = talib.ATR(df['high'].values, df['low'].values, df['close'].values, timeperiod=14)
# Use 2x ATR for target and 1x ATR for stop
target_price = current_price + (2 * atr[i] if not pd.isna(atr[i]) else current_price * 0.02)
stop_loss = max(recent_low, current_price - (atr[i] if not pd.isna(atr[i]) else current_price * 0.01))
signal_data = {
'price': df.iloc[i]['close'],
'price': current_price,
'patterns': ', '.join(found_patterns),
'pattern_count': len(found_patterns)
'pattern_count': len(found_patterns),
'target_price': target_price,
'stop_loss': stop_loss
}
signals.append((True, df.iloc[i]['date'], signal_data))