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

Lost Connection and not Reestablished

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

    Lost Connection and not Reestablished

    Hi,

    Today I had a connection loss problem that was not reestablished.
    No attempt was made to reestablish the connection via the log tab.

    In Tools -> Options -> Strategies i defined "On connection loss" like below:

    Handling: Keep Running
    Disconnect delay seconds: 10
    Number of restart attempts: 99999999
    Restart within x minutes: 1


    Q1: How do I set these parameters so that Ninja tries endlessly to reestablish the connection?

    Q2: Are reconnection attempts listed on the Log tab or elsewhere?

    Q3: When manually disconnecting and reconnecting, the connection was reestablished, but the strategy was disabled. This caused me a great deal of damage as my strategy lost all the references and variables I had so far. How do I configure my strategy not to be disabled when the connection goes down?

    Q4: Is it possible to perform some treatment through the OnConnectionStatusUpdate() event to reestablish the connection?

    Thanks.
    Last edited by brunoviveiros; 05-08-2020, 11:26 AM.

    #2
    Hello brunoviveiros,

    Thank you for the post.

    How do I set these parameters so that Ninja tries endlessly to reestablish the connection?
    I don't believe this would be completely possible. There are cases where if the platform adapter has a complete disconnect that will stop the strategies as the connection is no longer present. This would generally be if the provider disconnects you for maintenance or if your PC fully looses internet. For general connection drops or issues you can try to tune these settings for your specific situation.In what you provided that should generally cover a normal small timeframe disconnect.

    Are reconnection attempts listed on the Log tab or elsewhere?
    The reconnects will be listed in the log.

    Q3: When manually disconnecting and reconnecting, the connection was reestablished, but the strategy was disabled. This caused me a great deal of damage as my strategy lost all the references and variables I had so far. How do I configure my strategy not to be disabled when the connection goes down?
    If you manually disconnect and no longer have any internet that may close the connection adapter completely which would disable the strategy. That could also try to reconnect quickly as there is no wait time for a response, for other cases which fall within the general reconnect settings rules you can use "Keep Running" which will prevent the strategy from recalculating when it reconnects.

    Is it possible to perform some treatment through the OnConnectionStatusUpdate() event to reestablish the connection?
    You can use an addon to manage connections however there is no specific use case or sample relating to using OnConnectionStatusUpdate like that which I could provide. Generally this override is just used for informational use cases and also to call the reload historical data if needed. If you have frequent disconnects or problems with the connection it may be suggested to use a VPS instead of trying to work around the problem and relying on the connection loss settings to accurately handle the strategy.


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hello Jesse,

      Thanks for your ansewer.

      The reconnects will be listed in the log.
      I refer to attempts to reconnect.

      You can use an addon to manage connections however there is no specific use case or sample relating to using OnConnectionStatusUpdate like that which I could provide. Generally this override is just used for informational use cases and also to call the reload historical data if needed. If you have frequent disconnects or problems with the connection it may be suggested to use a VPS instead of trying to work around the problem and relying on the connection loss settings to accurately handle the strategy.
      I'm already using AWS VPS for running my strategy, but even so the problem occured in the last week.
      Is there another treatment to solve this problem? Like the option below?



      Tks again.
      Last edited by brunoviveiros; 05-11-2020, 07:14 AM.

      Comment


        #4
        Hello brunoviveiros,

        Thank you for the reply.

        I believe only the actual connection events would be logged in this situation, if you are seeing a situation where you get many reconnect attempts in a short period we could review your specific log to gather more details around the connection events that were logged for your connection.

        The link you had shown would be for the addon framework and would allow an addon to manage connections however that would not necessarily work for this situation. While you could monitor the connection you would not know when the connection would be valid to reconnect and also if a disconnect had occurred to where you need to manage the connection your strategy will have been disabled you will need to manually intervene at that point anyway.

        If you are seeing disconnects on the VPS I could suggest to look at other providers and review their up time and stability reports prior to testing their services. There still can be outages with any provider so there is not necessarily a way to make sure its running 100% of the time as there are certain events which would require some manual intervention.


        I look forward to being of further assistance.


        JesseNinjaTrader Customer Service

        Comment


          #5
          Hi, Jesse!

          Today i had a similar issue with the Phillip Capital connection.
          The strategy run in two instruments MES 09-20 and MNQ 09-20.

          When i connect in Phillip Capital, only the instrument MES 09-20 retrieve data in the chart.
          This behavior taked approximately 2 hours.


          So, i decied disconnect and connect manually to try fix this issue.
          And when i did that, both MES 09-20 and MNQ 09-20 were load correctly.


          In the event OnConnectionStatusUpdate, i have the status of my connection (connectionStatusUpdate.Connection.Status), however i can't force recconection by the code. I know that is possible disconect via the method connectionStatusUpdate.Connection.Disconnect(), but i don't have a method like connectionStatusUpdate.Connection.Connect().

          When i lose connection or my connection does not load data correctly, how can i act by the code to solve this issue ?

          Please, can you help me ?

          Comment


            #6
            Hello brunoviveiros,

            Thank you for the reply.

            You can try using the addon method for Connect, there is a sample located here:

            You would need to locate the connection using that approach, that is also shown in the addon sample here: https://ninjatrader.com/support/help...t_overview.htm

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Hi, Jesse!

              I implement the Connect() method like the example above, but i don't understand how this method can be useful.
              For example, I created a timer that is actived when the connection status is diferent from Connected.

              Code:
              protected override void OnConnectionStatusUpdate(ConnectionStatusEventArgs connectionStatusUpdate)
                      {
                              _myTimer.Enabled = (connectionStatusUpdate.Connection.Status != ConnectionStatus.Connected);
                      }
              This timer activates the Connect() method and runs every 5 seconds until the connection is reestabilished.
              But when my connection status is ConnectionLost, the line code for connection
              Code:
              Connection connect = Connection.Connect(connectOptions);
              is not reached, because the if condition it's only true when my connection hasn't instantiated.
              Code:
              if (Connection.Connections.FirstOrDefault(c => c.Options.Name == _cnnName) == null)

              So, is there a way to force Disconnect() and Connect() by code?
              If I call the Disconnect() method the connection will be disconnected (OK) but my strategy will be changed to Enable=False and my code will not be executed because the strategy is not active.


              Thank you so much for working to help!

              Comment


                #8
                Hello brunoviveiros,

                With the level of control over the connection that you want you would not be able to use a strategy for that. Strategies are controlled by a variety of factors and there are safeguards to take that offline when something unexpected happens. If you want to avoid any safeguards like disabling on disconnect you can use an addon rather than using a strategy.

                The strategy its self is not a good candidate for connection mitigation code because it has other outside factors controlling it beyond what you can control. If you wanted to work with the connection you can see the addon section and work with an addon for that type of logic. I had provided a comment about this:

                The link you had shown would be for the addon framework and would allow an addon to manage connections however that would not necessarily work for this situation. While you could monitor the connection you would not know when the connection would be valid to reconnect and also if a disconnect had occurred to where you need to manage the connection your strategy will have been disabled you will need to manually intervene at that point anyway.
                Even if you manage to reconnect the strategy is going to have been disabled. That approach just won't work based on how strategies accommodate connection losses. The alternative is to create an addon that places trades, that won't care about the connection at all in regard to being enabled/disabled it would just keep running.

                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Hi Jesse!

                  Sorry, I didn't exactly understand the behavior of add-ons before.
                  Now your explanation has made this clearer to me and I believe I understand.

                  Thank you very much for yout support, as you have always been very attentive.

                  I will venture more deeply into the behavior of these add-ons and any needs I get in touch again.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by GussJ, 03-04-2020, 03:11 PM
                  11 responses
                  3,223 views
                  0 likes
                  Last Post xiinteractive  
                  Started by andrewtrades, Today, 04:57 PM
                  1 response
                  10 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Started by chbruno, Today, 04:10 PM
                  0 responses
                  7 views
                  0 likes
                  Last Post chbruno
                  by chbruno
                   
                  Started by josh18955, 03-25-2023, 11:16 AM
                  6 responses
                  438 views
                  0 likes
                  Last Post Delerium  
                  Started by FAQtrader, Today, 03:35 PM
                  0 responses
                  10 views
                  0 likes
                  Last Post FAQtrader  
                  Working...
                  X