NinjaTrader Support Forum  

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

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 07-08-2012, 05:02 PM   #1
curmudgeon
Junior Member
 
Join Date: Sep 2011
Posts: 11
Thanks: 4
Thanked 0 times in 0 posts
Default problem with getcurrentbid / getcurrentask

hi,

I'm having a problem with a script that is intended to select one of multiple instruments. I have a loop as below, that is intended to ensure only executing a trade when the spread is beneath a threshold. I understood that getcurrentbid and getcurrentask are overloaded such that if I put in i as a parameter it would get the bid and ask of the instrument that corresponds with the bar series i.

When I run the loop below and examine the output, I find that irrespective of whether it's bar 1 or 2 (two futures of same instrument, different maturity), it will display the spread of the near future.

Could you please assist ?

for (i=1; i<Instruments.Length; i++)
{
Bid = GetCurrentBid(i);Ask = GetCurrentAsk(i);
if(Bid > 0 && Ask > 0 &&
GetCurrentBidVolume(i) > 0 &&
GetCurrentAskVolume(i) > 0)
if(Ask/Bid < ( 1.0+maxSpreadTrade)) okToTradeInst[i]=true;
else okToTradeInst[i]=false;
else okToTradeInst[i]=false;
Print(now+" bar "+i+" ask="+Ask+" bid="+Bid+" ok is "+okToTradeInst[i]);
}
curmudgeon is offline  
Reply With Quote
Old 07-09-2012, 07:30 AM   #2
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

curmudgeon,

What instruments are you using here along with their expiries?

Using this example, we are getting different prices.
Attached Files
File Type: cs DebugIndicator.cs (7.1 KB, 3 views)
Last edited by NinjaTrader_AdamP; 07-09-2012 at 07:53 AM.
NinjaTrader_AdamP is offline  
Reply With Quote
Old 07-09-2012, 02:01 PM   #3
curmudgeon
Junior Member
 
Join Date: Sep 2011
Posts: 11
Thanks: 4
Thanked 0 times in 0 posts
Default

Hello, I'm not sure if it matters, but this is running as a strategy and not as an indicator.

Bar0 is $AUDUSD
Bar1 is M6A 12-12 <== there should be no quote on this guy right now according to the market analyzer
Bar2 is M6A 09-12

It's connecting to Interactive Brokers. It's intended to help me deal with roll dates better (and since we're far from the next roll date the logic is to do this check and then not look at the far instrument).

Thanks
curmudgeon is offline  
Reply With Quote
Old 07-09-2012, 02:23 PM   #4
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

Curmudgeon,

This may have something to do with the non-liquid nature. Here is an output I got from Kinetick using M6A using that reference sample I sent you :

Instruments length : 3
M6A 09-12 BID : 1.0142
M6A 12-12 BID : 1.0143
Instruments length : 3
M6A 09-12 BID : 1.0142
M6A 12-12 BID : 1.0143
Instruments length : 3
M6A 09-12 BID : 1.0142
M6A 12-12 BID : 1.0143

This was after about a minute. Please try running my test script again and let me know if it works on your end, or if you notice the same behavior.
Attached Files
File Type: cs DebugIndicator.cs (7.1 KB, 2 views)
Last edited by NinjaTrader_AdamP; 07-09-2012 at 02:31 PM.
NinjaTrader_AdamP is offline  
Reply With Quote
Old 07-09-2012, 02:38 PM   #5
curmudgeon
Junior Member
 
Join Date: Sep 2011
Posts: 11
Thanks: 4
Thanked 0 times in 0 posts
Default

hi, Adam

yes, that's consistent with my run. if you look at the liquid big futures (6A) then the Dec is almost a cent less than the Sep one , which makes the AUD futures contract a good test case. It shows you're actually getting the mini September contract quotes when you query the mini December one

I would have thought the checking of the bid and ask volumes would have also warned me that there's effectively no quote, but that seems to give me the ones for the more liquid contract...

Is there another trick to use ? I want to be trading out of the near one into the far one when certain conditions are met with regards to the bid and ask, but it would only make sense if I have the right bids and asks !
curmudgeon is offline  
Reply With Quote
Old 07-09-2012, 02:59 PM   #6
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

Curmudgeon,

I am not sure if I understand. Right now I was using BID prices only. Are you saying because the bid price is close it shows we are getting the September quotes when we query December or is it because its 1 greater than the September query?

Here is some more output after I waited a bit longer :

Instruments length : 3
M6A 09-12 BID : 1.0141
M6A 12-12 BID : 1.0144
Instruments length : 3
M6A 09-12 BID : 1.0141
M6A 12-12 BID : 1.0144
NinjaTrader_AdamP is offline  
Reply With Quote
Old 07-09-2012, 03:13 PM   #7
curmudgeon
Junior Member
 
Join Date: Sep 2011
Posts: 11
Thanks: 4
Thanked 0 times in 0 posts
Default

I think the fact that the Sep and Dec quotes are close are strongly indicative that you are getting the September quotes. I think you should be getting no quote whatsoever for the December contract at this time on the mini (M6A) contract.

If you got right quotes for M6A it should be quite close to the big (6A) contract, i.e. with a gap between Sep and Dec. 6A is equivalent to ten M6A but is much more liquid.

Recent bids: 1.0142 for the 6A Sep , 1.0141 for the M6A Sep, 1.0064 for 6A Dec - whether I use the script or look at it in the Market Analyzer.

The problem comes from the M6A Dec which shows no current quote on the Market Analyzer but shows the Sep M6A quote in the script [I know it's not $AUDUSD because that one is above 1.02 at the same time]

I'm using this futures contract as a test case because it's badly behaved and want to make sure my script is robust.
Last edited by curmudgeon; 07-09-2012 at 03:16 PM.
curmudgeon is offline  
Reply With Quote
Old 07-10-2012, 09:40 AM   #8
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

Curmudgeon,

If I do this :

if(BarsInProgress == 0)
{
Print ("Instruments length : "+Instruments.Length);
Print ( "M6A 09-12 BID : " + GetCurrentBid(1));
Print ( "M6A 12-12 BID : " + GetCurrentBid(2));
}

Its guaranteed to only call GetCurrentBid(1) and GetCurrentBid(2) at the exact same time.

Here is the output from doing so with the DebugIndicator I attached earlier.

Instruments length : 3
M6A 09-12 BID : 1.0142
M6A 12-12 BID : 1.0143

So one instrument is 1 tick higher on its bid than the other, and since they were called at the exact same time they must be different prices. I am also not getting a quote on the MarketAnalyzer for M6A 12-12.

GetCurrentBid() will return the last reported Bid for the instrument you are requesting it for. There is no crossover between bid/ask/last with two separate instruments.
NinjaTrader_AdamP is offline  
Reply With Quote
Old 07-10-2012, 01:21 PM   #9
curmudgeon
Junior Member
 
Join Date: Sep 2011
Posts: 11
Thanks: 4
Thanked 0 times in 0 posts
Default

hi Adam,

I think I understand now

GetCurrentBid(1) will get the most recent bid that hit the exchange on that instrument, irrespective of whether that was recent or whether that bid is no longer effective and not replaced by a new bid price. Is that correct ?

Is there a command that would either show me only the bid that is on exchange right now and return 0 or something when there isn't one ? Or can I filter using another field to ensure that the quote was still live (barring system delay)

Thank you
Last edited by curmudgeon; 07-10-2012 at 01:53 PM.
curmudgeon is offline  
Reply With Quote
Old 07-10-2012, 01:48 PM   #10
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

Hello,

Yes, you are correct. This was how it was explained to me by our Tech lead.

I am not aware of any such function unfortunately. You could maybe add a Bid/Ask tick dataseries in a multi-series indicator and compare. if your data provider supports it.

You could also use OnMarketData() to get Level1 pricing information, and if the Bid/Ask didn't occur in the last X time frame then you could have your code set to 0.

http://www.ninjatrader.com/support/h...marketdata.htm
NinjaTrader_AdamP is offline  
Reply With Quote
The following user says thank you to NinjaTrader_AdamP for this post:
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
Getting wrong GetCurrentBid and GetCurrentAsk data guillembm Miscellaneous Support 6 09-09-2011 06:48 AM
GetCurrentBid()/GetCurrentAsk() in OnMarketData heech Strategy Development 1 09-02-2011 11:32 AM
GetCurrentBID and GetCurrentASK gives wrong data joanNT Indicator Development 9 01-25-2011 11:25 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


All times are GMT -6. The time now is 03:13 PM.