Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Best practice for multiple instrument order entries

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

    Best practice for multiple instrument order entries

    Hi,

    I have a pairs trading strategy that goes long one instrument and simultaneously shorts a different instrument. I tried to find a best practice for where best to place the second entry on the forum, but couldn't.

    I ideally want to make sure that the first order is filled before placing the second order (they will be market orders), so I tried putting the second EnterLong() in onExecutionUpdate(), when the relevant fromEntrySignal from the first entry is seen:

    Code:
    if (execution.Order != null && execution.Order.OrderState == OrderState.Filled)
    		 	{
    			  	// Initial Entry
    				if(execution.Order.FromEntrySignal == "LongSpread")
    				{
    					Print("EnterShort at: "+execution.Time.ToLocalTime());
    					EnterShort(0,DefaultQuantity,entryName+"Short");
    				}
    But these second orders are never triggered for some reason.

    Any help appreciated!

    #2
    Hello ours_solaire,

    I put together a sample which submits an order to buy the instrument the strategy is applied to, and within OnExecutionUpdate checks that that order is filled and then submits a market order to sell the secondary series of the strategy which is set to NQ 09-17.

    Please see attached and let us know if you need further assistance.
    Attached Files
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Thanks Alan. It seems to work, although I'm still not quite sure why my code didn't work..

      If I want to make sure the order was completely filled, I guess I need to add another check in there too?

      Comment


        #4
        Hello,

        By completely filled are you referring to the whole order quantity? Like 100 out of 100 silver futures contracts rather than 80 out of 100?

        I look forward to your reply.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Yes that's correct (not that I intend on trading 100 futures contracts anytime soon though!) it's more a question of thoroughness...

          Thanks

          Comment


            #6
            Hello ours_solaire,

            I modified the sample to check that the order is in OrderState.Filled, within OnOrderUpdate, before submitting the sell order to the Nasdaq Sept Contract.

            Please let us know if you need further assistance.
            Attached Files
            Alan P.NinjaTrader Customer Service

            Comment


              #7
              Hello Alan
              I cannot figure out how one can get the execution of the order on the secondary series, once an order on the primary has been executed. As an example I have enabled your sample strategy on the ES and the NQ, then I have set a limit buy order on the primary series ES, however when this order was executed I did not see any short order on the secondary series NQ.
              Please can you show how I should apply your sample in order to have the two orders on the ES and NQ triggered and executed as described above?
              Could you perhaps also show whether it would be possible to set a limit Long order not only on the primary (ES) series, but directly on the (chart of the) spread between the primary and the secondary, (ES – NQ, ie .: the green line on central panel of the attached image) and then have your sample triggering a Long@market on the primary (ES) and, immediately after this Long on the ES is executed, having a Short@market on the secondary NQ.
              Can all this be handled by the Strategy Builder of NT8?
              Thanks.
              Attached Files
              Last edited by guidoisot; 02-05-2018, 05:31 AM.

              Comment


                #8
                Hello guidoisot,

                I updated the strategy as the data series for the NQ was using Sept 17 expiration.
                When you apply the strategy, once an ES trade is filled it will submit a market order to the NQ 03-18.

                Where you are running the strategy in the strategies tab, you will see an arrow to the left of the symbol name, you could click this drop down and it will show you the other series in the strategy. Click the arrow to expand it, and it will show you the short position in the NQ.

                Regarding having the trade plotted on the spread panel, this would be possible. You would want to take the two fill prices, subtract the two to come up with the spread price, then could have this saved to a file or to a static variable, and another separate indicator applied to that spread chart which pulls this spread price and then could plot it on that graph. This would be beyond the ability of the strategy builder and would require custom coding.

                I added to the strategy 2 variables, Leg1 and Leg2, which are netted and passed to a static variable in an Addon called SpreadVariablePrice. I wrote a new indicator called PlotSpreadPriceOfSpreadBuyEsTheninOnPosition… which plots this variable below the chart. I have attached the Strategy, Addon, and Indicator. This is a basic framework for how you’d do what you’re looking to do, except you’d be drawing an arrow rather than a plot.

                If you’d like, I can have someone reach out with a list of third parties that would be interested tying this all together to do exactly as you’d like.

                Please let us know if you need further assistance.
                Attached Files
                Alan P.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Kaledus, Today, 01:29 PM
                2 responses
                7 views
                0 likes
                Last Post Kaledus
                by Kaledus
                 
                Started by frankthearm, Yesterday, 09:08 AM
                13 responses
                45 views
                0 likes
                Last Post frankthearm  
                Started by PaulMohn, Today, 12:36 PM
                2 responses
                16 views
                0 likes
                Last Post PaulMohn  
                Started by Conceptzx, 10-11-2022, 06:38 AM
                2 responses
                55 views
                0 likes
                Last Post PhillT
                by PhillT
                 
                Started by yertle, Yesterday, 08:38 AM
                8 responses
                37 views
                0 likes
                Last Post ryjoga
                by ryjoga
                 
                Working...
                X