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

Strategy with connection loss and NT Closed - Interactive Brokers

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

    Strategy with connection loss and NT Closed - Interactive Brokers

    My trades are generally swing trades that may last several days. On occasion something happens where I have to close out Ninjatrader and the Interactive Broker connection TWS and reopen both. When I reopen NT & TWS the strategy is disabled and both my target and stop loss orders are missing. I'm still in the trade but without those two exit orders. Is there some setting I can set to avoid this?

    Does the start behavior in my strategy affect this? I currently have Wait until flat.

    #2
    Hello bc24fl, thanks for writing in.

    You would need to set your startup behavior to something other than Wait Until Flat. Using Adopt Account Position or Immediately submit will preserve the orders that the strategy took after re-enabling the strategy. Please read through every start up behavior here for documentation on each feature:

    https://ninjatrader.com/support/help..._positions.htm

    Please let me know if I can assist any further.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChrisL View Post
      Hello bc24fl, thanks for writing in.

      You would need to set your startup behavior to something other than Wait Until Flat. Using Adopt Account Position or Immediately submit will preserve the orders that the strategy took after re-enabling the strategy. Please read through every start up behavior here for documentation on each feature:

      https://ninjatrader.com/support/help..._positions.htm

      Please let me know if I can assist any further.
      Yes I was reading that and notice the Adopt Account Position which looks fairly new since the last time I saw that page. I'll give that a try. Thank you.

      Comment


        #4
        Originally posted by bc24fl View Post

        Yes I was reading that and notice the Adopt Account Position which looks fairly new since the last time I saw that page. I'll give that a try. Thank you.
        So I tried that and purposely end tasked NT and TWS. Opened NT and TWS and received the below error. Also see the attached image.

        Error was not fully shown but the visible said

        "...behavior parameter 'Adopt account position' requires that there are no working orders on this strategy's instrument(s) in xxxxxxxxx. Please cancel any working orders on the same account-instrument combo(s) first to be able to ..."

        I don't need anything complicated really. I don't care about history or what was in the strategy position prior to losing connection. I want to be able to start up NT and TWS and have the strategy look at the account position (the position and two exit orders) and simply ADOPT THAT POSITION. So basically trust that what is on the live broker is the correct states and just sync with that. Is that possible?




        Attached Files

        Comment


          #5
          Ok so just tried a few more options:

          With "Immediately submit, synchronize account". Same thing as previous post. Shutdown TWS, and then shutdown NT. Opened NT and then TWS. Enabled the strategy and this time it put "synchronize" on the chart and exited my existing position but left both exit order (stop loss and profit target).

          With "Immediately submit". Same thing as previous post. Shutdown TWS, and then shutdown NT. Opened NT and then TWS. Enabled the strategy and this time it left my position opened but canceled my two exit orders (stop loss and profit target).

          I have read and reread this page https://ninjatrader.com/support/help..._positions.htm and I'm still drawing a blank.

          In my case, the account position (or what the broker has live) will always be the bible. Meaning I don't care what happened on the previous bars or historical. I don't care what the strategy thinks it needs to be. I want to enable the strategy and it automatically sync and copy what is in the Account Position to its Strategy Position. I know that the Account Position is in the perfect state so I just need to copy that to the Strategy Position when the strategy starts up again.

          Comment


            #6
            Hello bc24fl, thanks for your reply.

            A previously generated order is considered to match an active strategy order when the order action, order type, quantity, limit price, and stop price are exactly identical. I tested both Immediately Submit and Adopt Account Position and the orders the strategy previous and they are working on my end. See this demo video:


            If you test the attached strategy on your Interactive Brokers paper trading account you should get the same thing.

            If you do, then we would need to see why your strategy is not picking the orders back up after the restart. We would need a reduced example of the strategy.

            I look forward to hearing of your results.

            Attached Files
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              Hi Chris,
              I'm not sure, I understand the video. At the time the strat is deactivated, position size is 2. After reactivation it changes to 3.
              Is that expected behaviour? Shouldn't the strat recognize that it already had a position and only go long if that was not the case?
              Thanks for clarifying.
              NT-Roland

              Comment


                #8
                Hello NT-Roland, thanks for your reply.

                That is just a side effect from the test script. It submits an order at the first real time bar. The example was meant to demonstrate that matching orders will be resubmitted when the strategy starts back up.

                Best regards.
                Chris L.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_ChrisL View Post
                  Hello bc24fl
                  A previously generated order is considered to match an active strategy order when the order action, order type, quantity, limit price, and stop price are exactly identical.
                  Thank you Chris, I'll try that this weekend. Now that you say that, I generally use a market order to enter a position. Does the price have to match identical for the strategy and account to match/sync? If so that may be the issue.

                  Comment


                    #10
                    Hello bc24fl, thanks for your reply.

                    The market order would not be the issue. If the account is long, for example, and a stop loss and profit target are set up, then the strategy needs to be re-enabled, we use Immediately Submit because we already know the state the strategy will be in after re-enabling and we want the existing orders to be re-submitted.

                    Please let me know if I can assist any further.
                    Chris L.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_ChrisL View Post
                      Hello bc24fl, thanks for your reply.

                      A previously generated order is considered to match an active strategy order when the order action, order type, quantity, limit price, and stop price are exactly identical. I tested both Immediately Submit and Adopt Account Position and the orders the strategy previous and they are working on my end. See this demo video:


                      If you test the attached strategy on your Interactive Brokers paper trading account you should get the same thing.

                      If you do, then we would need to see why your strategy is not picking the orders back up after the restart. We would need a reduced example of the strategy.

                      I look forward to hearing of your results.
                      Hey Chris, I finally managed to get around to this. My apologies for the wait. I loaded your strategy and connected. The strategy first bought one contract with two exit orders. Then I disable the strategy and re-enable and it adds another contract and then changes both exit orders to another price. If you look at the strategy window you now see the Position 1L and Acct Position 2L with a sync of False. The only change I made was to set the start strategy to Immediate Submit. That's it. See attach for more settings. Any ideas?

                      Attached Files

                      Comment


                        #12
                        Hello bc24fl, thanks for your reply.

                        My demo script was only meant to demonstrate that the strategy generated resting orders are in fact resubmitted when the strategy is disabled and re-enabled. The strategy example is contrived, so it simply submits an order at the first real time bar which is why it submits an order after resubmission. In a real strategy, the entry condition would not happen again and again like this. I made a modification of the SampleMACrossover and added stops and targets to it to be more clear on the example. You will need to wait for an entry signal to test, but it makes the test more clear on how the strategy will pick back up on the orders it previously submitted.

                        https://clauber.tinytake.com/tt/NTAxMDM4MF8xNTc2MTgxMQ - demo video

                        Please let me know if you have any questions on this material.
                        Attached Files
                        Chris L.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_ChrisL View Post
                          Hello bc24fl, thanks for your reply.

                          My demo script was only meant to demonstrate that the strategy generated resting orders are in fact resubmitted when the strategy is disabled and re-enabled. The strategy example is contrived, so it simply submits an order at the first real time bar which is why it submits an order after resubmission. In a real strategy, the entry condition would not happen again and again like this. I made a modification of the SampleMACrossover and added stops and targets to it to be more clear on the example. You will need to wait for an entry signal to test, but it makes the test more clear on how the strategy will pick back up on the orders it previously submitted.

                          https://clauber.tinytake.com/tt/NTAxMDM4MF8xNTc2MTgxMQ - demo video

                          Please let me know if you have any questions on this material.
                          Thanks Chris. I'm not sure I understand. With respect to your first example, I was under the impression that when it is re-enabled again it would know it was in a hand (ie: !MarketPosition.Flat ) so your conditional will not EnterLong() again until the existing two exit orders get hit? Instead, it thinks it is flat so it EnterLog(). NT knows it's in a hand because you can see the strategy window displays 1L in the account position so why is MarketPosition not reflective of that state?
                          Last edited by bc24fl; 01-15-2021, 11:30 AM.

                          Comment


                            #14
                            Hello bc24fl, thanks for your reply.

                            This is because the Immediately Submit startup behavior is set. It's up to the user launching the strategy to know the account position will be in the correct state when enabling the strategy. Adopt Account Position would need to be used to take on the accounts position. Alternatively, if you use Immediately Submit, Synchronize account the strategy would first make the account flat because the strategy would start flat in the first example.

                            Please let me know if I can assist any further.
                            Chris L.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Segwin, 05-07-2018, 02:15 PM
                            10 responses
                            1,769 views
                            0 likes
                            Last Post Leafcutter  
                            Started by Rapine Heihei, 04-23-2024, 07:51 PM
                            2 responses
                            30 views
                            0 likes
                            Last Post Max238
                            by Max238
                             
                            Started by Shansen, 08-30-2019, 10:18 PM
                            24 responses
                            943 views
                            0 likes
                            Last Post spwizard  
                            Started by Max238, Today, 01:28 AM
                            0 responses
                            10 views
                            0 likes
                            Last Post Max238
                            by Max238
                             
                            Started by rocketman7, Today, 01:00 AM
                            0 responses
                            7 views
                            0 likes
                            Last Post rocketman7  
                            Working...
                            X