오랬동안 특정 지지/저항선을 돌파하지 못했다면 그 지지 저항선의 신뢰도는 높다. 따라서 시간의 흐름에 따라 돌파 또는 돌파시도 여부에 따라 특정 지지/저항선의…
- User
오랬동안 특정 지지/저항선을 돌파하지 못했다면 그 지지 저항선의 신뢰도는 높다. 따라서 시간의 흐름에 따라 돌파 또는 돌파시도 여부에 따라 특정 지지/저항선의 기간을 유동적으로 늘려야한다.
또한 이미 형성된 지지/저항선 근처에 새로운(지지보다 높고 저항보다 낮은)저점/고점이 생길 경우에는 무시해야 한다. 무시 안할 경우 지나치게 많은 지지/저항선이 생긴다. 즉 이때 '근처'라는 개념을 변동성을 통해서 도출해야 한다.
이때 근처의 개념을 확정짓기 위해서는 고점의 경우 고점만 판단하면 안되고 저점과 저점과 고점과의 차이도 고려해야 한다.
위의 아이디어를 실현시켜주는 파인스크립트 코드를 작성해줘
Assistant
지지/저항선 신뢰도 기반 필터링 파인스크립트
//@version=5 indicator("Dynamic Support/Resistance with Reliability", overlay=true) // 사용자 설정 input lookbackPeriod = 200 // 기본 분석 기간 input volatilityFactor = 1.5 // 변동성 계수 (근처 판단 기준) input minBounces = 3 // 최소 반응 횟수 input showZones = true // 지지/저항 영역 표시 여부 // 변수 선언 var float[] supportLevels = array.new_float() var float[] resistanceLevels = array.new_float() var int[] supportCounts = array.new_int() var int[] resistanceCounts = array.new_int() var int[] supportLastTest = array.new_int() var int[] resistanceLastTest = array.new_int() // 변동성 계산 (ATR 기반) atrLength = 14 atr = ta.atr(atrLength) zoneThreshold = atr * volatilityFactor // 고점/저점 식별 swingHigh = ta.pivothigh(high, 2, 2) swingLow = ta.pivotlow(low, 2, 2) // 새로운 고점/저점 처리 if not na(swingHigh) processSwing(swingHigh, true) if not na(swingLow) processSwing(swingLow, false) // 지지/저항선 업데이트 및 필터링 updateAndFilterLevels() // 차트 표시 if showZones displayZones() // --------------------------------------------------------------------------- // 함수: 스윙 포인트 처리 // --------------------------------------------------------------------------- processSwing(price, isHigh) => levelsArray = isHigh ? resistanceLevels : supportLevels countsArray = isHigh ? resistanceCounts : supportCounts lastTestArray = isHigh ? resistanceLastTest : supportLastTest foundNearby = false for i = 0 to array.size(levelsArray) - 1 level = array.get(levelsArray, i) // 변동성 기반 근접성 판단 if math.abs(price - level) <= zoneThreshold // 기존 레벨 근처에 새로운 스윙 포인트가 형성된 경우 foundNearby = true array.set(countsArray, i, array.get(countsArray, i) + 1) array.set(lastTestArray, i, bar_index) break if not foundNearby // 새로운 레벨 추가 array.push(levelsArray, price) array.push(countsArray, 1) array.push(lastTestArray, bar_index) // --------------------------------------------------------------------------- // 함수: 레벨 업데이트 및 필터링 // --------------------------------------------------------------------------- updateAndFilterLevels() => // 지지선 필터링 i = 0 while i < array.size(supportLevels) level = array.get(supportLevels, i) count = array.get(supportCounts, i) lastTest = array.get(supportLastTest, i) // 오랫동안 테스트되지 않았거나 반응 횟수가 적은 레벨 제거 if (bar_index - lastTest > lookbackPeriod * 0.5 and count < minBounces) or (close > level and count < minBounces) array.remove(supportLevels, i) array.remove(supportCounts, i) array.remove(supportLastTest, i) else i := i + 1 // 저항선 필터링 i = 0 while i < array.size(resistanceLevels) level = array.get(resistanceLevels, i) count = array.get(resistanceCounts, i) lastTest = array.get(resistanceLastTest, i) // 오랫동안 테스트되지 않았거나 반응 횟수가 적은 레벨 제거 if (bar_index - lastTest > lookbackPeriod * 0.5 and count < minBounces) or (close < level and count < minBounces) array.remove(resistanceLevels, i) array.remove(resistanceCounts, i) array.remove(resistanceLastTest, i) else i := i + 1 // --------------------------------------------------------------------------- // 함수: 지지/저항 영역 표시 // --------------------------------------------------------------------------- displayZones() => // 지지선 표시 for i = 0 to array.size(supportLevels) - 1 level = array.get(supportLevels, i) count = array.get(supportCounts, i) reliability = math.min(100, count * 20) lineColor = color.new(color.green, 100 - reliability * 0.7) lineWidth = math.max(1, reliability / 20) line.new(bar_index - lookbackPeriod, level, bar_index, level, color=lineColor, width=lineWidth, style=line.style_dashed) label.new(bar_index, level, str.tostring(level, format.mintick) + "\nRel: " + str.tostring(reliability, "#") + "%", color=color.green, style=label.style_label_up) // 저항선 표시 for i = 0 to array.size(resistanceLevels) - 1 level = array.get(resistanceLevels, i) count = array.get(resistanceCounts, i) reliability = math.min(100, count * 20) lineColor = color.new(color.red, 100 - reliability * 0.7) lineWidth = math.max(1, reliability / 20) line.new(bar_index - lookbackPeriod, level, bar_index, level, color=lineColor, width=lineWidth, style=line.style_dashed) label.new(bar_index, level, str.tostring(level, format.mintick) + "\nRel: " + str.tostring(reliability, "#") + "%", color=color.red, style=label.style_label_down)코드 설명
-
동적 지지/저항선 식별:
- 가격이 특정 수준에서 여러 번 반응할 경우 해당 수준을 지지/저항선으로 인식
- 변동성(ATR)을 기반으로 "근처" 개념을 정의하여 지나치게 많은 수준이 생성되는 것 방지
-
신뢰도 시스템:
- 각 지지/저항선이 테스트된 횟수를 기록하여 신뢰도 계산
- 오랫동안 테스트되지 않거나 반응이 적은 수준은 자동으로 제거
-
시각화:
- 지지선은 녹색, 저항선은 빨간색으로 표시
- 선의 두께와 투명도로 신뢰도 시각화
- 각 수준에 가격 값과 신뢰도(%) 표시
-
사용자 설정:
- 분석 기간(lookbackPeriod), 변동성 계수(volatilityFactor), 최소 반응 횟수(minBounces) 등을 조정 가능
이 코드는 여러 번 테스트된 강력한 지지/저항선을 강조하고, 약한 수준은 필터링하여 클린한 차트 분석을 가능하게 합니다.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
command-a-03-2025Compare side by side →
- gpt-4.1-mini-2025-04-14Compare side by side →
llama-3.3-70b-instructCompare side by side →
llama-3.3-70b-instructCompare side by side →
claude-3-5-sonnet-20241022Compare side by side →
- o3-miniCompare side by side →
gemini-2.5-proCompare side by side →
claude-sonnet-4-20250514Compare side by side →
qwen3-235b-a22bCompare side by side →