VWAP - all data

Could someone help me? I was trying to find Vwap not only for intraday but also for more historical DAta. Some platforms have this option for Vwap build in. I do have formula for normal Vwap:

The VWAP for a stock is calculated by adding the dollars traded for every
transaction in that stock ("price" x "number of shares traded") and dividing the total shares traded. A VWAP is computed from the Open of the market to the market Close, AND is calculated by Volume weighting all transactions during this time period
Bars_so_far_today = 1 + BarsSince( Day() != Ref(Day(), -1));
StartBar = ValueWhen(TimeNum() == 093000, BarIndex());
TodayVolume = Sum(V,Bars_so_far_today);
IIf (BarIndex() >= StartBar, VWAP = Sum (C * V, Bars_so_far_today  ) / TodayVolume,0);
Plot (VWAP,"VWAP",colorOrange, styleThick);

But it doesn’t work for more e.g 3,5 Years. I would really apreaciate help.

Best Regards

@PolTrader if you are looking at calculating a VWAP for any range of look back periods you could try the codes here,


1 Like

I have used the code given in the below link for creating VWAP indicator:
But when I call it in the formula to back test, it throws the error message 'variable 'vwap' used without having been initialized'. Could you please guide me?

That's not VWAP! Its VWMA. For VWAP, try this:


@av.ragavan I was mistaken back in 2017 and posted the wrong link/code. @Cougar is correct, sorry about that.

Doesn't appear as if anyone noticed or people were just too polite to point out my mistake. There are several discussion on this forum about related VWAP-like ("Midas" and "TB-F") indicators that you can also look over by searching this forum.

1 Like

Thanks for your support.

Thank you for listing this. I am a newer user. I entered this code and I am trying to figure out how to get VWAP to show correctly in the Parameter menu so I can edit it's settings there (color, line type, turn it on/off, etc).
When I look at other parameter code this is the type of code I see:
P = ParamField("Price field",-1);
would changing Price field to VWAP in this code do it?

Thank you!

See this forum for the same version but with Daily VWAP etc..