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 > Strategy Development

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

Reply
 
Thread Tools Display Modes
Old 03-07-2008, 04:37 PM   #1
yot1120
Junior Member
 
Join Date: Mar 2008
Posts: 1
Thanks: 0
Thanked 0 times in 0 posts
Smile Multi-instrument Strategy - Order Entry problem

Hi,

I'm developing and testing a multi-instrument automated strategy using Ninjascript. I've read the Help Guide, and made a couple of changes in my code.

My strategy is trading on real-time incoming tick data, therefore I add "CalculateOnBarClose = false;" to the Initialize() method.

Also I add the following to the very beginning of OnBarUpdate() method:
"if (Historical) return;" to make sure only real-time data will be checked.

The problem I have is that it seems all orders entered submitted in OnBarUpdate() method are submitted to the instrument referred by BarsInProgress context.

For example, my primary instrument is AAPL(BarsInProgress==0), my secondary instrument is MSFT(BarsInProgress==1).

My strategy is a real-time hedging strategy, e.g. the trading logic is based on AAPL real-time tick data, when the conditions match on AAPL most recent traded price, I'd like to LONG/SHORT MSFT using market or limit order. However I found that there is no way I can do this, since my trading logic is evaluated under the context of AAPL(BarsInProgress==0), EnterLong(), EnterLongLimit(), or even using ATM strategy will enter the order to AAPL, not MSFT!

Is there any solution to my problem?

Thanks.
yot1120 is offline  
Reply With Quote
Old 03-07-2008, 10:25 PM   #2
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

Please:
- install latest 6.5.0.10
- check out SampleMultiInstrument strategy
NinjaTrader_Dierk is offline  
Reply With Quote
Old 03-07-2008, 10:27 PM   #3
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

In NT6.5 we have added override methods that allow you to define which barsInProgress you want to submit to. As Dierk stated, please install the latest NT6.5. Check out the help guide for EnterLongLimit() for an example.
NinjaTrader_Josh is offline  
Reply With Quote
Old 03-08-2008, 10:06 PM   #4
Futures_Shark
Member
 
Join Date: Dec 2006
Location: , ,
Posts: 79
Thanks: 0
Thanked 0 times in 0 posts
Default

I'm using the following code from within a simple strategy in an attempt to manage orders in two different contracts from a single strategy. I'm working on 6.5. the strategy only submits one order yet both print statements show up in the output window and there is no order error mesasages in the log.

protected override void OnBarUpdate()
{
if (BarsInProgress == 0)
{

EnterLongLimit(1,true,1,GetCurrentBid(0)+7.5, "SPRD");
Print("BUY ZB: " + (GetCurrentBid(0)+7.5));

}

if (BarsInProgress == 1)
{

EnterShortLimit(0,true,1,GetCurrentAsk(1)-7.5, "SPRD");
Print("SELL ZN:" + (GetCurrentAsk(1)-7.5));

}
}
Futures_Shark is offline  
Reply With Quote
Old 03-09-2008, 01:31 AM   #5
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

Please use TraceOrders to debug your orders as per this tip: http://www.ninjatrader-support.com/v...ead.php?t=3627
NinjaTrader_Josh is offline  
Reply With Quote
Old 03-11-2008, 08:38 PM   #6
Futures_Shark
Member
 
Join Date: Dec 2006
Location: , ,
Posts: 79
Thanks: 0
Thanked 0 times in 0 posts
Default

Trace order produces this message but no order sent

3/11/2008 10:33:27 PM Entered internal PlaceOrder() method at 3/11/2008 10:33:27 PM: Action=SellShort OrderType=Limit Quantity=1 LimitPrice=117'080 StopPrice=0 SignalName='SPRD' FromEntrySignal=''
Futures_Shark is offline  
Reply With Quote
Old 03-12-2008, 12:15 AM   #7
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

You have likely hit one of the internal order handling rules. You can review the help article on it in your NT6.5 help guide. Search for "internal order handling rules".
NinjaTrader_Josh is offline  
Reply With Quote
Old 03-12-2008, 08:51 PM   #8
Futures_Shark
Member
 
Join Date: Dec 2006
Location: , ,
Posts: 79
Thanks: 0
Thanked 0 times in 0 posts
Default

OK, so in an attempt to remedy this multi instrument strategy problem I moved the second order to On Order Update method.
Here are the order results
Code:
ZN 06-08	SellShort	Limit	1	117'230	0	Filled	1	117.71875	0	SPRD2		Gtc		Sim101	Simulated Data Feed	198a61faa5354701842c2df8fbcd1018	NOB_ZB	198a61faa5354701842c2df8fbcd1018	3/12/2008 22:31	+	-	X
ZB 06-08	Sell	Limit	1	117'230	0	Filled	1	119.625	0	Close position		Gtc		Sim101	Simulated Data Feed	dc9f16e0ed3f45eb9080e7aa66f91dcc	NOB_ZB	dc9f16e0ed3f45eb9080e7aa66f91dcc	3/12/2008 22:31	+	-	X
ZB 06-08	Buy	Limit	1	119'205	0	Filled	1	119.640625	0	SPRD		Gtc		Sim101	Simulated Data Feed	7b7148c0b6d64b9790a33a0bcb803b76	NOB_ZB	7b7148c0b6d64b9790a33a0bcb803b76	3/12/2008 22:31	+	-	X
and here is the new code

Code:
protected override void OnBarUpdate()
{
   if (Historical)
	return;
		
   if (BarsInProgress == 1)
     {
	 if (ZBWrk ==false)
	   {
		ZBOrder =EnterLongLimit(0,true,1,GetCurrentBid(1)+1.75+ctr, "SPRD");
	        Print("BUY ZB: " + (GetCurrentBid(1)+1.75+ctr));
	        ctr = ctr + 0.015625;
	        Print("SPRD$: "+ctr);
	    }
	}
 }
		
protected override void OnOrderUpdate(IOrder order) 
{
	if (order.OrderState == OrderState.PartFilled ||order.OrderState == OrderState.Filled  )
	{
		ZBWrk = true;
		Print("***********************FILL************************");
		Print("QTY:"+order.Quantity.ToString());
		ZNOrder =EnterShortLimit(1,true,order.Quantity,GetCurrentBid(1), "SPRD2");
		Print("SELL ZN:" + (GetCurrentBid(1)));			Print("***********************FILL************************");
	}
}
SO it is working except for the "close position" order flattening the original position. This strategy was aplied to a ZB Chart. After it bought ZB it sold ZB with an order named Close position before selling the ZN order in the OnOrderUpdate method.

I'm not seeing anything in the advanced order management that would explain this behavior
Futures_Shark is offline  
Reply With Quote
Old 03-13-2008, 06:49 AM   #9
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

Josh will be looking into this and report back later.
NinjaTrader_Ray is offline  
Reply With Quote
Old 03-14-2008, 01:51 AM   #10
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

Thanks for your patience and for bringing this up Futures_Shark. It is a bug which will be fixed with the next beta.
NinjaTrader_Josh is offline  
Reply With Quote
Old 03-16-2008, 03:36 PM   #11
Futures_Shark
Member
 
Join Date: Dec 2006
Location: , ,
Posts: 79
Thanks: 0
Thanked 0 times in 0 posts
Default

Would it be possible to get some information on accessing marketdata events from an external application? That would allow a clean work around until the bug is fixed.

I have an application built to trade this strategy but without access to the MarketDataItem event I have to use a timer to update the market prices.
Futures_Shark is offline  
Reply With Quote
Old 03-16-2008, 05:16 PM   #12
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

Unfortunately that is not supported.
NinjaTrader_Josh is offline  
Reply With Quote
Old 03-16-2008, 09:30 PM   #13
Futures_Shark
Member
 
Join Date: Dec 2006
Location: , ,
Posts: 79
Thanks: 0
Thanked 0 times in 0 posts
Default

I know it's possible through the Ninjatrader.core.dll from information in other posts. If I use that DLL to code my application can I also use the Ninjatrader.Client.dll in the same application? I understand that the core.dll is not documented except for what is available though Visual Studio
Last edited by Futures_Shark; 03-16-2008 at 09:33 PM.
Futures_Shark is offline  
Reply With Quote
Old 03-16-2008, 09:34 PM   #14
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

In terms of NinjaScript, you could not find what you want through the use of the OnMarketData() or OnMarketDepth() method?
NinjaTrader_Josh is offline  
Reply With Quote
Old 03-23-2008, 06:26 PM   #15
Futures_Shark
Member
 
Join Date: Dec 2006
Location: , ,
Posts: 79
Thanks: 0
Thanked 0 times in 0 posts
Default

I tried using both OnOrderUpdate and OnBarUpdate to submit the second order in the spread strategy and neither worked. Do you have any reason to believe that OnMarketData() or OnMarketDepth() methods would work differently.
Futures_Shark 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
Multi-instrument Strategy dgregor5 Strategy Development 6 06-29-2010 04:47 AM
Multi-Instrument help Json General Programming 11 04-22-2008 10:42 AM
Multi Time Frame/Multi Instrument? GreenTrade Strategy Development 3 01-14-2008 02:24 PM
Order Entry Problem Mike Winfrey Strategy Development 7 12-09-2007 06:31 PM
Use of Order Entry APIs in multi-instrument environment lclifner General Programming 2 10-11-2007 05:58 PM


All times are GMT -6. The time now is 07:16 AM.