PINE LIBRARY
Mirpapa_Lib_Divergence

Library  "Mirpapa_Lib_Divergence"
다이버전스 감지 및 시각화 라이브러리 (범용 설계)
newPivot(bar, priceVal, indVal)
피벗 포인트 생성
Parameters:
bar (int): 바 인덱스
priceVal (float): 가격
indVal (float): 지표값
Returns: PivotPoint
newDivSettings(pivotLen, maxStore, maxShow)
다이버전스 설정 생성
Parameters:
pivotLen (int): 피벗 좌우 캔들
maxStore (int): 저장 개수
maxShow (int): 표시 라인 개수
Returns: DivergenceSettings
emptyDivResult()
빈 다이버전스 결과
Returns: 감지 안 된 DivergenceResult
checkPivotHigh(length, source)
고점 피벗 감지
Parameters:
length (int): 좌우 비교 캔들 수
source (float): 비교할 데이터 (지표값)
Returns: 피벗 값 또는 na
checkPivotLow(length, source)
저점 피벗 감지
Parameters:
length (int): 좌우 비교 캔들 수
source (float): 비교할 데이터 (지표값)
Returns: 피벗 값 또는 na
addPivotToArray(pivotArray, pivot, maxSize)
피벗을 배열에 추가 (FIFO 방식)
Parameters:
pivotArray (array<PivotPoint>): 피벗 배열
pivot (PivotPoint): 추가할 피벗
maxSize (int): 최대 크기
checkBullishDivergence(pivotArray)
상승 다이버전스 체크 (Bullish)
Parameters:
pivotArray (array<PivotPoint>): 저점 피벗 배열
Returns: DivergenceResult
checkBearishDivergence(pivotArray)
하락 다이버전스 체크 (Bearish)
Parameters:
pivotArray (array<PivotPoint>): 고점 피벗 배열
Returns: DivergenceResult
createDivLine(result, lineColor, isOverlay)
다이버전스 라인 생성
Parameters:
result (DivergenceResult): DivergenceResult
lineColor (color): 라인 색상
isOverlay (bool): true면 가격 기준, false면 지표 기준
Returns: [line, label]
cleanupLines(lineArray, labelArray, maxLines)
오래된 라인/라벨 정리
Parameters:
lineArray (array<line>): 라인 배열
labelArray (array<label>): 라벨 배열
maxLines (int): 최대 유지 개수
addLineAndCleanup(lineArray, labelArray, newLine, newLabel, maxLines)
라인/라벨 추가 및 자동 정리
Parameters:
lineArray (array<line>): 라인 배열
labelArray (array<label>): 라벨 배열
newLine (line): 새 라인
newLabel (label): 새 라벨
maxLines (int): 최대 개수
PivotPoint
피벗 데이터 저장
Fields:
barIndex (series int): 바 인덱스
price (series float): 종가
indicatorValue (series float): 지표값
DivergenceSettings
다이버전스 설정
Fields:
pivotLength (series int): 피벗 좌우 캔들 수
maxPivotsStore (series int): 저장할 최대 피벗 개수
maxLinesShow (series int): 표시할 최대 라인 개수
DivergenceResult
다이버전스 감지 결과
Fields:
detected (series bool): 다이버전스 감지 여부
isBullish (series bool): true면 상승, false면 하락
bar1 (series int): 첫 번째 피벗 바 인덱스
value1_price (series float): 첫 번째 가격
value1_ind (series float): 첫 번째 지표값
bar2 (series int): 두 번째 피벗 바 인덱스
value2_price (series float): 두 번째 가격
value2_ind (series float): 두 번째 지표값
다이버전스 감지 및 시각화 라이브러리 (범용 설계)
newPivot(bar, priceVal, indVal)
피벗 포인트 생성
Parameters:
bar (int): 바 인덱스
priceVal (float): 가격
indVal (float): 지표값
Returns: PivotPoint
newDivSettings(pivotLen, maxStore, maxShow)
다이버전스 설정 생성
Parameters:
pivotLen (int): 피벗 좌우 캔들
maxStore (int): 저장 개수
maxShow (int): 표시 라인 개수
Returns: DivergenceSettings
emptyDivResult()
빈 다이버전스 결과
Returns: 감지 안 된 DivergenceResult
checkPivotHigh(length, source)
고점 피벗 감지
Parameters:
length (int): 좌우 비교 캔들 수
source (float): 비교할 데이터 (지표값)
Returns: 피벗 값 또는 na
checkPivotLow(length, source)
저점 피벗 감지
Parameters:
length (int): 좌우 비교 캔들 수
source (float): 비교할 데이터 (지표값)
Returns: 피벗 값 또는 na
addPivotToArray(pivotArray, pivot, maxSize)
피벗을 배열에 추가 (FIFO 방식)
Parameters:
pivotArray (array<PivotPoint>): 피벗 배열
pivot (PivotPoint): 추가할 피벗
maxSize (int): 최대 크기
checkBullishDivergence(pivotArray)
상승 다이버전스 체크 (Bullish)
Parameters:
pivotArray (array<PivotPoint>): 저점 피벗 배열
Returns: DivergenceResult
checkBearishDivergence(pivotArray)
하락 다이버전스 체크 (Bearish)
Parameters:
pivotArray (array<PivotPoint>): 고점 피벗 배열
Returns: DivergenceResult
createDivLine(result, lineColor, isOverlay)
다이버전스 라인 생성
Parameters:
result (DivergenceResult): DivergenceResult
lineColor (color): 라인 색상
isOverlay (bool): true면 가격 기준, false면 지표 기준
Returns: [line, label]
cleanupLines(lineArray, labelArray, maxLines)
오래된 라인/라벨 정리
Parameters:
lineArray (array<line>): 라인 배열
labelArray (array<label>): 라벨 배열
maxLines (int): 최대 유지 개수
addLineAndCleanup(lineArray, labelArray, newLine, newLabel, maxLines)
라인/라벨 추가 및 자동 정리
Parameters:
lineArray (array<line>): 라인 배열
labelArray (array<label>): 라벨 배열
newLine (line): 새 라인
newLabel (label): 새 라벨
maxLines (int): 최대 개수
PivotPoint
피벗 데이터 저장
Fields:
barIndex (series int): 바 인덱스
price (series float): 종가
indicatorValue (series float): 지표값
DivergenceSettings
다이버전스 설정
Fields:
pivotLength (series int): 피벗 좌우 캔들 수
maxPivotsStore (series int): 저장할 최대 피벗 개수
maxLinesShow (series int): 표시할 최대 라인 개수
DivergenceResult
다이버전스 감지 결과
Fields:
detected (series bool): 다이버전스 감지 여부
isBullish (series bool): true면 상승, false면 하락
bar1 (series int): 첫 번째 피벗 바 인덱스
value1_price (series float): 첫 번째 가격
value1_ind (series float): 첫 번째 지표값
bar2 (series int): 두 번째 피벗 바 인덱스
value2_price (series float): 두 번째 가격
value2_ind (series float): 두 번째 지표값
Pine library
In true TradingView spirit, the author has published this Pine code as an open-source library so that other Pine programmers from our community can reuse it. Cheers to the author! You may use this library privately or in other open-source publications, but reuse of this code in publications is governed by House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Pine library
In true TradingView spirit, the author has published this Pine code as an open-source library so that other Pine programmers from our community can reuse it. Cheers to the author! You may use this library privately or in other open-source publications, but reuse of this code in publications is governed by House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.