Intrabar VWAP - futures io
futures io futures trading



Intrabar VWAP


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Fat Tails with 2 posts (2 thanks)
    2. looks_two ejtrader with 2 posts (0 thanks)
    3. looks_3 Eubie with 2 posts (1 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 3,603 views
    2. thumb_up 3 thanks given
    3. group 3 followers
    1. forum 6 posts
    2. attach_file 2 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • 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 and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

Intrabar VWAP

(login for full post details)
  #1 (permalink)
Prague, Czech republic
 
Experience: Beginner
Platform: NinjaTrader/ZF
Trading: ES, TF
 
Posts: 87 since Jul 2010
Thanks: 119 given, 47 received

Hello everybody,

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:

 
Code
	
private double SumPrices;
private double SumVolume;

...

protected override void OnMarketData(MarketDataEventArgs e)
{
if ( FirstTickOfBar ){
	SumPrices = 0;
	SumVolume = 0;
	}
	
SumPrices += e.Price;
SumVolume += e.Volume;

DrawDot( "IntrabarVWAP" + CurrentBar, false, 0, SumPrices / SumVolume, Color.Black);
}
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.

Attached Thumbnails
Click image for larger version

Name:	Intrabar_VWAP_error.PNG
Views:	144
Size:	20.3 KB
ID:	52214  
Started this thread Reply With Quote

Journal Challenge February 2021 results (so far):
Competing for $1500 in prizes from Topstep
looks_oneSBtrader82 's Trading Journalby SBtrader82
(170 thanks from 31 posts)
looks_twoJust BEING a Trader: Letting Go!!by iqgod
(116 thanks from 33 posts)
looks_3Wisdom is Emptinessby Mtype
(68 thanks from 25 posts)
looks_4Deetee’s DAX Trading Journal (time based)by Deetee
(31 thanks from 17 posts)
looks_5Journal for peanuts1956by peanuts1956
(23 thanks from 13 posts)
 
 
(login for full post details)
  #3 (permalink)
Market Wizard
Berlin, Europe
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
 
Fat Tails's Avatar
 
Posts: 9,855 since Mar 2010
Thanks: 4,238 given, 26,728 received



Eubie View Post
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.

There are several problems with your code.

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

 
Code
sumPriceVolume  +=  e.Price * e.Volume;
sumVolume += e.Volume;
or in OnBarUpdate() simply

 
Code
if (FirstTickOfBar)
{
      sumPriceVolume = Close[0] * Volume[0];
      sumVolume = Volume[0];
}
else
{
      sumPriceVolume += Close[0] * (Volume[0] - sumVolume);
      sumVolume = Volume[0];
}
if (sumVolume> 0)
   DrawDot ("IntrabarVWAP" + CurrentBar, false, 0, sumPriceVolume / sumVolume, Color.Black);
Not tested.

Reply With Quote
The following 2 users say Thank You to Fat Tails for this post:
 
(login for full post details)
  #4 (permalink)
Prague, Czech republic
 
Experience: Beginner
Platform: NinjaTrader/ZF
Trading: ES, TF
 
Posts: 87 since Jul 2010
Thanks: 119 given, 47 received

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.

Started this thread Reply With Quote
The following user says Thank You to Eubie for this post:
 
(login for full post details)
  #5 (permalink)
Portland, OR
 
Experience: Intermediate
Platform: Sierra Chart
Trading: ES
 
Posts: 269 since Jan 2011
Thanks: 327 given, 180 received

Eubie/Harry - I tried to use this exact code - and I get the dots plotted on the close of the bar - instead of calculated VWAP for the bar.

Anything wrong with the code or should I be doing this with Gomi framework?

Thanks.

 
Code
        protected override void OnBarUpdate()
        {
			if (FirstTickOfBar)
			{
      			sumPriceVolume = Close[0] * Volume[0];
      			sumVolume = Volume[0];
			}
			else
			{
      			sumPriceVolume += Close[0] * (Volume[0] - sumVolume);
      			sumVolume = Volume[0];
			}

			if (sumVolume> 0)
   			DrawDot ("IntrabarVWAP" + CurrentBar, false, 0, sumPriceVolume / sumVolume, Color.Black);
        }

Attached Thumbnails
Click image for larger version

Name:	NT_Dots.jpg
Views:	58
Size:	26.7 KB
ID:	61492  
Reply With Quote
 
(login for full post details)
  #6 (permalink)
Market Wizard
Berlin, Europe
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
 
Fat Tails's Avatar
 
Posts: 9,855 since Mar 2010
Thanks: 4,238 given, 26,728 received


ejtrader View Post
Eubie/Harry - I tried to use this exact code - and I get the dots plotted on the close of the bar - instead of calculated VWAP for the bar.

Anything wrong with the code or should I be doing this with Gomi framework?

Thanks.

 
Code
        protected override void OnBarUpdate()
        {
            if (FirstTickOfBar)
            {
                  sumPriceVolume = Close[0] * Volume[0];
                  sumVolume = Volume[0];
            }
            else
            {
                  sumPriceVolume += Close[0] * (Volume[0] - sumVolume);
                  sumVolume = Volume[0];
            }

            if (sumVolume> 0)
               DrawDot ("IntrabarVWAP" + CurrentBar, false, 0, sumPriceVolume / sumVolume, Color.Black);
        }

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.

Reply With Quote
 
(login for full post details)
  #7 (permalink)
Portland, OR
 
Experience: Intermediate
Platform: Sierra Chart
Trading: ES
 
Posts: 269 since Jan 2011
Thanks: 327 given, 180 received

Thanks Harry.

I would use the O+C+H+L instead of close instead.

Reply With Quote


futures io Trading Community Platforms and Indicators NinjaTrader > Intrabar VWAP


Last Updated on February 3, 2012


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Journal Challenge w/$1500 prizes from Topstep!

February
 

Battlestations! Show us your trading desk - $1,500 in prizes!

March
 

Call Option Buying: The New Pain Trade? w/Carley Garner

Elite only
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts