Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Entry Order number vs. Execution Order number

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

    Entry Order number vs. Execution Order number

    In my strategy, I have this code:

    Code:
            protected override void OnExecution(IExecution execution)
            {
                 if (EntryOrder != null && EntryOrder == execution.Order)
                {
                    if (execution.Order.OrderState == OrderState.Filled)
                    { 
    [...]
    In this strategy, I have a SetStopLoss and SetProfitTarget methods setting a stop and target price for the position. So whenever the target is hit or the stop is hit, I want this code to execute. The problem is that the EntryOrder token and the execution.Order token do not match if the stoploss is hit.

    I think I got this code that checks the EntryOrder with the execution.Order from one of your samples. So how do I know that a stoploss execution is part of the original EntryOrder that was filled? Apparently I can't compare the order tokens... is there another way?

    Thanks!
    Bryan

    #2
    Bryan, how are you setting the profit targets and stop losses? There is a reference sample that shows how to do this with all IOrders.
    AustinNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Austin View Post
      Bryan, how are you setting the profit targets and stop losses? There is a reference sample that shows how to do this with all IOrders.
      Ah, yes you found it thank you. That's the indicator I copied my logic from. In the sample is this code:

      Code:
              protected override void OnExecution(IExecution execution)
              {
                  /* We advise monitoring OnExecution to trigger submission of stop/target orders instead of OnOrderUpdate() since OnExecution() is called after OnOrderUpdate()
                  which ensures your strategy has received the execution which is used for internal signal tracking. */
                  if (entryOrder != null && entryOrder.Token == execution.Order.Token)
                  {
                      if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
                      {
      I set my stoploss and targets with the SetStopLoss() and SetProfitTarget() methods. These methods produce a new order with a new token. That means that the statement

      if (entryOrder != null && entryOrder.Token == execution.Order.Token)


      will be false if the stoploss is hit before the profit target. Is there a parameter or something in these methods where I can get it to share the same token as the entry order has?

      Bryan

      Comment


        #4
        Ural01, if you have some trouble with NT strategies, maybe you can get help here from me or others. I know it can be complicated and do things you don't expect, but there is usually a reason for the issues you're having. And the reason is seldom "NT is piece of junk." ;-) I'm sure there are many people who have used NT and been very successful with good money management, as you say.

        Comment


          #5
          Ninja junk

          I,m not looking for help fom you
          i let nfa and cftc help you to count better ballance in chart and dom window and compare to the broket window ballance
          i do 80 lots every day so $20 dollars difference on every lot betwen broker price in you cost 80 x $20 = $1800 every day ? Not too match ? A
          do you split prifit with mbt 50x50 or just for you nt ?
          And how about orders that open just like boom ? I never place any orders , atm of , no pending orders how ?
          I,m trading every day 5 days week 18 hours a day from 80 to 150 lots a day , i,m member of nfa and cbot and never see thinks like you do with ballance and extra possitions open



          Originally posted by cassb View Post
          ural01, if you have some trouble with nt strategies, maybe you can get help here from me or others. I know it can be complicated and do things you don't expect, but there is usually a reason for the issues you're having. And the reason is seldom "nt is piece of junk." ;-) i'm sure there are many people who have used nt and been very successful with good money management, as you say.

          Comment


            #6
            Originally posted by ural01 View Post
            I,m not looking for help fom you
            i let nfa and cftc help you to count better ballance in chart and dom window and compare to the broket window ballance
            i do 80 lots every day so $20 dollars difference on every lot betwen broker price in you cost 80 x $20 = $1800 every day ? Not too match ? A
            do you split prifit with mbt 50x50 or just for you nt ?
            And how about orders that open just like boom ? I never place any orders , atm of , no pending orders how ?
            I,m trading every day 5 days week 18 hours a day from 80 to 150 lots a day , i,m member of nfa and cbot and never see thinks like you do with ballance and extra possitions open

            Good money management is key, and if you are saving $20 per lot, then that's good money management. It sounds like you're doing well with the system you have already, so I would say to keep using what works for you. Good luck!

            Bryan

            Comment


              #7
              Originally posted by cassb View Post
              Ah, yes you found it thank you. That's the indicator I copied my logic from. In the sample is this code:

              Code:
                      protected override void OnExecution(IExecution execution)
                      {
                          /* We advise monitoring OnExecution to trigger submission of stop/target orders instead of OnOrderUpdate() since OnExecution() is called after OnOrderUpdate()
                          which ensures your strategy has received the execution which is used for internal signal tracking. */
                          if (entryOrder != null && entryOrder.Token == execution.Order.Token)
                          {
                              if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
                              {
              I set my stoploss and targets with the SetStopLoss() and SetProfitTarget() methods. These methods produce a new order with a new token. That means that the statement

              if (entryOrder != null && entryOrder.Token == execution.Order.Token)


              will be false if the stoploss is hit before the profit target. Is there a parameter or something in these methods where I can get it to share the same token as the entry order has?

              Bryan
              To get this thread back on track, order tokens can and do change over time. Please set your stop losses and profit targets with specific exit methods, like ExitLongStop() and ExitLongLimit() and such. You can then reference the IOrder method to see which order was filled and take appropriate action.
              AustinNinjaTrader Customer Service

              Comment


                #8
                Thanks Austin, but what if I have two positions open in the same strategy? How do I know which entry a stoploss execution.order is for? If there was some variable or property I could use to tie a stoploss order to its associated entry order, that would be great. Is it maybe the fromEntrySignal parameter in the SetStopLoss method?

                If that would tie the stoploss order to the entry order, then when the execution comes in for the stoploss, how do I check to see if the fromEntrySignal matches the proper entry order?

                Bryan

                Comment


                  #9
                  Bryan, you should be able to check the Execution.Name property to see from which entry signal the execution comes in and then you can make changes to your stops / targets accordingly.

                  Comment


                    #10
                    Originally posted by NinjaTrader_Bertrand View Post
                    Bryan, you should be able to check the Execution.Name property to see from which entry signal the execution comes in and then you can make changes to your stops / targets accordingly.
                    I already do that, Bertrand, but the execution.Name property does not tell me which of several entry orders the execution came from:

                    Code:
                    if (execution.Name == "Profit target" || execution.Name == "Stop loss" || execution.Name == "Trail stop" || execution.Name == "Close" || execution.Name.Contains("cover") || execution.Name == "Sell")
                    There is an execution.Order.FromEntrySignal that I will see if it will work. The problem is creating a unique entry signal name that can later be recreated somehow. I can of course make a fixed text signal name like "My Entry", but I'd have to append some unique value to it like the bar number or date/time or something. But then later, when the stoploss is hit, given the IOrder data - how do I determine what the entry's bar number or date/time was to match up the stoploss with the proper entry?

                    Maybe I'm missing the obvious here -- it seems simple. Maybe I'm making it too complicated?

                    Comment


                      #11
                      Thanks for clarifying, I misunderstood you - you will need to work with the Exit() methods then offering native IOrder returns, those would include the FromEntrySignal property for an IOrder.

                      Comment


                        #12
                        Originally posted by NinjaTrader_Bertrand View Post
                        Thanks for clarifying, I misunderstood you - you will need to work with the Exit() methods then offering native IOrder returns, those would include the FromEntrySignal property for an IOrder.
                        Is there a sample strategy you can point me to that would handle multiple open orders and executions, linking the stop and target executions to their original entry order? I would like to see how this would be done.

                        Thanks!
                        Bryan

                        Comment


                          #13
                          in case of multiple orders just create a list (of orders). you can directly compare the orders from the list. from the help files
                          To check for equality you can compare IOrder objects directly
                          like
                          Code:
                          List<IOrder> list = new List<IOrder>();
                          OnExecution
                          Code:
                          if (list.Contains(execution.Order))
                          {
                            //do something
                          }

                          this is really a very powerful feature.

                          as Bertrand said its always a good idea to give the name property a unique value, like

                          "Buy" + count.ToString(); //count is an integer

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          648 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          369 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
                          573 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          575 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X