This commit is contained in:
dsyoon
2025-07-20 22:03:06 +09:00
parent 0f93538112
commit f19cf092e9
3 changed files with 48 additions and 9 deletions

View File

@@ -112,12 +112,24 @@ def check_buy_signals(symbol, data):
# U자 반등 후 이전 고점 돌파 여부 계산 (BREAKOUT)
breakout_signal = False
if len(data) >= BREAKOUT_LOOKBACK + 1:
if len(data) >= max(BREAKOUT_LOOKBACK, BREAKOUT_WEEK_LOOKBACK) + 1:
# ① U자 형태 확인
window_close = data['Close'].iloc[-BREAKOUT_LOOKBACK-1:-1]
prev_high = window_close.max()
prev_low = window_close.min()
# 가격이 충분히 내려갔다가(BUY_THRESHOLD 비율) 다시 이전 고점을 돌파하면 breakout으로 간주
if prev_high > 0 and (prev_high - prev_low) / prev_high > BUY_THRESHOLD and current_price > prev_high:
# ② 1주일(42캔들) 전 가격 대비 5% 이상 상승하지 않았는지 체크
price_week_ago = data['Close'].iloc[-BREAKOUT_WEEK_LOOKBACK-1]
if price_week_ago > 0:
week_change = (current_price - price_week_ago) / price_week_ago
else:
week_change = 1 # 값이 0이면 조건 불충족 처리
# ③ 조건 종합: U자+돌파 && 주간 상승률 ≤ 5%
if (
prev_high > 0 and (prev_high - prev_low) / prev_high > BUY_THRESHOLD and current_price > prev_high
and week_change <= BREAKOUT_WEEK_LIMIT
):
breakout_signal = True
# RSI 과매도 신호 (RSI < 30)