![]() |
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
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Junior Member
Join Date: Mar 2008
Posts: 1
Thanks: 0
Thanked 0 times in 0 posts
|
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. |
|
|
|
|
|
#2 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
Please:
- install latest 6.5.0.10 - check out SampleMultiInstrument strategy
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#4 |
|
Member
Join Date: Dec 2006
Location: , ,
Posts: 79
Thanks: 0
Thanked 0 times in 0 posts
|
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)); } } |
|
|
|
|
|
#5 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
Please use TraceOrders to debug your orders as per this tip: http://www.ninjatrader-support.com/v...ead.php?t=3627
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#6 |
|
Member
Join Date: Dec 2006
Location: , ,
Posts: 79
Thanks: 0
Thanked 0 times in 0 posts
|
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='' |
|
|
|
|
|
#7 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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".
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#8 |
|
Member
Join Date: Dec 2006
Location: , ,
Posts: 79
Thanks: 0
Thanked 0 times in 0 posts
|
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 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************************");
}
}
I'm not seeing anything in the advanced order management that would explain this behavior |
|
|
|
|
|
#9 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
Josh will be looking into this and report back later.
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#10 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
Thanks for your patience and for bringing this up Futures_Shark. It is a bug which will be fixed with the next beta.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#11 |
|
Member
Join Date: Dec 2006
Location: , ,
Posts: 79
Thanks: 0
Thanked 0 times in 0 posts
|
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. |
|
|
|
|
|
#12 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
Unfortunately that is not supported.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#13 |
|
Member
Join Date: Dec 2006
Location: , ,
Posts: 79
Thanks: 0
Thanked 0 times in 0 posts
|
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.
|
|
|
|
|
|
#14 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
In terms of NinjaScript, you could not find what you want through the use of the OnMarketData() or OnMarketDepth() method?
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#15 |
|
Member
Join Date: Dec 2006
Location: , ,
Posts: 79
Thanks: 0
Thanked 0 times in 0 posts
|
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.
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |