Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
I am trying to create an indicator that takes all the ticks within a bar and makes a VWAP out of them. The purpose is to have a dot in the middle of the bar where the VWAP sits.
As a first attempt, I coded it form gomCD, separating Buy and Sell volume. It worked but there was too little difference between buy and sell VWAP for the amount of messing up of charts. Hence, I would like to replace it with a version that does not differentiate between buy/sell volume.
So far, my code is the following:
However, like this I sometimes get 3M bars with non-zero volume that have no VWAP (dot displayed). At the same time I sometimes get a VWAP that lies out of the High-Low range. NT Support kindly told me they cannot "debug custom indicators". It's obvious I am doing something wrong but can't figure out what. Including the screen of what is happening.
Any help is greatly appreciated.
Regards,
Daniel.
EDIT: After writing a new version which stored the Last price and volume from OnMarketData() and calculating the VWAP in OnBarUpdate(), I found out that OnMarketData() does not fire with each tick of the replay. I knew that OnMarketDepth() does not fire on each update of the book on replay, but I had no idea that OnMarketData() is unrealiable as well. NT know about this stuff, I sent them several emails regarding this anomaly, without response. So in the end, I hacked the good ol' gomCD. Gomi, you are King. Without gomCD, ninja is dead.
Can you help answer these questions from other members on NexusFi?
First, if you use OnMarketData(), the outcome depends on the data stream of you data provider. I personally use Interactive Brokers, and they use the fields e.price and e.Volume to transport other information. Often I just get a zero value for price and a huge value for volume, probably representing some sort of cumulated volume.
There is no need to use OnMarketData(), you can all do in OnBarUpdate(). Also I am not sure that OnMarketData() will recognize FirstTickOfBar, as this again is a value related to OnBarUpdate().
Third, your VWAP formula is false. You cannot simply up the price, but you need to add up the weighted price, so you sumSeries should include
or in OnBarUpdate() simply
Not tested.
The following 2 users say Thank You to Fat Tails for this post:
The e.Price * e.Volume was obviously a mistake out of rushing too much. The indicator is running nicely (the same as hacked gomi) but I guess faster. Thank you very much Fat Tails. I learned a lot from those few lines of code.
The following user says Thank You to Eubie for this post:
You would need to set your indicator to CalculateOnBarClose = false. The VWAP will only be displayed on real-time data but not on historical data. If you also want to display an intraday VWAP on historical data, this would would require to load a secondary bar series of 1-tick bars and then perform the calculations by using the secondary bar series.
You can use high + low + open + close as a proxy for the VWAP. It is easier to calculate and does not make much of a difference.