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

Matching multiple unmanaged entry orders with their corresponding exit orders

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

    Matching multiple unmanaged entry orders with their corresponding exit orders

    I have a strategy that may create more than one entry order at a time. When an entry order fills... how can I create exit orders that are related to that particular entry order. The reason is that I would like the profit and loss lines (and statistics) to reflect each position appropriately.

    #2
    Hello BrianARice,

    This would need to be done with logic when using the unmanaged approach.

    Orders are first in first out.

    To provide an idea, your logic could track if an <order>.Name has filled in an entry and set a value to a variable to know this order makes up some of the position. Then you could check that variable to see that value and place an exit order and then remove that value from the variable.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Right... but there is no way to get the profit and loss lines to match up with the proper entry and exit orders on a chart then?

      Comment


        #4
        Hello BrianARice,

        You would need to draw the lines yourself.. but could achieved.

        NinjaTrader's strategy profit lines will be first in first out, but you can draw lines how you would like.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi, are there any update in this topic? Is there a way to close the order we need in an unmanaged method? Also, Can you please tell me, I found a method in StrategyBase class

          [MethodImpl( MethodImplOptions.NoInlining )
          private Order SubmitOrderNow( int selectedBarsInProgress, bool isLiveUntilCancelled, OrderAction orderAction, OrderType orderType, int quantity, double limitPrice, double stopPrice, string signalName, string fromEntrySignal, string oco, bool isSimulatedStop )
          {
          return null;
          }

          This looks like what I'm looking for, this method has a string argument fromEntrySignal that would help me close the open position I want.
          Last edited by AdvancedSoftwareFeatures; 04-01-2023, 03:36 AM.

          Comment


            #6
            Originally posted by BrianARice View Post
            I have a strategy that may create more than one entry order at a time. When an entry order fills... how can I create exit orders that are related to that particular entry order. The reason is that I would like the profit and loss lines (and statistics) to reflect each position appropriately.
            When using SubmitUnmanagedOrder, doesn't the 'signalName' parameter help you with this?

            For entry orders, I use a simple naming scheme. I typically use names that start with a prefix
            of 'L' or 'S' (to indicate a Long or Short) followed by a counter, such as CurrentBar.

            For example,

            L3267 <-- Long entry order at bar 3267

            When the entry order fills, I submit matching exit orders (aka, the stop loss and profit target orders)
            using the entry order's signalName, but add a suffix, like this,

            L3267stp <-- stop loss order
            L3267tgt <-- profit target order


            If the entry order had Quantity > 1, then the strategy might submit multiple profit target orders, in
            which case I numbered them,

            L3267stp <-- stop loss order (always the same)
            L3267tg1 <-- 1st profit target
            L3267tg2 <-- 2nd profit target
            ...
            L3267tg6 <-- 6th profit target (as needed)


            The strategy should create the exit orders inside OnOrderUpdate or OnExecutionUpfdate, when
            the entry order L3267 state has changed to Filled (or PartFilled).

            Is this kind of naming convention what you're talking about?
            Last edited by bltdavid; 04-01-2023, 07:27 PM.

            Comment


              #7
              Originally posted by AdvancedSoftwareFeatures View Post
              Hi, are there any update in this topic? Is there a way to close the order we need in an unmanaged method? Also, Can you please tell me, I found a method in StrategyBase class

              [MethodImpl( MethodImplOptions.NoInlining )
              private Order SubmitOrderNow( int selectedBarsInProgress, bool isLiveUntilCancelled, OrderAction orderAction, OrderType orderType, int quantity, double limitPrice, double stopPrice, string signalName, string fromEntrySignal, string oco, bool isSimulatedStop )
              {
              return null;
              }

              This looks like what I'm looking for, this method has a string argument fromEntrySignal that would help me close the open position I want.
              For me this question is still open, the main purpose of my question, it is to close the selective positions if I opened a grid of orders in one direction, how can I solve such a question, for example I opened 10 long orders which have been executed and after some time I need to close for example 10.9.8 and 1,2. Now the positions are closed by the principle first in first out.That is, when I close 5 positions, then close 1,2,3,4,5.

              Comment


                #8
                Hello bltdavid,

                There is no fromEntrySignal when using the unmanaged approach. In the managed approach, using the fromEntrySignal in an exit will attach the exit order to the signalName of a specific entry order. This will be use used for the pairing of the orders in the performance window. The unmanaged approach does not have this ability to attach exits to specific entries. The matching in the performance window will be purely first in first out. This means the developer would have to make their own report that matches these differently based on signal names and not based on first in first out.


                AdvancedSoftwareFeatures,

                You can assign orders to variables in OnOrderUpdate() and know which orders are still working and which orders have filled and add up the quantities. When an entry order fills, you can submit a specific exit order with the quantity of that entry.

                You also have access the Position.MarketPosition and Position.Quantity, which update when the position changes in OnPositionUpdate().
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_ChelseaB View Post
                  Hello bltdavid,

                  There is no fromEntrySignal when using the unmanaged approach. In the managed approach, using the fromEntrySignal in an exit will attach the exit order to the signalName of a specific entry order. This will be use used for the pairing of the orders in the performance window. The unmanaged approach does not have this ability to attach exits to specific entries. The matching in the performance window will be purely first in first out. This means the developer would have to make their own report that matches these differently based on signal names and not based on first in first out.


                  AdvancedSoftwareFeatures,

                  You can assign orders to variables in OnOrderUpdate() and know which orders are still working and which orders have filled and add up the quantities. When an entry order fills, you can submit a specific exit order with the quantity of that entry.

                  You also have access the Position.MarketPosition and Position.Quantity, which update when the position changes in OnPositionUpdate().
                  Thank you so much for the tip.

                  Comment


                    #10
                    AdvancedSoftwareFeatures The SubmitOrderUnmanaged() method allows specification of a signalName ("A string representing the name of the order. Max 50 characters.​").

                    By tracking individual Orders as recommended by NinjaTrader_ChelseaB with signal names, and using a naming convention for your Orders that allows you to distinguish each one and know it as an entry or exit Order, you should be able to manage this quite well.

                    Thanks.
                    Multi-Dimensional Managed Trading
                    jeronymite
                    NinjaTrader Ecosystem Vendor - Mizpah Software

                    Comment


                      #11
                      Originally posted by jeronymite View Post
                      AdvancedSoftwareFeatures The SubmitOrderUnmanaged() method allows specification of a signalName ("A string representing the name of the order. Max 50 characters.​").

                      By tracking individual Orders as recommended by NinjaTrader_ChelseaB with signal names, and using a naming convention for your Orders that allows you to distinguish each one and know it as an entry or exit Order, you should be able to manage this quite well.

                      Thanks.
                      Thanks for the tip, but I don't have a problem with order management if I may say so, for my task I don't fit the principle of closing orders first in first out. Otherwise everything is great, thanks.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by DanielTynera, Today, 01:14 AM
                      0 responses
                      2 views
                      0 likes
                      Last Post DanielTynera  
                      Started by yertle, 04-18-2024, 08:38 AM
                      9 responses
                      40 views
                      0 likes
                      Last Post yertle
                      by yertle
                       
                      Started by techgetgame, Yesterday, 11:42 PM
                      0 responses
                      10 views
                      0 likes
                      Last Post techgetgame  
                      Started by sephichapdson, Yesterday, 11:36 PM
                      0 responses
                      2 views
                      0 likes
                      Last Post sephichapdson  
                      Started by bortz, 11-06-2023, 08:04 AM
                      47 responses
                      1,615 views
                      0 likes
                      Last Post aligator  
                      Working...
                      X