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

When strategy loses connection

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

    #31
    Hello timko,

    I have added a vote on your behalf.

    Please note that if you are using Interactive Brokers, you can use IB Gateway to connect instead of TWS and you will not receive server side disconnections on a daily basis. Please see the thread below where this is discussed.

    Hi all, i'm working on automation for a stable service environment for my strategies. Following Applications / Versions are in place: NT8 (8.0.20.1) TWS from IB / Captader (978.1h) 1.) First i tried/checked auto restart for TWS by it self. It is still working good. After a quick shotdown of around 20-30sec. TWS is


    We look forward to assisting.
    JimNinjaTrader Customer Service

    Comment


      #32
      Please also add my vote to SFT-2395.

      Comment


        #33
        Hello Jim,
        Thanks a lot for your suggestion! I appreciate it very much.
        My current problem is indeed, after a data disconnect, a strategy does not take up and carry on what was left after a restart (either due to a data reconnect, a strategy restart or a NT8 program restart). This extends to the behavior that a strategy does not take account into the existing positions in the trading account.
        What I want is: when a strategy starts, it reads in any existing trading account position and gives the user an option if to carry on to work on the current positions. Same applies to any position added (manually) outside the strategy while it is active.

        Comment


          #34
          Hello timko,

          Thanks for your message.

          What I want is: when a strategy starts, it reads in any existing trading account position and gives the user an option if to carry on to work on the current positions. Same applies to any position added (manually) outside the strategy while it is active.
          Creating a strategy that adopts the account position is already possible. Please see Adopt Account Position under Start Behaviors and the strategy I have attached. If the strategy detects an account position, you could have the script prompt the user if it should use that position or not. Using the Unmanaged Approach, you will not be tied to the bounds of a strategy position.

          Creating a prompt could be done similarly to the script here - https://ninjatrader.com/support/foru...m-in-indicator

          Start Behaviors - https://ninjatrader.com/support/help...rtbehavior.htm

          Unmanaged Approach - https://ninjatrader.com/support/help...d_approach.htm

          The strategy can also monitor PositonAccount with the Unmanaged Approach to be able to monitor changes to the account's position.

          PositionAccount - https://ninjatrader.com/support/help...ionaccount.htm

          We look forward to assisting.
          Attached Files
          JimNinjaTrader Customer Service

          Comment


            #35
            thanks a lot Jim! let me take a look into this

            Comment


              #36
              please add my vote to SFT-2395. This is a very much needed function.

              Comment


                #37
                Hello PWidera,

                The Interactive Brokers Connection Adapter does have the functionality added since Release 22 to be able to automatically reconnect when the connection is disconnected. This was added when we moved to using TWS/IB Gateway 978.2c which instills that you use an Auto Restart or Auto Log Off feature for daily restarts or to automatically log off.

                There were some hitches getting the Interactive Brokers Connection Adapter to work friendly with the TWS/IB Gateway Auto Restart feature, which we have made changes internally to address those remaining issues and are continuing to test to look for other reconnect issues.

                This would mean that if you leave the strategy running with Connection Loss Handling set to Keep Running with Disconnect Delay Seconds set to be long enough to withstand the disconnect, the strategy will resume once the connection is re-established.

                If you need to re-enable a strategy, you can consider using the ImmediatelySubmit start behavior to have the strategy calculate its orders and position from processing historical data and attempt to resume an active position/orders.

                You could also consider using AdoptAccountPosition to have the account position inherited. My example posted in post #34 can help to show how AdoptAccountPosition strategies can be written.

                If you are referring to another Connection Adapter, I will be happy to add your vote.
                JimNinjaTrader Customer Service

                Comment


                  #38
                  Hi Jim,

                  regarding to your advices for AdoptAccountPosition and parameters for StartBehavior (ImmediatelySubmit & ImmediatelySubmitSynchronizeAccount) i'm not able to follow you.
                  I have tested that 5 min. ago with any positive result.

                  If i reconnect and then start strategy with StartBehavior (ImmediatelySubmit or ImmediatelySubmitSynchronizeAccount) current existing AccountPosition would be directly closed!
                  If i reconnect and then start strategy while StartBehavior is (AdoptAccountPosition), current AccountPosition semms to be visual detected but not handled by strategy anymore.
                  (You see on chart, that current position is marked as virtual!?)

                  My expectation is:
                  What ever goes wrong, if connection and strategy is re-established, current AccountPosition (real Money) must be respected and adopted.
                  From there on, AccountPosition should be handled by strategy again.

                  My code and screenshots with real live demo-results you find here: https://ninjatrader.com/support/foru...t-interruption


                  May you can help me out?

                  Comment


                    #39
                    Hi Jim,

                    i also have checked your code from post #34.
                    With this recommendation, we leave completely managed approach and most of NT-Servicefunctions!?

                    I have tried to work with your code on analyzer-side / historical-data.
                    I can't get open any position if it is not realtime... :-(

                    Comment


                      #40
                      Hello PWidera,

                      As you were working with my colleague, Paul, I left your questions for his response so we would not have multiple technicians working the same ticket. Please avoid posting the same questions in separate threads as it can result in multiple technicians working the same ticket and can hurt our response time for others.

                      Paul had showed how AdoptAccountPositon could be used to have a strategy pick up the account position. The example strategy does not process historical data, so it will always cancel the live working orders and replace them with the protective orders submitted in State.Realtime.

                      ImmediatelySubmit would be used to have a strategy resume a position after you re-enable it. The strategy processes historical data, calculates the historical orders and tries to resume them. If the live orders do not match they will not be resumed, and they will be canceled and replaced with the historical orders.

                      (Please see Start Behaviors above for more details.)

                      The video below shows a slight modification of the SampleOnOrderUpdate strategy, with larger stops and targets for testing, resume orders after re-enable.

                      Demo - https://drive.google.com/file/d/1YID...w?usp=drivesdk

                      As for leaving a connection running with Interactive Brokers, please see the demonstration below.

                      Demo - https://drive.google.com/file/d/1xGo...w?usp=drivesdk

                      We look forward to assisting.
                      JimNinjaTrader Customer Service

                      Comment


                        #41
                        Hi Jim,

                        thanks for your explanation and both of your videos.
                        I would love to follow along with you especially with your second video, but i can't!

                        I have modified values on (Options --> Strategies --> Connection) as you pointed.
                        StartBehavoir was also the same as you showed on video.

                        I have tested that behavoir with IB-Gateway (978 and also 984).
                        Every time IB-Gateway startet (re-start)-process an alert from NT-site occured and strategy as well as account-connection would be stopped and never comes back to live!!!!!!
                        Please check my provided trace-file and all screenshots...

                        What course the problem?
                        How can i prevent from that real problem for an algotrader?


                        Cheers,
                        Phil
                        Attached Files
                        Last edited by NinjaTrader_Jim; 05-24-2021, 07:07 AM.

                        Comment


                          #42
                          Hello Phil,

                          I have removed the trace file from your post for security reasons, but we have it saved internally in our ticket tracking system.

                          I do see that you are using an older version of NinjaTrader 8. You can try using Release 23.2 which should handle the TWS/IB Gateway restarts better, but we should note that we are still looking into some remaining reconnect issues in our internal build.



                          The current reconnect issues after Release 23.2 are being investigated with the internal ticket ID NTEIGHT-14865. The number for this ID will be posted in the Release Notes page of the Help Guide when a new release comes out and contains a fix for the remaining reconnect issues. Please note that we cannot offer an ETA on new release schedules as they are determined by Product Management and pending Development tasks.

                          Release Notes - https://ninjatrader.com/support/help...ease_notes.htm

                          We look forward to assisting.



                          JimNinjaTrader Customer Service

                          Comment


                            #43
                            I fully setup a new virtual machine to install all need application from scratch.
                            - Windows Server 2019
                            - Java-Runtime
                            - NT (8.0.24.2)
                            - IB-Gateway (984)

                            - DataConnection was established
                            - CapTrader / IB-Account Connection was established
                            - For stratgies setting (keep running) is defined as well as max. timeout
                            - Load a simple strategy to open every (05, 15, 25, 35 etc.) a contract and close every (0, 10, 20, 30 etc.) current contract on real live account!

                            I defined for 02:58 PM auto re-start for IB-Gateway!

                            Result you can see by my trace-file... :-(
                            IB-Gateway starts daily auto re-start on 02:58 PM.
                            NT-Connection for CapTrader/IB goes red, but nothing else (nothing bad).
                            IB-Gateway provided re-connected session.
                            NT-Connection for CapTrader/IB persists as RED!!!!
                            Once strategy tries to open a new position an error message occurs.
                            Strategy can't handle any position for related account!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!

                            What i should do to fix that problem?
                            Attached Files

                            Comment


                              #44
                              Hello PWidera,

                              I have removed the trace file from your post again as we do not want to have these files hosted on the forums as they may contain personal information. Even if you scrub the files, some personal information may still be left. Please do not post log and trace files on the forum.

                              As I mentioned in post #42, there are still some reconnect issues remaining with NinjaTrader reconnecting after the TWS/IB Gateway Auto Restart that are still under investigation.

                              If you want to find a work around in the meantime, other users have reported that they could still use IB Gateway 973.2h to stay connected, which does not mandate the Auto Restart, and does not disconnect on its own until a weekend mandatory disconnect.
                              JimNinjaTrader Customer Service

                              Comment


                                #45
                                This is a old post. But for someone coming across this thread again, please note that Ninja trade 8 now has keep running option available. Go to tools -> Options-> Strategy -> On connection lost -> Keep running.

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by elirion, Today, 01:36 AM
                                0 responses
                                3 views
                                0 likes
                                Last Post elirion
                                by elirion
                                 
                                Started by gentlebenthebear, Today, 01:30 AM
                                0 responses
                                4 views
                                0 likes
                                Last Post gentlebenthebear  
                                Started by samish18, Yesterday, 08:31 AM
                                2 responses
                                9 views
                                0 likes
                                Last Post elirion
                                by elirion
                                 
                                Started by Mestor, 03-10-2023, 01:50 AM
                                16 responses
                                391 views
                                0 likes
                                Last Post z.franck  
                                Started by rtwave, 04-12-2024, 09:30 AM
                                4 responses
                                34 views
                                0 likes
                                Last Post rtwave
                                by rtwave
                                 
                                Working...
                                X