Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

strategy with 2 symbols: order questions

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

    strategy with 2 symbols: order questions

    Hi,

    I am writing a strategy that uses two symbols (both on 1-min bar charts), but only trades the main symbol (BarsInProgress == 0). CalculateOnBarClose is set to TRUE!

    My questions are:
    1) Since it can happen that the main symbol doesn't have a tick for a while or even misses a full bar I want to send entry/exit orders based on completed bars from BOTH symbols. In the OnBarUpdate() method I would place an order like:
    MyEntryOrder = EnterLongLimit(0, false, MyUnits, MyEntryPrice, "Limit_Entry_L");

    Is this correct so that even if the secondary symbol called the OnBarUpdate() method (BarsInProgress == 1) this order:
    - would be placed (sent to broker)
    - and also refer to my main symbol?

    2) To my knowledge I need to resend that order to keep it alive, right? On what events am I required to resend? For example:
    - OnBarUpdate() of ANY symbol
    - OnBarUpdate(), but only for the symbol that the order trades (here when BarsInProgress == 0)
    - any other events like OnExcecution(), ...

    3) This is a limit order that may only be partially filled for a while. If I resend the order do I need to take into account the amount that has already been filled or can I keep resending the original order without changing the number of shares (stored in "MyUnits")? Whatever the answers is: does it also apply to resending EXIT orders?

    4) Is it possible to put the text of the signal into a string variable? Example:
    Code:
    string MyEntryName = "Limit_Entry_L";
    MyEntryOrder = EnterLongLimit(0, false, MyUnits, MyEntryPrice, MyEntryName);
    The reason I am asking is that TradeStation doesn't allow to use a variable to make sure the same order doesn't show up at several places in the code.

    Thanks a lot,
    NutFlush

    #2
    Hi NutFlush,

    1. Correct BIP == 1 indicates second instrument updating, you send the orders then to the primary series.
    2. Correct, per default the order expires on the next OnBarUpdate(), either set it to liveUntilCancelled and CancelOrder() then or resend if unfilled and entry still valid. You resend when you want to resend it from an event perspective, OnExecution() would only be called if you see an incoming execution...
    3. I would generally suggest working with the IOrder objects, giving you access to the .Filled property for your order exactly, then upon resending you know how much qty you would need to complete the partial previous fill to reach your final desired qty - http://www.ninjatrader.com/support/h...ightsub=IOrder
    4. Yes, using a variable is possible.

    Comment


      #3
      Originally posted by NinjaTrader_Bertrand View Post
      2. Correct, per default the order expires on the next OnBarUpdate(), either set it to liveUntilCancelled and CancelOrder() then or resend if unfilled and entry still valid. You resend when you want to resend it from an event perspective, OnExecution() would only be called if you see an incoming execution...
      3. I would generally suggest working with the IOrder objects, giving you access to the .Filled property for your order exactly, then upon resending you know how much qty you would need to complete the partial previous fill to reach your final desired qty - http://www.ninjatrader.com/support/h...ightsub=IOrder
      Hi Bertrand,

      thanks for your answers, but I need to clarify those 2 points:

      to 2. If I choose to resend the order will I need to do that on ANY call of the OnBarUpdate() or only when the symbol that the order trades calls OnBarUpdate()?

      to 3. Do you mean I have to recalculate the number of shares before I resend the order? I was hoping to simply resend the initial quantity until the order was completely filled to avoid any timing issues. Since my order sits at the broker with the initial quantity NT doesn't need to do anything. So why should my strategy recalculate the number of shares when my order ticket (as the broker has it) doesn't required to be changed?

      Thanks,
      NutFlush

      Comment


        #4
        Hello NutFlush,

        Thank you for your response.

        2. You can re-send the order on either BarsInProgress as the order is being submitted to BIP index 0 you can re-submit on BIP 1 or BIP 2.

        3. Resubmitting the order with the same quantity as the original order means you are now submitting that quantity regardless of what filled. So let's say 2 of the 4 quantity was filled, you then resubmit with 4 and you now have 4 quantity to fill again not 2 as it should be. Using IOrder objects to re-calculate the quantity means once you receive an update that the execution was partially filled you can then adjust the quantity for the order properly to compensate for the partial fill.
        The partial fill will be reported by your broker to NinjaTrader, so this plays a factor in your re-submission and recalculation of the quantity.

        Please let me know if you have any further questions.

        Comment


          #5
          Originally posted by NinjaTrader_PatrickH View Post
          3. Resubmitting the order with the same quantity as the original order means you are now submitting that quantity regardless of what filled. So let's say 2 of the 4 quantity was filled, you then resubmit with 4 and you now have 4 quantity to fill again not 2 as it should be. Using IOrder objects to re-calculate the quantity means once you receive an update that the execution was partially filled you can then adjust the quantity for the order properly to compensate for the partial fill.
          The partial fill will be reported by your broker to NinjaTrader, so this plays a factor in your re-submission and recalculation of the quantity.
          Hi Patrick,

          sorry, but I still have some questions how updating orders works.

          Let's assume I send an exit order like this:
          Code:
          private IOrder myExitOrder = null;
          private int myShares = 1000;
          private double myTarget = 123.45;
          protected override void OnBarUpdate()
          {
               // Submit the original exit order
               if (myExitOrder == null)
               {
                    myExitOrder = ExitLongLimit(0, [COLOR=Red][B]true[/B][/COLOR], myShares, myTarget, "Long Exit", "Long Entry");
              }
          }
          After sending the order myExitOrder holds the IOrder object that reflects my order. Let's assume I got partially filled and 300 shares were sold. I understand that I can retrieve this information by using the OnExecution() method.

          But how do I change the order to reflect a new target price (and the new number of shares)?
          a) Do I access the order through the IOrder object to make any changes (how?)?
          b) Or do I issue a new order like this:
          Code:
               // Change the parameters for the existing original exit order
               if (myExitOrder != null)
               {
                      myTarget = myTarget - 0.25;
                      myShares = myShares - 300;
                      myExitOrder = ExitLongLimit(0, [COLOR=Red][B]true[/B][/COLOR], myShares, myTarget, "Long Exit", "Long Entry");
               }
          Wouldn't that give me a new IOrder object so that I would lose the object from the initial exit order?

          Thanks,
          NutFlush

          Comment


            #6
            Hello NutFlush,

            Thank you for your response.

            If you are using the liveUntilCancelled bool set to True the order is going to stay active until completely filled. There would be no need to re-submit unless your strategy dictates a new quantity is necessary.

            Comment


              #7
              Originally posted by NinjaTrader_PatrickH View Post
              If you are using the liveUntilCancelled bool set to True the order is going to stay active until completely filled. There would be no need to re-submit unless your strategy dictates a new quantity is necessary.
              Hi Patrick,

              please take another look at my last post. In my example I need to change the target price (by 0.25$). How do I change the order accordingly?

              Specifically:
              - I want to prevent to have 2 exit orders active at the same time. Does some feature of NT take care of that in the background (wait for cancellation before sending a new order)? Or does NT reference the ticket number from the broker so there is no cancellation, but an update of the order ticket?
              - Since I need to update the order to reflect the new price I also need to reduce the number of shares to reflect the partial fill (300 less shares). How is that done?
              - Will the changes in the order also change the IOrder object?

              I hope I could make my problem more clear now.

              Thanks,
              NutFlush

              Comment


                #8
                Originally posted by NinjaTrader_Bertrand View Post
                Hi NutFlush,

                1. Correct BIP == 1 indicates second instrument updating, you send the orders then to the primary series.
                2. Correct, per default the order expires on the next OnBarUpdate(), either set it to liveUntilCancelled and CancelOrder() then or resend if unfilled and entry still valid. You resend when you want to resend it from an event perspective, OnExecution() would only be called if you see an incoming execution...
                3. I would generally suggest working with the IOrder objects, giving you access to the .Filled property for your order exactly, then upon resending you know how much qty you would need to complete the partial previous fill to reach your final desired qty - http://www.ninjatrader.com/support/h...ightsub=IOrder
                4. Yes, using a variable is possible.
                You mean that if an order is only part filled, NT will cancel the rest of the order on a new bar?

                Comment


                  #9
                  Hello NutFlush,

                  Thank you for your patience.

                  Using the same IOrder object name the order will be changed to the new price with the new quantity. The following is an example that shows the use of an IOrder object in OnExecution() to change the quantity based on what has been filled when a partial fill occurs:
                  Code:
                          #region Variables
                          private bool tradeOk = true;
                  		private IOrder myEntry = null;
                          #endregion
                  
                          
                          protected override void Initialize()
                          {
                             	
                          }
                  		
                  		protected override void OnBarUpdate()
                  		{
                  			if(Historical)
                  				return;
                  			
                  			if(tradeOk)
                  			{
                  				myEntry = EnterLongLimit(0, true, 5000, Close[0], "ThisEntry");
                  				tradeOk = false;
                  			}
                  
                  		}
                  		
                  		protected override void OnExecution(IExecution execution)
                  		{
                  			if(myEntry != null && myEntry == execution.Order)
                  			{
                  				if(myEntry.OrderState == OrderState.PartFilled)
                  				{
                  					myEntry = EnterLongLimit(0, true, 5000 - myEntry.Filled, Close[0], "ThisEntry");
                  				}
                  			}
                  		}
                  Please let me know if you have any questions.

                  Comment


                    #10
                    Originally posted by koganam View Post
                    You mean that if an order is only part filled, NT will cancel the rest of the order on a new bar?
                    Hello Koganam,

                    That is correct, even if the order is partially filled and you have the liveUntilCancelled bool set to false the order will be cancelled on the next bar.

                    Please let me know if I may be of further assistance.

                    Comment


                      #11
                      Originally posted by NinjaTrader_PatrickH View Post
                      Hello NutFlush,

                      Thank you for your patience.

                      Using the same IOrder object name the order will be changed to the new price with the new quantity. The following is an example that shows the use of an IOrder object in OnExecution() to change the quantity based on what has been filled when a partial fill occurs:
                      Code:
                              #region Variables
                              private bool tradeOk = true;
                              private IOrder myEntry[B][COLOR=Red]Old[/COLOR][/B] = null;
                              private IOrder [B][COLOR=Red]myEntryNew[/COLOR][/B] = null;
                              #endregion
                              
                              protected override void Initialize()
                              {
                              }
                              
                              protected override void OnBarUpdate()
                              {
                                  if(Historical)
                                      return;
                                  if(tradeOk)
                                  {
                                      myEntry[B][COLOR=Red]Old[/COLOR][/B] = EnterLongLimit(0, true, 5000, Close[0], "ThisEntry");
                                      tradeOk = false;
                                  }
                      
                              }
                              
                              protected override void OnExecution(IExecution execution)
                              {
                                  if(myEntry[B][COLOR=Red]Old[/COLOR][/B] != null && myEntry[B][COLOR=Red]Old[/COLOR][/B] == execution.Order)
                                  {
                                      if(myEntry[B][COLOR=Red]Old[/COLOR][/B].OrderState == OrderState.PartFilled)
                                      {
                                          [COLOR=Red][B]myEntryNew [/B][/COLOR]= EnterLongLimit(0, true, 5000 - myEntry[B][COLOR=Red]Old[/COLOR][/B].Filled, Close[0], "ThisEntry");
                                      }
                                  }
                              }
                      Please let me know if you have any questions.
                      Hi Patrick,

                      I sincerely thank YOU for your patience!

                      Please forgive me for my additional questions, but I am switching from TradeStation to NT and try to figure out what the differences are as their TradeManager takes care of certain order handling issues automatically.

                      I changed your code example (red) to make my questions more clear:
                      1) Since the entry order was given with liveUntilCancelled = true it would normally remain in the market until filled or cancelled (no automatic cancellation on the end of the bar), right?
                      2) After the updated order was given are the 2 IOrder objects identical or different? Is (myEntryNew == myEntryOld) true or false?
                      3) What happened to the order ticket at the broker? Did myEntryNew update the existing ticket or was a new ticket opened (for the reduced number of shares)? If the latter: wouldn't there be 2 active tickets at the broker or did NT in the background automatically cancel the first ticket?
                      4) Wouldn't it be possible that the original order could get filled some more even after the strategy received a number from "5000 - myEntryOld.Filled"? Or do you assume that myEntryOld has already been cancelled so that it can no longer receive any more fills (what cancelled that order then)?

                      Thanks again for your great support!
                      NutFlush

                      Comment


                        #12
                        Hello NutFlush,
                        Originally posted by NutFlush View Post
                        1) Since the entry order was given with liveUntilCancelled = true it would normally remain in the market until filled or cancelled (no automatic cancellation on the end of the bar), right?
                        That is correct, the bool liveUntilCancelled set to True will allow for the Limit order to stay active until cancelled or filled.
                        Originally posted by NutFlush View Post
                        2) After the updated order was given are the 2 IOrder objects identical or different? Is (myEntryNew == myEntryOld) true or false?
                        With your sample you now have two IOrder objects, which means you have two orders not one.
                        Originally posted by NutFlush View Post
                        3) What happened to the order ticket at the broker? Did myEntryNew update the existing ticket or was a new ticket opened (for the reduced number of shares)? If the latter: wouldn't there be 2 active tickets at the broker or did NT in the background automatically cancel the first ticket?
                        myEntryNew did not update myEntryOld, you created two orders. myEntryOld is still active and myEntryNew is now added as a new order.
                        Originally posted by NutFlush View Post
                        4) Wouldn't it be possible that the original order could get filled some more even after the strategy received a number from "5000 - myEntryOld.Filled"? Or do you assume that myEntryOld has already been cancelled so that it can no longer receive any more fills (what cancelled that order then)?
                        myEntryOld is still active, that means it can still be filled even though myEntryNew was submitted.

                        Please let me know if I may be of further assistance.

                        Comment


                          #13
                          Originally posted by NinjaTrader_PatrickH View Post
                          With your sample you now have two IOrder objects, which means you have two orders not one.

                          myEntryNew did not update myEntryOld, you created two orders. myEntryOld is still active and myEntryNew is now added as a new order.

                          myEntryOld is still active, that means it can still be filled even though myEntryNew was submitted.
                          Hi Patrick,

                          thanks for making those points clear!

                          Unfortunately I want to avoid to have 2 active orders and would like to update the existing order. Is there a way of doing it? Did that happen in YOUR example (without my changes), because you use the same IOrder variable "myEntry" instead of "myEntryOld" & "myEntryNew"?

                          Thanks again!
                          NutFlush

                          Comment


                            #14
                            Originally posted by NutFlush View Post
                            Hi Patrick,

                            thanks for making those points clear!

                            Unfortunately I want to avoid to have 2 active orders and would like to update the existing order. Is there a way of doing it? Did that happen in YOUR example (without my changes), because you use the same IOrder variable "myEntry" instead of "myEntryOld" & "myEntryNew"?

                            Thanks again!
                            NutFlush
                            In a nutshell: "yes".

                            Comment


                              #15
                              Hello NutFlush,

                              Thank you for your response.

                              Correct, in my example the order was changed to the new quantity and price but stayed as one order.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              649 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
                              576 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X