NexusFi: Find Your Edge


Home Menu

 





NT Providing Bad Price & Volume Data in OnMarketData!!!


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one RJay with 6 posts (24 thanks)
    2. looks_two NinjaTrader with 2 posts (4 thanks)
    3. looks_3 Zondor with 2 posts (5 thanks)
    4. looks_4 aviat72 with 2 posts (2 thanks)
      Best Posters
    1. looks_one RJay with 4 thanks per post
    2. looks_two Zondor with 2.5 thanks per post
    3. looks_3 NinjaTrader with 2 thanks per post
    4. looks_4 aviat72 with 1 thanks per post
    1. trending_up 9,989 views
    2. thumb_up 36 thanks given
    3. group 8 followers
    1. forum 18 posts
    2. attach_file 1 attachments




 
Search this Thread

NT Providing Bad Price & Volume Data in OnMarketData!!!

  #11 (permalink)
 
RJay's Avatar
 RJay 
Hartford, CT. USA
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG, Kinetick
Trading: RTY
Posts: 683 since Jun 2009
Thanks Given: 758
Thanks Received: 787


Zondor View Post
hi RJay,

Please post sample code or pseudo code showing correct method to use, thanks!

No problem, here is a sample.

-----------------------------------------------------------------------------------------------------------------------

protected override void OnMarketData(MarketDataEventArgs e)

{


if (e.MarketDataType == MarketDataType.Ask )theAsk = e.Price; // Add this line

if (e.MarketDataType == MarketDataType.Bid )theBid = e.Price; // Add this line

if (e.MarketDataType != MarketDataType.Last)return;


// if (e.MarketData.Ask != null) theAsk = e.MarketData.Ask.Price; // comment out this line

// if (e.MarketData.Bid != null) theBid = e.MarketData.Bid.Price; // comment out this line

if(theBid <= 0 || theAsk <= 0) return;


if (e.Price == theAsk) { netVolUp += e.Volume; }
else if (e.Price == theBid) { netVolDown -= e.Volume; }


}


------------------------------------------------------------------------------------------------------------------


RJay

Started this thread Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
MC PL editor upgrade
MultiCharts
Better Renko Gaps
The Elite Circle
Trade idea based off three indicators.
Traders Hideout
About a successful futures trader who didn´t know anyth …
Psychology and Money Management
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
  #12 (permalink)
 
eDanny's Avatar
 eDanny 
East Rochester, NY
 
Experience: Intermediate
Platform: NT
Posts: 329 since Jul 2009
Thanks Given: 18
Thanks Received: 425


aviat72 View Post
I think the conversation confirms what I wrote in the previous post. The FirstTickOfBar is only valid in the context of OnBarUpdate().

This is the problem. Volume[0] works ok in OnBarUpdate(). If counting your own volume from OnMarketData() the first tick of the bar will be dropped. If the number of contracts in that tick is one, your count will be less that Volume[0] or the VOL indicator by one. If there were three contracts, your count will be three less than VOL shows. This is a problem that shows up if using FirstTickOfBar in OnBarUpdate() or if using code like if(CurrentBar != activeBar) in OnMarketData() to start your count in NT7.

Dan

Reply With Quote
Thanked by:
  #13 (permalink)
 
RJay's Avatar
 RJay 
Hartford, CT. USA
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG, Kinetick
Trading: RTY
Posts: 683 since Jun 2009
Thanks Given: 758
Thanks Received: 787



RJay View Post
In OnMarketData, NT provides temporary values for coders for volume and price, for bid, ask and last.

These values are accessed with the following code.

-----------------------------------------------------------------

e.MarketData.Ask.Price

e.MarketData.Bid.Price

e.MarketData.Last.Price

e.MarketData.Ask.Volume

e.MarketData.Bid.Volume

e.MarketData.Last.Volume

----------------------------------------------------------------

If you are using any of these coding queries in your indicators, your indicators are displaying bad data!!!


Here are a few examples of what is going wrong:


When several ticks arrive at the same time, NT tends to assign all of those trades the same volume even though the trades all had different volumes.

Also, When the market trends strongly in one direction, the bid and ask prices offered fall behind the live market. This
results in last trades for both the bid and the ask, to be tallied, either, all for the bid, or all for the ask.

This really screws up stuff like volume delta calculations!!!!


This problem is persistent in both NT 6.5 and NT7.


The workaround for this problem is to create your own temporary store values from e.Volume and e.Price.

Below are the lines of code that I now use in my indicators.

---------------------------------------------------------------------------------------------------

if (e.MarketDataType == MarketDataType.Ask)ePriceAsk = e.Price;

if (e.MarketDataType == MarketDataType.Bid)ePriceBid = e.Price;

if (e.MarketDataType == MarketDataType.Last)ePriceLast = e.Price;

if (e.MarketDataType == MarketDataType.Ask)eVolumeAsk = e.Volume;

if (e.MarketDataType == MarketDataType.Bid)eVolumeBid = e.Volume;

if (e.MarketDataType == MarketDataType.Last)eVolumeLast = e.Volume;

---------------------------------------------------------------------------------------------------

After I made these changes and put the temporary patch for the CurrentBar/FirstTickOfBar bug into my indicators, my NT7 indicators are now matching the Time & Sales display window tick for tick.


I plan to post a problem report on the NT forum this Monday and hope they will take steps to resolve this issue.

I am also building an indicator that will send all of the bad data mismatches to the output window to help NT confirm the problem.


Comments and feedback are appreciated,


RJay



FYI, All the Bid/Ask volume indicators I have posted here, on this forum, have this problem. I will update them when NT7 is finally released.

Just to clarify, This problem is not about your datafeed, it's about how your indicators are constructed.

If your indicators are using bad data values, it won't matter what datafeed your using.

Your indicator displays on the chart will be wrong!!!


Test this for yourselves.

Attached is a test indicator that displays differences between NT's temporary store values and your live feed.

Just open your output window and see what I'm talking about. Every display update is a mismatch.

Seeing is Believing,

RJay

Attached Files
Elite Membership required to download: AA_RJay_OnMarketData_Test.cs
Started this thread Reply With Quote
  #14 (permalink)
 
NinjaTrader's Avatar
 NinjaTrader  NinjaTrader is an official Site Sponsor
Site Sponsor

Web: NinjaTrader
AMA: Ask Me Anything
Webinars: NinjaTrader Webinars
Elite offer: Click here
 
Posts: 1,714 since May 2010
Thanks Given: 203
Thanks Received: 2,686

RJay,
You are correct that if you are to use OnMarketData() and you wish to do value comparisons you should store local values in your indicator/strategy. This is expected and has always been the case and is by design. We have advised developers of this in the past but in further research, I see this critical point should have been clearly documented and it will be going forward.

Here are a few points of clarification:

- OnMarketData() is guaranteed to be called in the correct sequence for all level I market data events received from the underlying data source (no data is ever dropped)
- e.MarketDataType determines what data type (bid, ask, last etc…) changed and triggered the call to OnMarketData()
- You should store local variables and update them as OnMarketData() is fired based off the data type that was changed
- e.MarketData can be ignored (if doing comparisons) since values can and likely will be ahead of the data type/value that triggered OnMarketData()
- This is because the underlying MarketData object can be updated on different threads and reflects the most recent values received (you of course will get a OnMarketData() call for these events subsequently)
- And as I replied to you before, FirstTickOfBar is only relevant in the scope of OnBarUpdate()

Ray

Follow me on Twitter Reply With Quote
  #15 (permalink)
 
Jigsaw Trading's Avatar
 Jigsaw Trading  Jigsaw Trading is an official Site Sponsor
 
Posts: 2,988 since Nov 2010
Thanks Given: 831
Thanks Received: 10,393

Many thanks to the OP on this.

I noticed yesterday that something wasn't right on the ES. I have a couple of tools & one of them uses e.MarketData.Bid.Price;

I have been scratching my head all morning looking at code that should work - now I know why it doesn't.

Testing tonight - but based on the symptoms in the OP - this fits my problem perfectly.

DT

Visit my NexusFi Trade Journal Reply With Quote
  #16 (permalink)
 grimReaper 
Los Angeles, CA
 
Posts: 50 since Nov 2011

Did NT fix this?

I haven't encountered this problem (yet), but perhaps this would increase smoothness:



 
Code
protected override void OnMarketData(MarketDataEventArgs e){

      MarketDataEventArgs L1DataEvents = e;

      if (L1DataEvents.MarketDataType == MarketDataType.Ask)newAsk = L1DataEvents.Price;

...

}

Reply With Quote
  #17 (permalink)
 
NinjaTrader's Avatar
 NinjaTrader  NinjaTrader is an official Site Sponsor
Site Sponsor

Web: NinjaTrader
AMA: Ask Me Anything
Webinars: NinjaTrader Webinars
Elite offer: Click here
 
Posts: 1,714 since May 2010
Thanks Given: 203
Thanks Received: 2,686


grimReaper View Post
Did NT fix this?

I haven't encountered this problem (yet), but perhaps this would increase smoothness:



 
Code
protected override void OnMarketData(MarketDataEventArgs e){

      MarketDataEventArgs L1DataEvents = e;

      if (L1DataEvents.MarketDataType == MarketDataType.Ask)newAsk = L1DataEvents.Price;

...

}

On post #14 I clarified the architecture and how to properly handle on market data comparisons in an asynchronous environment. There was nothing to fix.

Follow me on Twitter Reply With Quote
  #18 (permalink)
lance80
United Kingdom
 
Posts: 1 since Jun 2017
Thanks Given: 0
Thanks Received: 0

hi has anyone fix this as I'm trying to make an Indicator that will let me see the sales in the candle

Reply With Quote
  #19 (permalink)
 
freedomtrader's Avatar
 freedomtrader 
N.Texas
 
Experience: Advanced
Platform: NinjaTrader
Broker: Global Futures
Trading: ZB
Posts: 39 since Aug 2010
Thanks Given: 174
Thanks Received: 6


lance80 View Post
hi has anyone fix this as I'm trying to make an Indicator that will let me see the sales in the candle

Hey lance80

Have you checked out NT8 downloads?
There are several that will show you orderflow/footprint [" the sales in the candle" ] ie;
https://nexusfi.com/local_links_sort.php?catid=27&filter=&sort=d&page=1&pp=10&keyid=1210

Good luck

Follow me on Twitter Reply With Quote




Last Updated on June 5, 2017


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
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.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts