차트분석이야기

코인지수 트레이딩뷰 파인스크립트

2025. 7. 31. 01:14
728x90
반응형

// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 athttps://mozilla.org/MPL/2.0/
// © rooding

//@version=6
indicator("Alt Market Index (Halving-Adjusted BTC Supply, EMA)", overlay=false)

// 비트코인 시작가 고가 저가 종가
btcOpen = request.security("BINANCE:BTCUSD", timeframe.period, open)
btcHigh = request.security("BINANCE:BTCUSD", timeframe.period, high)
btcLow = request.security("BINANCE:BTCUSD", timeframe.period, low)
btcClose = request.security("BINANCE:BTCUSD", timeframe.period, close)

// 도미넌스 시작가 고가 저가 종가
domOpen = request.security("CRYPTOCAP:BTC.D", timeframe.period, open)
domHigh = request.security("CRYPTOCAP:BTC.D", timeframe.period, high)
domLow = request.security("CRYPTOCAP:BTC.D", timeframe.period, low)
domClose = request.security("CRYPTOCAP:BTC.D", timeframe.period, close)

// 날짜 계산용 기준점
halving2020 = timestamp(2020, 5, 11, 0, 0)
halving2024 = timestamp(2024, 4, 20, 0, 0)

// 오늘 날짜
now = timenow

// 비트코인 일일 추가물량 반감기적용
days1 = (math.min(now, halving2024) - halving2020) / (1000 * 60 * 60 * 24) // 900
days2 = now > halving2024 ? (now - halving2024) / (1000 * 60 * 60 * 24) : 0 // 450
btcSupply = 18600000 + (days1 * 900) + (days2 * 450) // 2020 반감기 기준 초기 공급량 18,600,000 BTC



// 알트 시가총액
calcAltCap(price, dom) =>
btcMarketCap = price * btcSupply
altRatio = 1 - (dom / 100)
btcMarketCap * altRatio

// 알트시총 시작가 고가 저가 종가
altOpen = calcAltCap(btcOpen, domOpen)
altHigh = calcAltCap(btcHigh, domLow)
altLow = calcAltCap(btcLow, domHigh)
altClose = calcAltCap(btcClose, domClose)

// 정규화 함수 기준 100
var float base = na
if na(base) and altClose != 0
base := altClose

norm(v) =>
base != 0 and not na(base) ? v / base * 100 : na


// 정규화된 시작가 고가 저가 종가
nOpen = norm(altOpen)
nHigh = norm(altHigh)
nLow = norm(altLow)
nClose = norm(altClose)

// 캔들 출력 조건
plotcandle(nOpen, nHigh, nLow, nClose, title="Alt Market Index (Candle)", color=(nClose > nOpen ? color.green : color.red))

// EMA 이평선
ema50 = ta.ema(nClose, 50)
ema200 = ta.ema(nClose, 200)
ema300 = ta.ema(nClose, 300)

ema21 = ta.ema(nClose, 21)


plot(ema50, title="EMA 50", color=color.blue, linewidth=1)
plot(ema200, title="EMA 200", color=color.black, linewidth=1)
plot(ema300, title="EMA 300", color=color.purple, linewidth=1)

plot(ema21, title="EMA 21", color=color.red, linewidth=1)

728x90
반응형