How to get VWAP Value at the bottom of the Chart?

I want to plot VWAP(Volume Weighted Average Price) value at the bottom of the chart for each bars.

I tried it but there is no default option available for VWAP

like, for example

for Bollingr Bands, one can use

Upper Band  = bbandtop( close, 20, 2 );

Lower Band  = bbandbot( close, 20, 2 );

similarly, how to do that for VWAP?

ChatGPT gave me wrong code, was: VWAP Giving all Errors - AFL Programming - AmiBroker Community Forum

understand the code in the topic

I used the following code but value is not coming
(after going through your link)

it shows as NAN

DayStart = DateNum() != Ref( DateNum(), -1 );
VWAP = SumSince( DayStart, Avg * Volume) / SumSince( DayStart, Volume );

Plot(VWAP,"Test VWAP",colorTurquoise);

here is the screenshot

VWAP NAN Error

what is wrong on the above code and how to fix it?

the answer is in the thread, use other formula in later posts. People put so much effort into that topic, one can't expect anything more.

How do I debug my formula? - AFL Programming - AmiBroker Community Forum

1 Like

thanks
the other formula in later posts worked well

here is the code for that

SetBarsRequired(10000, 0); // get enough data

DayStart = DateNum() != Ref( DateNum(), -1 );
Vwap = SumSince(DayStart, (Avg * Volume) ) / SumSince(DayStart, Volume);

Vwap = IIf( DayStart, Avg, Vwap ); // remove Nans !

Plot(Vwap,"Test VWAP",colorTurquoise);

actually I need only VWAP value, no need for VWAP band as of now

so little bit confused on it

as you told lot of discussion on that thread

NAN is not a number. It is result of division zero by zero. In your case the sum of volumes were zero. You can use SafeDivide() function to prevent Nans, or Nz() to convert NAN to zero.

If I remove the following code

Vwap = IIf( DayStart, Avg, Vwap ); // remove Nans !

NAN is appearing at first candle of a intraday chart for that day, even though that candle has volume.

and from next candles its working nicely.