RSI 다이버전스란
RSI 다이버전스(RSI Divergence)는 가격의 움직임과 RSI(상대강도지수) 지표의 움직임이 서로 반대 방향으로 나타나는 현상입니다. 이는 현재 추세의 모멘텀이 약화되고 있다는 강력한 신호로, 추세 전환을 미리 포착할 수 있는 대표적인 선행 지표입니다.
다이버전스는 단순히 RSI가 과매수·과매도 구간에 진입했다는 것보다 훨씬 강력한 신호입니다. 가격은 새로운 고점을 만들었지만 RSI는 이전 고점을 넘지 못한다면, 매수세의 힘이 빠지고 있다는 뜻이기 때문입니다.
다이버전스의 종류
일반 다이버전스(Regular Divergence) — 추세 반전 신호
- 강세 다이버전스(Bullish): 가격은 저점을 낮추는데(Lower Low), RSI는 저점을 높임(Higher Low) → 하락 추세 약화, 매수 신호
- 약세 다이버전스(Bearish): 가격은 고점을 높이는데(Higher High), RSI는 고점을 낮춤(Lower High) → 상승 추세 약화, 매도 신호
히든 다이버전스(Hidden Divergence) — 추세 지속 신호
- 강세 히든: 가격은 저점을 높이는데(Higher Low), RSI는 저점을 낮춤(Lower Low) → 상승 추세 지속 확인
- 약세 히든: 가격은 고점을 낮추는데(Lower High), RSI는 고점을 높임(Higher High) → 하락 추세 지속 확인
일반 다이버전스는 반전 매매, 히든 다이버전스는 추세 추종 매매에 활용됩니다.
Python 구현: RSI 다이버전스 감지
import numpy as np
import pandas as pd
def calculate_rsi(prices: pd.Series, period: int = 14) -> pd.Series:
"""RSI 계산"""
delta = prices.diff()
gain = delta.where(delta > 0, 0).rolling(period).mean()
loss = (-delta.where(delta < 0, 0)).rolling(period).mean()
rs = gain / loss
return 100 - (100 / (1 + rs))
def find_pivots(series: pd.Series, window: int = 5):
"""피벗 고점·저점 탐지"""
highs = []
lows = []
for i in range(window, len(series) - window):
# 피벗 고점
if series.iloc[i] == series.iloc[i-window:i+window+1].max():
highs.append(i)
# 피벗 저점
if series.iloc[i] == series.iloc[i-window:i+window+1].min():
lows.append(i)
return highs, lows
def detect_divergence(prices: pd.Series, rsi: pd.Series,
window: int = 5, lookback: int = 60):
"""
RSI 다이버전스 감지
Returns: list of (index, type) tuples
type: 'bullish', 'bearish', 'hidden_bullish', 'hidden_bearish'
"""
price_highs, price_lows = find_pivots(prices, window)
rsi_highs, rsi_lows = find_pivots(rsi, window)
signals = []
# 강세 다이버전스: 가격 LL + RSI HL
for i in range(1, len(price_lows)):
curr_idx = price_lows[i]
prev_idx = price_lows[i-1]
if curr_idx - prev_idx > lookback:
continue
# 가격: Lower Low
if prices.iloc[curr_idx] >= prices.iloc[prev_idx]:
continue
# RSI: Higher Low (해당 구간에서 가장 가까운 RSI 저점 찾기)
curr_rsi_lows = [r for r in rsi_lows
if abs(r - curr_idx) <= window]
prev_rsi_lows = [r for r in rsi_lows
if abs(r - prev_idx) <= window]
if curr_rsi_lows and prev_rsi_lows:
curr_rsi = rsi.iloc[curr_rsi_lows[0]]
prev_rsi = rsi.iloc[prev_rsi_lows[0]]
if curr_rsi > prev_rsi:
signals.append((curr_idx, 'bullish'))
# 약세 다이버전스: 가격 HH + RSI LH
for i in range(1, len(price_highs)):
curr_idx = price_highs[i]
prev_idx = price_highs[i-1]
if curr_idx - prev_idx > lookback:
continue
if prices.iloc[curr_idx] <= prices.iloc[prev_idx]:
continue
curr_rsi_highs = [r for r in rsi_highs
if abs(r - curr_idx) <= window]
prev_rsi_highs = [r for r in rsi_highs
if abs(r - prev_idx) <= window]
if curr_rsi_highs and prev_rsi_highs:
curr_rsi = rsi.iloc[curr_rsi_highs[0]]
prev_rsi = rsi.iloc[prev_rsi_highs[0]]
if curr_rsi < prev_rsi:
signals.append((curr_idx, 'bearish'))
return signals
자동매매 전략 통합
다이버전스 신호를 실제 자동매매에 적용할 때는 확인 조건을 추가해야 합니다. 다이버전스만으로 진입하면 거짓 신호에 노출되기 쉽습니다.
class RSIDivergenceBot:
"""RSI 다이버전스 기반 자동매매 봇"""
def __init__(self, rsi_period=14, pivot_window=5,
confirmation_bars=3):
self.rsi_period = rsi_period
self.pivot_window = pivot_window
self.confirmation_bars = confirmation_bars
def evaluate(self, prices: pd.Series) -> dict:
"""현재 시점 매매 판단"""
rsi = calculate_rsi(prices, self.rsi_period)
divergences = detect_divergence(
prices, rsi, self.pivot_window
)
if not divergences:
return {'action': 'HOLD', 'reason': '다이버전스 없음'}
last_div_idx, div_type = divergences[-1]
bars_since = len(prices) - 1 - last_div_idx
current_rsi = rsi.iloc[-1]
# 신호 발생 후 확인 기간 내인지 체크
if bars_since > self.confirmation_bars * 3:
return {'action': 'HOLD', 'reason': '신호 만료'}
# 강세 다이버전스 + RSI 반등 확인
if div_type == 'bullish' and current_rsi > rsi.iloc[-2]:
return {
'action': 'BUY',
'reason': f'강세 다이버전스 확인 (RSI: {current_rsi:.1f})',
'stop_loss': prices.iloc[last_div_idx] * 0.98,
'take_profit': prices.iloc[-1] * 1.04
}
# 약세 다이버전스 + RSI 하락 확인
if div_type == 'bearish' and current_rsi < rsi.iloc[-2]:
return {
'action': 'SELL',
'reason': f'약세 다이버전스 확인 (RSI: {current_rsi:.1f})',
'stop_loss': prices.iloc[last_div_idx] * 1.02,
'take_profit': prices.iloc[-1] * 0.96
}
return {'action': 'HOLD', 'reason': '확인 대기 중'}
다이버전스 매매 성공률 높이기
| 확인 조건 | 방법 | 효과 |
|---|---|---|
| 거래량 확인 | 다이버전스 발생 시 거래량 감소 확인 | 추세 약화 확실성 ↑ |
| 지지·저항선 | 주요 지지/저항 레벨 근처에서만 진입 | 반전 확률 ↑ |
| 다중 타임프레임 | 일봉+4시간봉 동시 다이버전스 | 신호 신뢰도 ↑↑ |
| 캔들 패턴 | 망치형·샛별형 등 반전 캔들 동반 | 진입 타이밍 정밀화 |
| 볼린저 밴드 | 밴드 터치와 다이버전스 동시 발생 | 복합 확인으로 거짓 신호 ↓ |
다이버전스 매매의 리스크 관리
다이버전스는 강력한 신호지만 100% 정확하지 않습니다. 특히 강한 추세장에서는 여러 번 연속으로 약세 다이버전스가 나타나도 가격이 계속 상승할 수 있습니다. 이를 "다이버전스 페일(Divergence Failure)"이라 합니다.
- 손절선 필수: 다이버전스 발생 시점의 극점(고점/저점)을 손절선으로 설정합니다. 이 레벨이 깨지면 다이버전스 신호가 무효화된 것입니다.
- 분할 진입: 한 번에 전체 포지션을 잡지 말고, 다이버전스 감지 → 확인 → 추가 확인 단계로 나눠 진입합니다.
- 포지션 사이징: 리스크 관리 원칙에 따라 1회 매매 손실을 계좌의 1~2%로 제한합니다.
- 연속 다이버전스 주의: 같은 방향 다이버전스가 3번 이상 연속 실패하면 강한 추세이므로 반전 매매를 중단하세요.
RSI 다이버전스 vs 다른 모멘텀 지표
| 지표 | 다이버전스 감지 | 장점 | 단점 |
|---|---|---|---|
| RSI | 가장 보편적 | 직관적, 과매수/과매도 동시 판단 | 횡보장에서 잦은 신호 |
| MACD | 히스토그램 활용 | 추세 강도 측정 우수 | 지연이 큰 편 |
| 스토캐스틱 | %K, %D 활용 | 단기 반전 포착 우수 | 노이즈가 많음 |
| OBV | 거래량 기반 | 스마트 머니 추적 | 개별 종목에서만 유효 |
RSI 다이버전스는 범용성과 직관성 면에서 가장 균형 잡힌 선택입니다. 이동평균 크로스오버와 결합하면 추세 방향과 모멘텀 변화를 동시에 포착할 수 있습니다.
마무리
RSI 다이버전스는 추세 전환을 사전에 감지하는 몇 안 되는 선행 신호 중 하나입니다. 일반 다이버전스로 반전을, 히든 다이버전스로 추세 지속을 확인할 수 있어 자동매매 시스템의 신호 품질을 크게 높입니다. 거래량·지지저항·볼린저 밴드 등 확인 조건과 함께 사용하고, 철저한 손절 관리를 병행하면 안정적인 수익을 기대할 수 있습니다.