Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi-instrument Strategy - Order Entry problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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.

    #2
    Please:
    - install latest 6.5.0.10
    - check out SampleMultiInstrument strategy

    Comment


      #3
      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 P.NinjaTrader Customer Service

      Comment


        #4
        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));

        }
        }

        Comment


          #5
          Please use TraceOrders to debug your orders as per this tip: http://www.ninjatrader-support.com/v...ead.php?t=3627
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            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=''

            Comment


              #7
              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 P.NinjaTrader Customer Service

              Comment


                #8
                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

                Comment


                  #9
                  Josh will be looking into this and report back later.
                  RayNinjaTrader Customer Service

                  Comment


                    #10
                    Thanks for your patience and for bringing this up Futures_Shark. It is a bug which will be fixed with the next beta.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      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.

                      Comment


                        #12
                        Unfortunately that is not supported.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          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, 09:33 PM.

                          Comment


                            #14
                            In terms of NinjaScript, you could not find what you want through the use of the OnMarketData() or OnMarketDepth() method?
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #15
                              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.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              650 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              370 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              109 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              574 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              577 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X