Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Handling Data Connection interruption

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

    Handling Data Connection interruption

    Background:

    A couple of days ago my Strategy had placed a few orders in the wee hours of the morning. My Strategy is such that after I receive notice of Fills, I SetStopLoss & SetTarget. A while after placing the opening orders my IB TWS connection locked up. A while after that my opening orders were filled and because my Strategy was not notified I was left without StopLoss orders.

    Suggestion:

    Could NT could provide an Overrideable method like the OnBarUpdate called OnceEverySecond or OnceEveryMinute that fires on a time interval as opposed to receiving tick data? I could then check to see how long it has been since receiving a Tick and take actions accordingly...

    Thanks!

    #2
    SteveB,

    You can create custom events to do what you need. Please see this reference sample: http://www.ninjatrader-support2.com/...ead.php?t=5965

    Also, you can use the OnConnectionStatus() method to check for connection states.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Just what the doctor ordered...Thanks!

      Comment


        #4
        In the sample...

        Why is the author insisting on Raising an Event to handle logic instead of handling in the Timer Event?

        Thanks!

        Comment


          #5
          SteveB,

          This is standard programming procedure: to create a handler for the event.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            I have created a timer to fire every 1000ms...

            Problem:

            During the routine temporary disconnects from IB; timer event must be firing (or maybe not) but Raising Events is not happening. After 100 seconds my Strategy freezes. IB does come back eventually, but Strategy is frozen.

            Log Message:

            Error on triggering custom event for strategy '<myStrategy>': More than 100 subsequent user events

            Comment


              #7
              If you are no longer connected to a data feed you should not continue processing your events.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                I work too hard on this for such a lame answer.

                The FACT of the matter is NT freezes...are you the least bit concerned?

                Comment


                  #9
                  SteveB,

                  You are programming in much more advanced C# techniques and for sure there are many things you can do in code that will freeze NT. You need to program in a manner that addresses your concerns. NinjaTrader can only support up to NinjaScript. Anything above that we can only send you off in the right direction (which I already have done), but ultimately you will have to take it from there. You mention your events are no longer triggering. That is clear indication the code is not working as desired and the way to proceed is for you to code around it. There are many ways to detect disconnects like OnConnectionStatus(). Unfortunately I cannot assist you in this matter any further. If you want to get this professionally done you can try one of the 3rd party NinjaScript Consultants here: http://www.ninjatrader.com/webnew/pa...injaScript.htm
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    I understand how OnConnectionStatus works. And the Strategy used to come back to life when the ticks began flowing again after IB TWS reconnected to its host.

                    What I am trying to do is notify myself via alert & email if the connection has been down for more than xx minutes...

                    The suggestions below using a Timer have been implemented and work fine except for when the connection has been lost for > 100 seconds. Either the Timer Event does not fire or the Standard Procedure Raise Event does not fire when IB TWS loses its connection. It appears NT places the Events on a stack of sorts and overflows when 100 is reached, freezing the Strategy.

                    That's an FYI.

                    I will code around it.

                    Comment


                      #11
                      Hint: NT does not stack/buffer any timer events for custom coded timers. If the Windows event loop is stuck (for whatever reason) then the System.Windows.Form.Timer events would be queued by Windows like any other Windows event.

                      Unfortunately that is all the information I can provide. Good luck.
                      Josh P.NinjaTrader Customer Service

                      Comment


                        #12
                        Suggestion:

                        How about an OnFatalError Event I can program to.

                        It would be great to Alert/SendMail if NT can no longer execute my Stategy...

                        Comment


                          #13
                          Thank you for the suggestion. I will forward it to development.
                          Josh P.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          627 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          359 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by Mindset, 02-09-2026, 11:44 AM
                          0 responses
                          105 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                          0 responses
                          562 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          567 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X