PROTECTED SOURCE SCRIPT
Atualizado

Dual Anchored VWAP (v6) by MrTiff

32
Dual Anchored VWAP

//version=6
indicator("Dual Anchored VWAP (v6, fixed)", overlay=true)

// ---------- Inputs: AVWAP #1 (buyers)
useAVWAP1 = input.bool(true, "Show AVWAP #1 (buyers)")
tz1 = input.string("Etc/UTC", "Timezone #1")
y1 = input.int(2024, "Year #1")
m1 = input.int(9, "Month #1", 1, 12)
d1 = input.int(1, "Day #1", 1, 31)
h1 = input.int(13, "Hour #1", 0, 23)
min1 = input.int(30, "Minute #1",0, 59)
col1 = input.color(color.new(color.teal, 0), "Color #1")
width1 = input.int(2, "Width #1", minval=1, maxval=5)

// ---------- Inputs: AVWAP #2 (sellers)
useAVWAP2 = input.bool(true, "Show AVWAP #2 (sellers)")
tz2 = input.string("Etc/UTC", "Timezone #2")
y2 = input.int(2024, "Year #2")
m2 = input.int(10, "Month #2", 1, 12)
d2 = input.int(8, "Day #2", 1, 31)
h2 = input.int(15, "Hour #2", 0, 23)
min2 = input.int(30, "Minute #2",0, 59)
col2 = input.color(color.new(color.orange, 0), "Color #2")
width2 = input.int(2, "Width #2", minval=1, maxval=5)

// ---------- Other settings
src = input.source(ohlc4, "Price source (VWAP uses weighted avg)")
showBands = input.bool(false, "Show simple 1σ bands (approx)")

// ---------- Build anchor timestamps from parts
anchor1 = timestamp(tz1, y1, m1, d1, h1, min1)
anchor2 = timestamp(tz2, y2, m2, d2, h2, min2)

// ---------- Function: AVWAP from an anchor (no session reset)
avwapFrom(anchorTime) =>
cond = time >= anchorTime
cumPV = ta.cum(cond ? (src * volume) : 0.0)
cumV = ta.cum(cond ? volume : 0.0)
vw = cumV > 0 ? (cumPV / cumV) : na
vw

// ---------- Compute AVWAPs
vwap1 = useAVWAP1 ? avwapFrom(anchor1) : na
vwap2 = useAVWAP2 ? avwapFrom(anchor2) : na

// ---------- Plot AVWAPs
plot(vwap1, title="AVWAP #1", color=col1, linewidth=width1)
plot(vwap2, title="AVWAP #2", color=col2, linewidth=width2)

// ---------- Optional σ bands (proxy; not true VWAP σ)
sigma(v) => ta.stdev(close - v, 100)

// Compute the stdevs only when needed, otherwise na
s1 = (showBands and not na(vwap1)) ? sigma(vwap1) : na
s2 = (showBands and not na(vwap2)) ? sigma(vwap2) : na

// Build band series (or na if disabled)
vwap1_up = not na(s1) ? vwap1 + s1 : na
vwap1_dn = not na(s1) ? vwap1 - s1 : na
vwap2_up = not na(s2) ? vwap2 + s2 : na
vwap2_dn = not na(s2) ? vwap2 - s2 : na

// Plot at global scope (valid in Pine)
plot(vwap1_up, title="AVWAP #1 +1σ", color=color.new(col1, 60))
plot(vwap1_dn, title="AVWAP #1 -1σ", color=color.new(col1, 60))
plot(vwap2_up, title="AVWAP #2 +1σ", color=color.new(col2, 60))
plot(vwap2_dn, title="AVWAP #2 -1σ", color=color.new(col2, 60))

// ---------- Alerts
alertcondition(ta.cross(close, vwap1), "Cross AVWAP #1", "Price crossed AVWAP #1")
alertcondition(ta.cross(close, vwap2), "Cross AVWAP #2", "Price crossed AVWAP #2")

Notas de Lançamento
update

Aviso legal

As informações e publicações não devem ser e não constituem conselhos ou recomendações financeiras, de investimento, de negociação ou de qualquer outro tipo, fornecidas ou endossadas pela TradingView. Leia mais em Termos de uso.