Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Testing for null Time object

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

    Testing for null Time object

    Not sure this is really an NT8 issue but I'm posting it here as I'm refactoring some older code in NT8. Basically I wrote myself a Print method with PrintLevels - similar to LogLevels. I'm plotting a lot of context for every print call I'm making, part of it is the Time[0].

    Only problem I'm running into is that sometimes Print(value, PrintLevel) is being called during the initialization process. And Time[0] throws one of these:

    Error on calling 'OnStateChange' method: Object reference not set to an instance of an object.

    Not good. I'm trying to test for it like this:

    String time = (Time == null || Time.Count == 0) ? "" : Time[0].ToString();

    Not helping though - still getting that exception. Anyone know how to properly test for this? Obviously this doesn't come up often as usually nobody calls Time[0] before the bars are flowing.

    Thanks in advance.

    #2
    Never mind - I figured it out. This is my solution:

    Code:
    String time = "";
    
    if (State != State.SetDefaults && State != State.Configure && State != State.DataLoaded 
    && Time != null  && Time.Count > 0) {
    	time = Time[0].ToString();
    }
    Last edited by molecool; 06-02-2015, 05:21 AM.

    Comment


      #3
      Hello molecool,

      Thank you for your post.

      Glad you were able to resolve this matter.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Max238, Today, 01:28 AM
      5 responses
      40 views
      0 likes
      Last Post Max238
      by Max238
       
      Started by giulyko00, Yesterday, 12:03 PM
      3 responses
      12 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by habeebft, Today, 07:27 AM
      1 response
      14 views
      0 likes
      Last Post NinjaTrader_ChristopherS  
      Started by AveryFlynn, Today, 04:57 AM
      1 response
      12 views
      0 likes
      Last Post NinjaTrader_Erick  
      Started by r68cervera, Today, 05:29 AM
      1 response
      10 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Working...
      X