NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Indicator Development

Indicator Development Support for the development of custom indicators using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 01-25-2011, 09:17 AM   #1
joanNT
Senior Member
 
Join Date: Feb 2010
Posts: 128
Thanks: 0
Thanked 0 times in 0 posts
Default GetCurrentBID and GetCurrentASK gives wrong data

Hi!

It's strange cause when I open a chart with ZN and ZB instruments I can see the right price displayed on the right right axis, but when I develop an indicator trying to obtain the close, bid or ask data from these instruments it's different that one displayed for each instrument.

I've put some displays and i get wrong values, all variables were defined as double:

Close[0]: 120,3125
Inputs[0][0]: 120,3125
Inputs[1][0]: 120,171875
Bid(0): 120,3125
Ask(1): 120,1875

Please, see the attached chart, at bottom there's the values of the spread indicator, with last, bid and ask prices of the spread, with other instruments like YC and YW the values shown by the indicator are right.

Which could be the problem?

Thank you
Attached Images
File Type: jpg zn-zb.JPG (109.8 KB, 10 views)
joanNT is offline  
Reply With Quote
Old 01-25-2011, 09:34 AM   #2
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

Hello JoanNT,

There are a couple items here that may explain what you are seeing.

GetCurrentAsk() and GetCurrentBid() are real time values. When called historically they will use close prices rather than historical bid / ask.

To get the most accuracy for bid/ ask data, you must work in OnMarketData() method. If you are accessing from OBU, it is only updated when there has been a trade. This can be less frequent than changes in level I data, like OnMarketData is used for.

Viewing changes in bid / ask data aligned with a bar through charting is challenging because of this. You're comparing two different thing as bid / ask can be updated much more often than trades.
NinjaTrader_RyanM is offline  
Reply With Quote
Old 01-25-2011, 09:52 AM   #3
joanNT
Senior Member
 
Join Date: Feb 2010
Posts: 128
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks RyanM

but I'm working with real data and not historical one, I've just copied the example method

protected override void OnMarketData(MarketDataEventArgs e)
{
// Print some data to the Output window
if (e.MarketDataType == MarketDataType.Last)
Print("Last = " + e.Price + " " + e.Volume);

else if (e.MarketDataType == MarketDataType.Ask)
Print("Ask = " + e.Price + " " + e.Volume);
else if (e.MarketDataType == MarketDataType.Bid)
Print("Bid = " + e.Price + " " + e.Volume);
}

and I got this results:
Bid = 120,40625 918
Ask = 120,421875 629
Last = 120,421875 20
Close[0]: 120,421875
Inputs[0][0]: 120,71875
Inputs[1][0]: 120,421875
Bid(0): 120,71875
Ask(1): 120,421875

both prices for Ask are the same and both are wrong, I've tried the same with other instruments and this don't happens
joanNT is offline  
Reply With Quote
Old 01-25-2011, 09:56 AM   #4
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

How are you determining they're wrong? Who is your data provider?
NinjaTrader_RyanM is offline  
Reply With Quote
Old 01-25-2011, 09:59 AM   #5
joanNT
Senior Member
 
Join Date: Feb 2010
Posts: 128
Thanks: 0
Thanked 0 times in 0 posts
Default

I work with IB, simply looking to their IB ask and bid data, the ones i get from NT are far from ones i get from IB
joanNT is offline  
Reply With Quote
Old 01-25-2011, 10:48 AM   #6
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

It's working OK here. I'm getting the same values in TWS for ZN.

I would make sure you're looking at the same instrument / exchange within both applications.

Are you aware of the different formatting between Ninja's output and TWS?

Ninja - Decimal
TWS - Tick
Attached Images
File Type: png IbBidAsk.png (70.8 KB, 11 views)
NinjaTrader_RyanM is offline  
Reply With Quote
Old 01-25-2011, 11:09 AM   #7
joanNT
Senior Member
 
Join Date: Feb 2010
Posts: 128
Thanks: 0
Thanked 0 times in 0 posts
Default

I don't see the same values in your attached image, this could be "the different formatting between Ninja's output and TWS", what do you mean?

is there any thread or document about this?

thanks!
joanNT is offline  
Reply With Quote
Old 01-25-2011, 11:16 AM   #8
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

You'll want to check contract specifications for more info on price formatting.
http://www.cmegroup.com/trading/inte...fications.html

Points ($1,000) and halves of 1/32 of a point. For example, 126-16 represents 126 16/32 and 126-165 represents 126 16.5/32. Par is on the basis of 100 points.

ZN 120^170 = 120.53125
NinjaTrader_RyanM is offline  
Reply With Quote
Old 01-25-2011, 11:23 AM   #9
joanNT
Senior Member
 
Join Date: Feb 2010
Posts: 128
Thanks: 0
Thanked 0 times in 0 posts
Default

Ryan Thank you very much, I didn't know about that.

Have a nice day
joanNT is offline  
Reply With Quote
Old 01-25-2011, 11:25 AM   #10
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

My pleasure, Joan. Glad we were able to get it sorted.
NinjaTrader_RyanM is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Question with GetCurrentBid() BigDog008 Strategy Development 12 10-07-2010 08:59 PM
GetCurrentAsk() returns wrong price Buthus Strategy Development 9 11-06-2009 07:33 AM
Premarket GetCurrentBid() GetCurrentAsk() TheChingachgook Indicator Development 5 06-18-2009 09:34 AM
GetCurrentBid/Ask SystemTrading Miscellaneous Support 1 08-20-2008 01:19 PM
NT hangs on GetCurrentBid/Ask? ATI user Indicator Development 5 10-09-2007 05:19 AM


All times are GMT -6. The time now is 10:54 PM.