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

ConnectionStatus on chart as text

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

    ConnectionStatus on chart as text

    Hello,

    I have a "cloned" monitor in my living room that displays my charts from my study PC. Since I do not have the Control Center visible I am often unaware that my data is disconnected. I wrote some code to display as text on my chart if it is disconnected below:

    Code:
    private string data = "";
    
    protected override void OnBarUpdate()
            {
    			if (Bars.MarketData.Connection.PriceStatus == Cbi.ConnectionStatus.ConnectionLost || Bars.MarketData.Connection.PriceStatus == Cbi.ConnectionStatus.Connecting)
    				data = "Disconnected";
    			else if (Bars.MarketData.Connection.PriceStatus == Cbi.ConnectionStatus.Disconnected)
    				data = "*";
    			else
    				data = "";
    Font fontData = new Font("Arial", 16f,FontStyle.Regular);
    			DrawTextFixed("Status1", data, TextPosition.BottomLeft, Color.Yellow, fontData, Color.Yellow, Color.Yellow, 1);
            }
    But then I realised that if the datafeed is disconnected, then an OnBarUpdate will not occur and thus will not display my text.

    Any solutions? Thanks in advance.

    #2
    Hi Sim22, correct you could not rely on a OnBarUpdate() call being seen. Why not use the dedicated OnConnectionStatus method that would get triggered? Or a custom timer event?
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Such as this?

      Such as this?

      Code:
      protected override void OnConnectionStatus(ConnectionStatus orderStatus, ConnectionStatus priceStatus) 
      { 
       
      }

      Comment


        #4
        For anyone interested. This has not been tested with a live market, just connected to the weekend data feed. For a strategy of course. Is there any way to make this work as an indicator?

        Code:
        private ConnectionStatus dataFeed = ConnectionStatus.Disconnected;
        private string dataFeedStatus = "";
        
        protected override void OnConnectionStatus(ConnectionStatus orderStatus, ConnectionStatus priceStatus)
        		{
        			dataFeed = priceStatus; 
        			if (dataFeed != ConnectionStatus.Connected)
        			{
        				dataFeedStatus = "Disconnected";
        				Font fontData = new Font("Arial", 16f,FontStyle.Regular);
        				DrawTextFixed("Status1", dataFeedStatus, TextPosition.BottomLeft,         Color.Yellow, fontData, Color.Yellow, Color.Yellow, 1);
        				DrawTextFixed("Status2", dataFeedStatus, TextPosition.BottomRight, Color.Yellow, fontData, Color.Yellow, Color.Yellow, 1);
        			}
        		}

        Comment


          #5
          Originally posted by Sim22 View Post
          For anyone interested. This has not been tested with a live market, just connected to the weekend data feed. For a strategy of course. Is there any way to make this work as an indicator?

          Code:
          private ConnectionStatus dataFeed = ConnectionStatus.Disconnected;
          private string dataFeedStatus = "";
          
          protected override void OnConnectionStatus(ConnectionStatus orderStatus, ConnectionStatus priceStatus)
          		{
          			dataFeed = priceStatus; 
          			if (dataFeed != ConnectionStatus.Connected)
          			{
          				dataFeedStatus = "Disconnected";
          				Font fontData = new Font("Arial", 16f,FontStyle.Regular);
          				DrawTextFixed("Status1", dataFeedStatus, TextPosition.BottomLeft,         Color.Yellow, fontData, Color.Yellow, Color.Yellow, 1);
          				DrawTextFixed("Status2", dataFeedStatus, TextPosition.BottomRight, Color.Yellow, fontData, Color.Yellow, Color.Yellow, 1);
          			}
          		}
          In an indicator, use a custom Timer object and the TriggerCustomEvent() event handler, to process the original code idea that you had with OnBarUpdate().

          ref: http://www.ninjatrader.com/support/h...ustomevent.htm


          You forgot to Dispose() of your Font object. Remember to do so.
          Last edited by koganam; 09-14-2014, 08:38 AM.

          Comment


            #6
            Thanks koganam, much appreciated!

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by frankthearm, Yesterday, 09:08 AM
            11 responses
            41 views
            0 likes
            Last Post frankthearm  
            Started by junkone, Today, 11:37 AM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by quantismo, 04-17-2024, 05:13 PM
            5 responses
            35 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by proptrade13, Today, 11:06 AM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_Clayton  
            Started by love2code2trade, 04-17-2024, 01:45 PM
            4 responses
            34 views
            0 likes
            Last Post love2code2trade  
            Working...
            X