feat: Add Heikin Ashi signal handling with dynamic target price calculation

This commit is contained in:
Bobby (aider) 2025-02-12 22:17:04 -08:00
parent aec5929ea7
commit 4ad01316b7

View File

@ -43,15 +43,27 @@ def initialize_scanner(min_price: float, max_price: float, min_volume: int,
return interval, start_date, end_date, qualified_stocks, calculator
def process_signal_data(ticker: str, signal_data: dict, current_volume: int,
def process_signal_data(ticker: str, signal_ dict, current_volume: int,
last_update: int, stock_type: str, calculator: PositionCalculator = None) -> dict:
"""
Process and format signal data consistently
"""
entry_price = signal_data['price']
# Determine target price based on signal type
if 'ha_close' in signal_data: # Heikin Ashi signal
# Use a 2:1 reward-to-risk ratio for Heikin Ashi
stop_loss_pct = 0.07 # 7% stop loss
stop_distance = entry_price * stop_loss_pct
target_price = entry_price + (stop_distance * 2) # 2x the stop distance
else:
# Handle other signal types (ATR-EMA or Sunny Bands)
target_price = signal_data.get('ema', signal_data.get('upper_band'))
entry_data = {
'ticker': ticker,
'entry_price': signal_data['price'],
'target_price': signal_data.get('ema', signal_data.get('upper_band')), # Handle both ATR and Sunny
'entry_price': entry_price,
'target_price': target_price,
'volume': current_volume,
'signal_date': signal_data.get('date', datetime.now()),
'stock_type': stock_type,
@ -59,8 +71,8 @@ def process_signal_data(ticker: str, signal_data: dict, current_volume: int,
}
if calculator:
position = calculator.calculate_position_size(entry_data['entry_price'])
potential_profit = (entry_data['target_price'] - entry_data['entry_price']) * position['shares']
position = calculator.calculate_position_size(entry_price)
potential_profit = (target_price - entry_price) * position['shares']
entry_data.update({
'shares': position['shares'],
'position_size': position['position_value'],