OPEN-SOURCE SCRIPT
Reversal_Detector

//version=6
indicator("상승 반전 탐지기 (Reversal Detector)", overlay=true)
// ==========================================
// 1. 설정 (Inputs)
// ==========================================
rsiLen = input.int(14, title="RSI 길이")
lbR = input.int(5, title="다이버전스 확인 범위 (오른쪽)")
lbL = input.int(5, title="다이버전스 확인 범위 (왼쪽)")
rangeUpper = input.int(60, title="RSI 과매수 기준")
rangeLower = input.int(30, title="RSI 과매도 기준")
// ==========================================
// 2. RSI 상승 다이버전스 계산 (핵심 로직)
// ==========================================
osc = ta.rsi(close, rsiLen)
// 피벗 로우(Pivot Low) 찾기: 주가의 저점
plFound = na(ta.pivotlow(osc, lbL, lbR)) ? false : true
// 다이버전스 조건 확인
// 1) 현재 RSI 저점이 이전 RSI 저점보다 높아야 함 (상승)
// 2) 현재 주가 저점이 이전 주가 저점보다 낮아야 함 (하락)
showBull = false
if plFound
// 이전 피벗 지점 찾기
oscLow = osc[lbR]
priceLow = low[lbR]
// 과거 데이터를 탐색하여 직전 저점과 비교
for i = 1 to 60
if not na(ta.pivotlow(osc, lbL, lbR)) // 이전에 저점이 있었다면
prevOscLow = osc[lbR + i]
prevPriceLow = low[lbR + i]
// 다이버전스 조건: 가격은 더 떨어졌는데(Lower Low), RSI는 올랐을 때(Higher Low)
if priceLow < prevPriceLow and oscLow > prevOscLow and oscLow < rangeLower
showBull := true
break // 하나 찾으면 루프 종료
// ==========================================
// 3. 보조 조건 (MACD 골든크로스 & 이평선)
// ==========================================
[macdLine, signalLine, _] = ta.macd(close, 12, 26, 9)
macdCross = ta.crossover(macdLine, signalLine) // MACD 골든크로스
ma5 = ta.sma(close, 5)
ma20 = ta.sma(close, 20)
maCross = ta.crossover(ma5, ma20) // 5일선이 20일선 돌파
// ==========================================
// 4. 시각화 (Plotting)
// ==========================================
// 1) 상승 다이버전스 발생 시 (강력한 바닥 신호)
plotshape(showBull,
title="상승 다이버전스",
style=shape.labelup,
location=location.belowbar,
color=color.red,
textcolor=color.white,
text="Bull Div\n(바닥신호)",
size=size.small,
offset=-lbR) // 과거 시점에 표시
// 2) MACD 골든크로스 (추세 확인용)
plotshape(macdCross and macdLine < 0, // 0선 아래에서 골든크로스 날 때만
title="MACD 골든크로스",
style=shape.triangleup,
location=location.belowbar,
color=color.yellow,
size=size.tiny,
text="MACD")
// 3) 이동평균선
plot(ma5, color=color.blue, title="5일선")
plot(ma20, color=color.orange, title="20일선")
// 알림 설정
alertcondition(showBull, title="상승 다이버전스 포착", message="상승 다이버전스 발생! 추세 반전 가능성")
indicator("상승 반전 탐지기 (Reversal Detector)", overlay=true)
// ==========================================
// 1. 설정 (Inputs)
// ==========================================
rsiLen = input.int(14, title="RSI 길이")
lbR = input.int(5, title="다이버전스 확인 범위 (오른쪽)")
lbL = input.int(5, title="다이버전스 확인 범위 (왼쪽)")
rangeUpper = input.int(60, title="RSI 과매수 기준")
rangeLower = input.int(30, title="RSI 과매도 기준")
// ==========================================
// 2. RSI 상승 다이버전스 계산 (핵심 로직)
// ==========================================
osc = ta.rsi(close, rsiLen)
// 피벗 로우(Pivot Low) 찾기: 주가의 저점
plFound = na(ta.pivotlow(osc, lbL, lbR)) ? false : true
// 다이버전스 조건 확인
// 1) 현재 RSI 저점이 이전 RSI 저점보다 높아야 함 (상승)
// 2) 현재 주가 저점이 이전 주가 저점보다 낮아야 함 (하락)
showBull = false
if plFound
// 이전 피벗 지점 찾기
oscLow = osc[lbR]
priceLow = low[lbR]
// 과거 데이터를 탐색하여 직전 저점과 비교
for i = 1 to 60
if not na(ta.pivotlow(osc, lbL, lbR)) // 이전에 저점이 있었다면
prevOscLow = osc[lbR + i]
prevPriceLow = low[lbR + i]
// 다이버전스 조건: 가격은 더 떨어졌는데(Lower Low), RSI는 올랐을 때(Higher Low)
if priceLow < prevPriceLow and oscLow > prevOscLow and oscLow < rangeLower
showBull := true
break // 하나 찾으면 루프 종료
// ==========================================
// 3. 보조 조건 (MACD 골든크로스 & 이평선)
// ==========================================
[macdLine, signalLine, _] = ta.macd(close, 12, 26, 9)
macdCross = ta.crossover(macdLine, signalLine) // MACD 골든크로스
ma5 = ta.sma(close, 5)
ma20 = ta.sma(close, 20)
maCross = ta.crossover(ma5, ma20) // 5일선이 20일선 돌파
// ==========================================
// 4. 시각화 (Plotting)
// ==========================================
// 1) 상승 다이버전스 발생 시 (강력한 바닥 신호)
plotshape(showBull,
title="상승 다이버전스",
style=shape.labelup,
location=location.belowbar,
color=color.red,
textcolor=color.white,
text="Bull Div\n(바닥신호)",
size=size.small,
offset=-lbR) // 과거 시점에 표시
// 2) MACD 골든크로스 (추세 확인용)
plotshape(macdCross and macdLine < 0, // 0선 아래에서 골든크로스 날 때만
title="MACD 골든크로스",
style=shape.triangleup,
location=location.belowbar,
color=color.yellow,
size=size.tiny,
text="MACD")
// 3) 이동평균선
plot(ma5, color=color.blue, title="5일선")
plot(ma20, color=color.orange, title="20일선")
// 알림 설정
alertcondition(showBull, title="상승 다이버전스 포착", message="상승 다이버전스 발생! 추세 반전 가능성")
Skrip sumber terbuka
Dalam semangat TradingView sebenar, pencipta skrip ini telah menjadikannya sumber terbuka, jadi pedagang boleh menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupuan anda boleh menggunakan secara percuma, ingat bahawa penerbitan semula kod ini tertakluk kepada Peraturan Dalaman.
Penafian
Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.
Skrip sumber terbuka
Dalam semangat TradingView sebenar, pencipta skrip ini telah menjadikannya sumber terbuka, jadi pedagang boleh menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupuan anda boleh menggunakan secara percuma, ingat bahawa penerbitan semula kod ini tertakluk kepada Peraturan Dalaman.
Penafian
Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.