From 3f10207481d59e0e00e62b9d88dfd725c58c9f06 Mon Sep 17 00:00:00 2001 From: "Bobby Abellana (aider)" Date: Thu, 6 Feb 2025 23:10:41 -0800 Subject: [PATCH] refactor: Improve SunnyBands target price calculation using band range --- src/screener/t_sunnyband.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/screener/t_sunnyband.py b/src/screener/t_sunnyband.py index f76a005..25d7bc5 100644 --- a/src/screener/t_sunnyband.py +++ b/src/screener/t_sunnyband.py @@ -355,10 +355,15 @@ def run_sunny_scanner(min_price: float, max_price: float, min_volume: int, portf try: entry_price = last_day['close'] upper_band = results['upper_band'].iloc[-1] - # Calculate a more aggressive target price (2x the distance to upper band) - band_distance = upper_band - entry_price - target_price = entry_price + (band_distance * 2) - print(f"Debug: Entry: ${entry_price:.2f}, Upper Band: ${upper_band:.2f}, Target: ${target_price:.2f}") # Debug line + dma = results['dma'].iloc[-1] + + # Calculate band distances + band_range = upper_band - dma # Distance from middle to upper band + + # Set target as one full band range above the upper band + target_price = upper_band + band_range + + print(f"Debug: Entry: ${entry_price:.2f}, DMA: ${dma:.2f}, Upper Band: ${upper_band:.2f}, Target: ${target_price:.2f}") position = calculator.calculate_position_size( entry_price=entry_price, target_price=target_price