Paste this independent implementation into the Pine Editor. Enable Synthetic example with length 3 to reproduce bars 0 through 9 of the table; indexing starts at the first loaded chart bar. The Data Window exposes input volume, S, α and window validity. With test mode off, the script uses close and volume from the chart feed. The strict-window VWMA comparison is calculated explicitly so both lines share the stated missing-data policy.
Educational formula implementation. Syntax validation checks compilation diagnostics; numerical examples and chart comparisons test separate properties.pine
//@version=6
indicator("Rolling-budget EVWMA and VWMA", overlay=true)
length = input.int(3, "Volume window", minval=1)
isTest = input.bool(false, "Synthetic example")
float samplePrice = switch bar_index
0 => 100.0
1 => 102.0
2 => 104.0
3 => 110.0
4 => 120.0
5 => 80.0
6 => 90.0
=> 100.0
float sampleVolume = switch bar_index
0 => 10.0
1 => 10.0
2 => 10.0
3 => 30.0
4 => 0.0
5 => 60.0
6 => 0.0
7 => 0.0
8 => 0.0
=> 10.0
float p = isTest ? samplePrice : close
float v = isTest ? sampleVolume : volume
bool validBar = not na(p) and not na(v) and v >= 0
float validCount = math.sum(validBar ? 1.0 : 0.0, length)
float total = math.sum(validBar ? v : 0.0, length)
float weighted = math.sum(validBar ? p * v : 0.0, length)
bool validWindow = bar_index >= length - 1 and validCount == length
float alpha = validWindow and total > 0 ? math.max(0.0, math.min(1.0, v / total)) : na
var float evwma = na
if not validWindow
evwma := na
else if total > 0 and v > 0
evwma := na(evwma[1]) ? p : evwma[1] + alpha * (p - evwma[1])
else
evwma := evwma[1]
float vwma = validWindow and total > 0 ? weighted / total : na
plot(evwma, "EVWMA", color=color.blue, linewidth=2, style=plot.style_linebr)
plot(vwma, "Strict-window VWMA", color=color.orange, style=plot.style_linebr)
plot(v, "Input volume", display=display.data_window)
plot(validWindow ? total : na, "Volume budget", display=display.data_window)
plot(alpha, "Update fraction", display=display.data_window)
plot(validWindow ? 1 : 0, "Valid window", display=display.data_window)
plot(isTest ? bar_index : na, "Test bar", display=display.data_window)
bool crossUp = ta.crossover(p, evwma)
alertcondition(not isTest and validWindow and v > 0 and barstate.isconfirmed and crossUp, "Price crosses above EVWMA", "Close crossed above EVWMA on a confirmed chart bar.")