Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How do you stop Strategt canceling all orders if restarted

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

    How do you stop Strategt canceling all orders if restarted

    Hi

    How do I stop a strategy from canceling all live orders that where placed by the strategy when the strategy is restarted.

    This is causing me some problems in my testing as if I have a position in the market, with a stop and target order, I stop the strategy all is fine the stop and target are still there, however if I restart the strategy the strategy cancels my stop and target order and leaves my position open and naked.

    Thanks

    Mike

    #2
    Hello,

    Unfortunately there is no way to disable this as this has to do with core NinjaTrader strategy sync logic.

    What occurs is when you re enable a strategy it cancels orders that may have been submitted by the strategy historically. Then resubmits them and the new recalculated levels. There may be no change to the order, however they just might have been. This is the reason this occurs.

    If they are not being resubmitted this indicates that the strategy is most likely flat in its position, but the account is still long. In which case to bring the account back in sync with the strategy you can submit a market order to sell your currently active order.

    Let me know if I can be of further assistance.

    Comment


      #3
      This is a very important topic to me.

      Can you please elaborate on what is happening here?

      Comment


        #4
        Hello,

        What do you need me to elaborate on here? I elaborated in the following post #2 let me know if you have questions.

        Let me know if I can be of further assistance.

        Comment


          #5
          Thanks for your reply Brett.

          Ouch that is going to cause me some issues.

          This raises a few more questions.

          1. Is there an unsupported way of doing this?

          2. Does this only happen to managed orders and will unmanaged orders get me around this?

          3. Does the OnOrderUpdate() method get called when these orders are canceled?

          4. Is it possible to programatically get the details of the orders that have been canceled, so that I can get the strategy to resubmit stop and target orders.

          Thanks

          Mike

          Comment


            #6
            Hello,

            1) There is not a supported way to get around this unfortunately.

            2) This occurs for all orders, managed or unmanged.

            3) No it does not.

            4) No information on this is accesible.

            Essentially, the reason this occured is that the strategy no longer was in the position and the orders where cancelled. This is working as expected. If the strategies not in a position it is not going to keep the previously submitted strategy orders in the market.

            If your strategy was in the same state as it was when you disabled it would have kept the orders there. However since it wasnt it took the neccisary steps to insure everything is on sync. This is known as strategy persistence.

            If your in this situation that only think I can think of is to completely delete the strategy then enable it fresh. This would not cause this to occur.

            Let me know if I can be of further assistance.

            Comment


              #7
              The way I am interpreting the issue of this thread is this...

              The user has a strategy. The strategy has submitted an order and that order has filled. The strategy submits an OCO target/stop order pair. So there is a LIVE order with a stop and target ordre above and below it. THEN the USER turns off his machine and goes to lunch (or somehow disables the strategy) .

              (Here is the important part that I might be misunderstanding)...

              When the strategy is stopped ( by turning off machine or some other method) the target/stop orders are canceled or when the strategy is re-started(turn on the machine) the target/stop orders are canceled.


              Am I mis-interpreting what is happening here? And if I am not, when do the OCO orders get canceled...when the strategy stops or when the strategy re-starts?

              Comment


                #8
                Originally posted by NinjaTrader_Brett View Post
                Hello,


                What occurs is when you re enable a strategy it cancels orders that may have been submitted by the strategy historically. Then resubmits them and the new recalculated levels. There may be no change to the order, however they just might have been. This is the reason this occurs.

                If they are not being resubmitted this indicates that the strategy is most likely flat in its position, but the account is still long. In which case to bring the account back in sync with the strategy you can submit a market order to sell your currently active order.

                Let me know if I can be of further assistance.
                When it cancels orders that may have been submitted historically what exactly do you mean? Why would the strategy have a need to cancel existing orders and recalculate and resubmit new orders. Can you please give a concrete example of what you mean?

                I see no reason , at all , for the strategy to do anything to any orders that are already sitting on the exchange floor...

                After recalculation , how can the strategy be flat while a position exists in the real market? At the time the strategy was stopped there was a position in the real market.

                My instincts are telling me that it would be very dangerous for the strategy to be issuing ANY orders based on historical data.

                I do see that an order could easily have been consumed by the real market during the time that the strategy was disabled. In this case the strategy would not have been aware of the changed state of these orders. Is this a mechanism that NT uses to get the strategy back in sync with the real market? Please explain in more detail or can you tell me where I can read exactly what is happening. A referral to the actual c# code would be good...
                Last edited by bob100; 01-22-2011, 10:22 AM.

                Comment


                  #9
                  I will have Brett get back to you on Monday.
                  AustinNinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by bob100 View Post
                    The way I am interpreting the issue of this thread is this...

                    The user has a strategy. The strategy has submitted an order and that order has filled. The strategy submits an OCO target/stop order pair. So there is a LIVE order with a stop and target ordre above and below it. THEN the USER turns off his machine and goes to lunch (or somehow disables the strategy) .

                    (Here is the important part that I might be misunderstanding)...

                    When the strategy is stopped ( by turning off machine or some other method) the target/stop orders are canceled or when the strategy is re-started(turn on the machine) the target/stop orders are canceled.


                    Am I mis-interpreting what is happening here? And if I am not, when do the OCO orders get canceled...when the strategy stops or when the strategy re-starts?

                    You are not misinterpreting the situation, that is exactly the scenario.

                    It is very concerning as what is happening is that you are left with a position in the market with no stop or target protecting your position.

                    Brett or someone else from NinjaTrader can you please check the replies given to this post as I find it very difficulty to believe that this is the case. If it is infact the case I see this as a catastrophic fault in the product.

                    Thanks

                    Mike

                    Comment


                      #11
                      I found the following in the documentation under the heading "Strategy Position vs Account Position"

                      An important concept to understand prior to using NinjaScript strategies in a real-time trading environment (live brokerage account for example) is the difference between a Strategy Position and an Account Position. A Strategy Position is a virtual position that is created by the entry and exit executions generated by a strategy and is independent from any other running strategy’s position or an account position. An Account Position is the position you actually hold in a real-time trading account, whether it is a NinjaTrader internal simulation account (Sim101) or your live real-money brokerage account. In most cases, a trader would want their Strategy Position’s size and market direction to be equal (in sync) to their Account Position but there are situations when this may not be the case.

                      For example:

                      You want to run multiple strategies in the same market simultaneously where strategy A holds a LONG 1 position, strategy B holds a LONG 2 position resulting in an account that should hold a LONG 3 position in order to be in sync with both strategies
                      You want to run a strategy and at the same time trade the same market the strategy is running on using discretionary tactics through one of NinjaTrader’s advanced order entry window such as the SuperDOM or Chart Trader

                      An extremely common scenario…

                      An extremely common scenario is starting a NinjaScript strategy in the middle of a trading session, such as one hour after the session has begun.. The NinjaScript strategy is run on each historical bar for the 1st hour of the session (it will actually run on all historical data loaded in a chart) to determine the current position state it would be in if it had been running live since the start of the session. This position state then becomes the Strategy Position for your strategy. Let us assume that during the historical hour your strategy would have entered a LONG 1 position and the position is still open. This would mean the Strategy Position is LONG 1 and since this trade was not actually executed on an account your Account Position is FLAT.

                      What can you do in this case?

                      If you want your Account Position to match your Strategy Position, you will need to place a manual order into the account the strategy is running on. Continuing from the above example, you would need to place a 1-lot market order for the market being traded into the account the strategy is running on.

                      What if I do not submit a manual order to sync my account?

                      The resulting behavior when the Strategy Position and Account Position are out of sync is when your strategy (continuing with the example above) closes the long position with a sell order it would bring the Strategy Position to flat and your Account Position to SHORT 1.

                      Comment


                        #12
                        Bob, Exactly correct. As NinjaTrader is built to calculate its strategy position based on Historical data. You can have this disabled however.

                        Let me know if I can be of further assistance.

                        Comment


                          #13
                          To Disable, Add if(Historical) return; to the top of OnBarUpdate() to disable running on historical data.

                          Let me know if I can be of further assistance.

                          Comment


                            #14
                            Originally posted by upshon View Post
                            Hi

                            How do I stop a strategy from canceling all live orders that where placed by the strategy when the strategy is restarted.

                            Mike
                            Mike,

                            Not a great workaround, but if you have the same exact strategy under a different name I dont believe it will affect any unfilled orders. Another workaround is to install 'buttons' that will let the strategy run but stop any further orders, so you dont need to actually stop the strategy itself, just its actions.

                            IF I am misunderstanding your intent, please enlighten me.

                            TJ

                            Comment


                              #15
                              Yes, you could use both of these methods as workarounds.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by carnitron, Today, 08:42 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post carnitron  
                              Started by strategist007, Today, 07:51 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post strategist007  
                              Started by StockTrader88, 03-06-2021, 08:58 AM
                              44 responses
                              3,974 views
                              3 likes
                              Last Post jhudas88  
                              Started by rbeckmann05, Today, 06:48 PM
                              0 responses
                              9 views
                              0 likes
                              Last Post rbeckmann05  
                              Started by rhyminkevin, Today, 04:58 PM
                              4 responses
                              58 views
                              0 likes
                              Last Post dp8282
                              by dp8282
                               
                              Working...
                              X