OPEN-SOURCE SCRIPT

Anchored VWAP + Bands + Signals

51
//version=5
indicator("Anchored VWAP + Bands + Signals", overlay=true)

// ===== INPUTS =====
anchorTime = input.time(timestamp("2025-12-02 00:00"), "Anchor Date/Time")
std1 = input.float(1.0, "±1σ Band")
std2 = input.float(2.0, "±2σ Band")

// ===== VWAP CALCULATION =====
var float cumPV = 0.0
var float cumVol = 0.0

if time >= anchorTime
cumPV += close * volume
cumVol += volume

vwap = cumVol != 0 ? cumPV / cumVol : na

// ===== STANDARD DEVIATION =====
barsSinceAnchor = bar_index - ta.valuewhen(time >= anchorTime, bar_index, 0)
sd = barsSinceAnchor > 1 ? ta.stdev(close, barsSinceAnchor) : 0

// ===== BANDS =====
upper1 = vwap + std1 * sd
lower1 = vwap - std1 * sd
upper2 = vwap + std2 * sd
lower2 = vwap - std2 * sd

plot(vwap, color=color.orange, title="VWAP")
plot(upper1, color=color.green, title="+1σ Band")
plot(lower1, color=color.green, title="-1σ Band")
plot(upper2, color=color.red, title="+2σ Band")
plot(lower2, color=color.red, title="-2σ Band")

// ===== SIGNALS =====
buySignal = ta.crossover(close, lower1)
sellSignal = ta.crossunder(close, upper1)

plotshape(buySignal, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, title="Buy Signal")
plotshape(sellSignal, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, title="Sell Signal")

alertcondition(buySignal, title="Buy Alert", message="Price touched lower 1σ band – Buy Opportunity")
alertcondition(sellSignal, title="Sell Alert", message="Price touched upper 1σ band – Sell Opportunity")

면책사항

해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.