OPEN-SOURCE SCRIPT
Anchored VWAP + Bands + Signals

//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")
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")
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.