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

OnConnectionStatusUpdate PriceStatus

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

    OnConnectionStatusUpdate PriceStatus

    This worked well in N7 but not quite sure in N8. Can someone tell me if this a good way to tell if the PriceStatus (not just connection) is being properly tested in the OnConnectionStatusUpdate event:

    Code:
    #region Variables
    private bool dataFeed = true;
    #endregion
    Code:
    protected override void OnConnectionStatusUpdate(ConnectionStatusEventArgs connectionStatusUpdate)
    {
       if(connectionStatusUpdate.PriceStatus == ConnectionStatus.Connected)
       {
        	dataFeed = true;
       }
    		  
       else if(connectionStatusUpdate.PriceStatus == ConnectionStatus.ConnectionLost)
       {
        	dataFeed = false;
       }
    }
    Somewhere in my code:

    Code:
    if (dataFeed != true)
    {
    	// do something on PriceStatus loss.
    }
    Kind regards and please advise.
    Last edited by Bluepoint; 12-06-2016, 10:40 AM. Reason: Update

    #2
    Hello Bluepoint,

    Thank you for your post.

    You are properly testing the PriceStatus connection. However, you are only setting a bool. This bool does not trigger any event. When you check the bool elsewhere in your code you would be waiting for that function to be called (such as OnBarUpdate). Which may not be called (OnBarUpdate for example) in the event of a disconnection.

    I would recommend processing whatever code you are performing with the bool verification elsewhere in your code in the OnConnectionStatusUpdate() function.

    For example:
    Code:
    protected override void OnConnectionStatusUpdate(ConnectionStatusEventArgs connectionStatusUpdate)
    {
       if(connectionStatusUpdate.PriceStatus == ConnectionStatus.Connected)
       {
        	Print("Price Feed Connected");
       }
    		  
       else if(connectionStatusUpdate.PriceStatus == ConnectionStatus.ConnectionLost)
       {
        	Print("Price Feed Disconnected");
       }
    }

    Comment


      #3
      Hello PatrickH,

      Thanks for the reply. When you say "However, you are only setting a bool. This bool does not trigger any event." Yes, I understand this point. This bool is checked in another function triggered by a timer so I do not need anything else other than to know the price feed is connected or not from the supposed OnConnectionStatusUpdate event.

      Perhaps I should have been more specific. In the below code snipet. The bool gets set to false upon "connectionStatusUpdate.PriceStatus == ConnectionStatus.ConnectionLost".

      But it never gets set back to true on "connectionStatusUpdate.PriceStatus == ConnectionStatus.Connected".

      This seems to be what I can't quite get. This "connectionStatusUpdate.PriceStatus == ConnectionStatus.Connected" appears not to be correct or the OnConnectionStatusUpdate connection event never fires.

      What should it be?

      Note: "connectionStatusUpdate.Status" with this mechanism does work, but not PriceStatus. But connection Status and PriceStatus are not the same. I want to check this at the price feed level, as often it is connected but has lost just the price feed. I noticed the following "PreviousPriceStatus" in other ConnectionStatusEventArgs but not sure what to check for here. Again, this all worked in N7, though it is slightly different in the code:

      N7 code:

      Code:
      private ConnectionStatus dataFeed = ConnectionStatus.Connected;
      
      protected override void OnConnectionStatus(ConnectionStatus orderStatus, ConnectionStatus priceStatus)
      {
      	dataFeed = priceStatus; 
      }
      
      .... somewhere else in the code (ensuring the event was triggered):
      
      if (dataFeed != ConnectionStatus.Connected)
      {
         // do something
      }
      Last edited by Bluepoint; 12-05-2016, 09:48 AM.

      Comment


        #4
        OnConnectionStatusUpdate never fires for PriceStatus - Bug?

        Based on my logs the OnConnectionStatusUpdate never fires saying the connection is back when the connection returns.


        Strategy 'BptAUDIT/91983334' lost price connection but will keep running.
        BptAUDIT: 2016-12-05 23:09:08.433 Enter: OnConnectionStatusUpdate
        BptAUDIT: 2016-12-05 23:09:08.433 Set to FALSE: OnConnectionStatusUpdate
        ...
        No reconnection trigger.

        protected override void OnConnectionStatusUpdate(ConnectionStatusEventArgs connectionStatusUpdate)
        {
        oops("Enter: OnConnectionStatusUpdate",0); // function write logfile
        if(connectionStatusUpdate.PriceStatus == ConnectionStatus.Connected)
        {
        oops("Set to TRUE: OnConnectionStatusUpdate",0); // function write logfile
        dataFeed = true;
        }

        else if(connectionStatusUpdate.PriceStatus == ConnectionStatus.ConnectionLost)
        {
        oops("Set to FALSE: OnConnectionStatusUpdate",0); // function write logfile
        dataFeed = false;
        }
        }
        Last edited by Bluepoint; 12-06-2016, 10:43 AM. Reason: Update

        Comment


          #5
          In order to debug this type of strategy we will need to force a connection loss. An easy way to do this is to force your computer into airplane mode where applicable, and to then physically unplug your ethernet cable. You will know you have a connection loss Ninja can detect if, when re-plugging your ethernet cable, you hear a chime letting you know you are connected.

          Once we have the ability to force connection loss, we may then use the instructions here to set up your strategy so that we can use Visual Studio to debug with.



          Once your strategy is set up for visual studio debugging, please set breakpoints both places dataFeed is set. This will give you a clear view into what is occurring when your connection is interrupted and restored. You will want to carefully review your connectionStatusUpdate object's settings every time one of these breakpoints is reached.

          With the information you are able to glean from this process, if there are any questions that come up that we may answer, such as why one of your breakpoints is not getting reached, please let us know so we may assist further.
          Jessica P.NinjaTrader Customer Service

          Comment


            #6
            Hello NinjaTrader_JessicaP

            Thank you for your response. But frankly going into debug in whatever strategy (I have tried this on several - all the same results), the following code simply does not work, because the reconnect trigger never fires. The Print statements below should be more than enough.

            protected override void OnConnectionStatusUpdate(ConnectionStatusEventArgs connectionStatusUpdate)
            {
            Print("YOU ARE HERE"); // <- this code never executes after the "Price Feed Disconnected" though the price feed has reconnected.
            if(connectionStatusUpdate.PriceStatus == ConnectionStatus.Connected)
            {
            Print("Price Feed Connected");
            }

            else if(connectionStatusUpdate.PriceStatus == ConnectionStatus.ConnectionLost)
            {
            Print("Price Feed Disconnected");
            }
            }
            Note: I do see the reconnect in the log tab. I am a bit surprised as this is a very basic function. Also, this is running on a server so I can not simulate this, though price feed loss happens several times a day with IB, so looking at the output one can easily see that this trigger never fires. Why? I can't imagine that any configuration options (or other strategy code) would affect this. We are talking PriceStatus not Status and this worked well in NT7.

            Kind regards and please advise ...
            Last edited by Bluepoint; 12-06-2016, 01:02 PM.

            Comment


              #7
              I have prepared an indicator and strategy on my system which produce the following output when I unplug my ethernet in airplane mode, wait until I hear "connection lost", then plug my ethernet cable back in physically :

              Indicator :
              status=ConnectionLost priceStatus=ConnectionLost previousStatus=Connected previousPriceStatus=Connected errorCode=NoError nativeError=''
              status=Connected priceStatus=Connected previousStatus=ConnectionLost previousPriceStatus=ConnectionLost errorCode=NoError nativeError=''
              Strategy:
              status=ConnectionLost priceStatus=ConnectionLost previousStatus=Connected previousPriceStatus=Connected errorCode=NoError nativeError=''
              Strategy 'Example1616661/92596219' lost price connection for more than 10 seconds and will be restarted.
              Disabling NinjaScript strategy 'Example1616661/92596219'
              Enabling NinjaScript strategy 'Example1616661/92596219' : On starting a real-time strategy - StartBehavior=WaitUntilFlat EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=Per entry execution ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=True / triggering 30 seconds before close SetOrderQuantityBy=Strategy ConnectionLossHandling=Recalculate DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=False CancelExitsOnStrategyDisable=False Calculate=On bar close IsUnmanaged=False MaxRestarts=4 in 5 minutes
              status=Connecting priceStatus=Connecting previousStatus=Disconnected previousPriceStatus=Disconnected errorCode=NoError nativeError=''
              status=Connected priceStatus=Connected previousStatus=Connecting previousPriceStatus=Connecting errorCode=NoError nativeError=''
              The strategy's start behavior was wait until flat. My tools -> options -> on connection loss setting is recalculate, 10 delay seconds, 4 restart attempts, restarts within 1 minute.

              Could you run the scripts I have attached with these settings on your computer, and let us know if you get different results?
              Attached Files
              Jessica P.NinjaTrader Customer Service

              Comment


                #8
                Hello NinjaTrader_JessicaP,

                Thank you for this. In short, the issue persists.

                I see the same results from my code as the code you provided. I did not (because I am on a server and do not have the same PC access) create the error in the same way as you. Pulling the cable might cause NT to act differently. I just let the typical priceStatus loss happen (they happen several per day) naturally. The following are the results:

                On start up:

                NJ TEST:status=Connecting priceStatus=Connecting previousStatus=Disconnected previousPriceStatus=Disconnected errorCode=NoError nativeError=''
                NJ TEST:status=Connected priceStatus=Connected previousStatus=Connecting previousPriceStatus=Connecting errorCode=NoError nativeError=''

                On priceStatus loss:

                Strategy 'NJ TEST/91983341' lost price connection but will keep running.
                NJ TEST:status=Connected priceStatus=ConnectionLost previousStatus=Connected previousPriceStatus=Connected errorCode=NoError nativeError=''


                Never receives a reconnect trigger.

                Also, the application sometimes freezes (application not responding) and requires a restart, though these two issues are not necessarily connected. I noticed a release upgrade to NinjaTrader 8.0.2.0 so I have applied this to see if anything helps, though in the release notes not sure it will help me.

                UPDATE: After upgrade - this had no effect on this issue.

                Kind regards and please advise ...
                Last edited by Bluepoint; 12-07-2016, 11:07 PM.

                Comment


                  #9
                  I noticed for your test you were using a different tools -> options -> on connection loss setting. For our test please change this to recalculate. If you feel this would invalidate the test or would rather not, please let me know so that I may change the setting on my end.

                  I would like to clarify, with the connection losses you report happening naturally, are you able to hear Ninja say audibly "connection lost", and are you able to receive a connection restored chime? These may be different sound clips if you have configured your system. Does the light in the lower left hand corner of Ninja go red on disconnect, and then green?

                  A test similar to the one I recommended that will work for servers will involve you using the freely and publicly available program TcpView . With Ninja running, highlight all NinjaTrader.exe processes, right-click, and select "Close Connection", to force a connection loss.

                  If you are certain a connection loss is being recognized by Ninja, but not NinjaScript, this is not a situation we have been able to reproduce with any network configuration so far. In order to see the same thing you are seeing on your end, we would need a way to reproduce the natural connection losses you are reporting. Any information you can give us about these would be appreciated. Even if you have given this information before, having it all in one place will make testing easy. Could you let us know

                  • which data feed provider you are using
                  • approximately how frequently natural connection losses occur
                  • what times of day natural connection losses occur
                  • if you have a trace file in your (My) Documents\NinjaTrader X\trace folder that includes the name as your data feed provider, please send a copy to platformsupport[at]ninjatrader[dot]com, with Attn:NinjaTrader_JessicaP and 1615425 in the subject line
                  • when a connection loss occurs, are you able to access your server remotely at this time? In other words, is the connection loss isolated to communication between Ninja and your data feed, with your server itself still connected to the internet?

                  Thank you in advance, I look forward to assisting further.
                  Last edited by NinjaTrader_JessicaP; 12-08-2016, 08:46 AM.
                  Jessica P.NinjaTrader Customer Service

                  Comment


                    #10
                    Hello NinjaTrader_JessicaP,

                    Thank you for your response. To answer your questions:

                    Ok, I set this accordingly -> For our test please change this to recalculate. The following are the Print logs from the script:

                    NJ TEST:status=Connected priceStatus=ConnectionLost previousStatus=Connected previousPriceStatus=Connected errorCode=NoError nativeError=''
                    NJ TEST:status=Connected priceStatus=ConnectionLost previousStatus=Connected previousPriceStatus=Connected errorCode=NoError nativeError=''
                    NJ TEST:status=Connected priceStatus=ConnectionLost previousStatus=Connected previousPriceStatus=Connected errorCode=NoError nativeError=''
                    NJ TEST:status=Connected priceStatus=ConnectionLost previousStatus=Connected previousPriceStatus=Connected errorCode=NoError nativeError=''

                    Again no reconnection trigger ....

                    I would like to clarify, with the connection losses you report happening naturally, are you able to hear Ninja say audibly "connection lost", and are you able to receive a connection restored chime? These may be different sound clips if you have configured your system. Does the light in the lower left hand corner of Ninja go red on disconnect, and then green?

                    ->The application is on a server so I can not hear, but when one loses priceStatus the indicator light turns yellow not red. On reconnect it turns back to green.

                    which data feed provider you are using

                    -> IB

                    approximately how frequently natural connection losses occur - Between 5 to 10 times of day ... this is normal with IB.

                    what times of day natural connection losses occur

                    -> every morning 2 to 8 times around 6am Paris time.

                    if you have a trace file

                    -> ok sent

                    when a connection loss occurs, are you able to access your server remotely at this time? In other words, is the connection loss isolated to communication between Ninja and your data feed, with your server itself still connected to the internet?

                    -> Yes I can access our server and yes "the connection loss isolated to communication between Ninja and your data feed".....

                    Kind regards and please advise ...

                    Comment


                      #11
                      Thank you Bluepoint, I have enough information to investigate on my end. I will return to this thread should I need any further information or to report my findings and advise further.
                      Jessica P.NinjaTrader Customer Service

                      Comment


                        #12
                        Hello NinjaTrader_JessicaP

                        Thank you for this. In a live industrial environment these triggers are very important. To launch trades in any strategy into an unstable environment is dubious. I would consider this issue a high priority for any serious organization using Ninjatrader in a live operational environment.

                        Why IB cuts its price feed every day at 6am in another issue for them, but they are a very big organization and it has been like this for years. So it is what it is.

                        I rest this with you in confidence.

                        Kind regards and please advise accordingly ...

                        Comment


                          #13
                          Hello Bluepoint,

                          I would like to check in with you to see if this is still occurring in 8.0.4.0 ?
                          Jessica P.NinjaTrader Customer Service

                          Comment


                            #14
                            The short answer is that it is not fixed. I had my NJ on 8.0.4 and this issue was not working. I had to return to 8.0.3 because of another issue: http://ninjatrader.com/support/forum...ad.php?t=95996

                            It seems we have a lot of critical bugs to correct. I am waiting for a new version.

                            Comment


                              #15
                              Thank you for your report Bluepoint. Since no other customers have been able to report this and we can not see the same thing in a controlled environment on our end, would you be comfortable letting a tech remote desktop into the affected computer? If not we understand. If so, please send contact information to platformsupport[at]ninjatrader[dot]com so we can investigate further. Should you come across any other information we may use please let us know.
                              Jessica P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by arvidvanstaey, Today, 02:19 PM
                              4 responses
                              10 views
                              0 likes
                              Last Post arvidvanstaey  
                              Started by samish18, 04-17-2024, 08:57 AM
                              16 responses
                              56 views
                              0 likes
                              Last Post samish18  
                              Started by jordanq2, Today, 03:10 PM
                              2 responses
                              8 views
                              0 likes
                              Last Post jordanq2  
                              Started by traderqz, Today, 12:06 AM
                              10 responses
                              18 views
                              0 likes
                              Last Post traderqz  
                              Started by algospoke, 04-17-2024, 06:40 PM
                              5 responses
                              47 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Working...
                              X