피벗 기록 (type + map)
esi 추천지표 · esi · 2026-11-23 · 복제 0회 · #패턴 #배우기
확정된 피벗 고점·저점을 사용자 자료형에 담아 최근 값을 선으로, 개수는 map에 세어 5개째마다 알림.
원문
28줄 · 1,101자indicator("피벗 기록", overlay=true)
left = input.int(5, "왼쪽 봉", minval=1, maxval=50)
right = input.int(5, "오른쪽 봉", minval=1, maxval=50)
type Pivot
float price = na
int index = 0
string kind = "H"
var Pivot lastHigh = na
var Pivot lastLow = na
var counts = map.new<string, float>()
// 피벗: right봉 전 고가가 앞뒤 (left + right + 1)봉 중 가장 높으면 그 봉에서 확정
ph = high[right] == ta.highest(high, left + right + 1) ? high[right] : na
pl = low[right] == ta.lowest(low, left + right + 1) ? low[right] : na
if not na(ph)
lastHigh := Pivot.new(ph, bar_index - right, "H")
counts.put("H", nz(counts.get("H")) + 1)
if not na(pl)
lastLow := Pivot.new(pl, bar_index - right, kind = "L")
counts.put("L", nz(counts.get("L")) + 1)
hi = na(lastHigh) ? na : lastHigh.price
lo = na(lastLow) ? na : lastLow.price
highs = nz(counts.get("H"))
plot(hi, "최근 피벗 고점", color=red)
plot(lo, "최근 피벗 저점", color=blue)
plotshape(not na(ph), "피벗 고점 확정", shape=down, location=abovebar, color=red)
plotshape(not na(pl), "피벗 저점 확정", shape=up, location=belowbar, color=blue)
alert(not na(ph) and highs % 5 == 0, "피벗 고점 5개째마다")
스크립트는 계산식 공유이며 매수·매도 추천이 아니에요. 서버는 문법만 검사했고, 실행은 내 브라우저에서만 해요(네트워크·외부 코드 실행 없음). 투자 판단과 책임은 이용자 본인에게 있어요.