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

SetState Error

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

    SetState Error

    How can I avoid following error, while changing input of an indicator:

    Indicator '(null)': Error on calling 'SetState' method: Object reference not set to an instance of an object.

    Is it due to using following code within State.SetDefaults and State.SetConfigure:
    if (Instrument != null)
    {
    Print(this.Name + " [" + DateTime.Now.ToString("dd-MMM-yyyy hh.mm.ss.ffffff") + "] " + Instrument.FullName );
    }

    Kind Regards
    Vivek

    #2
    Hello engrvivs, and thank you for your question. It is very likely that your Instrument is not set up in advance of this call. I would recommend the following code change :

    Print(this.Name + " [" + DateTime.Now.ToString("dd-MMM-yyyy hh.mm.ss.ffffff") + "] " + (Instrument == null ? "(Instrument not yet set up) : Instrument.FullName) );

    Please let us know if there are any other ways we can help.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Thanks Jessica for the response!

      Yet, confusing point is before executing the Print command I have checked using:
      if (Instrument != null)

      Won't it do the same task as you suggested?

      Thanks

      Comment


        #4
        Hello engrvivs,

        You are correct, this was a mistake caused by my overlooking that part of your code.

        I would like to mention, the Help Guide section on Instrument mentions this :

        Originally posted by http://ninjatrader.com/support/helpGuides/nt7/instrument.htm
        NOTE: The properties in this class should NOT be accessed within the Initialize() method.
        In light of this, I would like to ask a few questions :

        1. Would it be possible for you to comment out this section in your code and replace it by this code?

          Print(Instrument);
          //Print(Instrument.FullName);
        2. Could you test that, then comment out the first line and uncomment the second line, and test that
        3. Could you provide some contextual information concerning the code surrounding your call to Instrument?
        Jessica P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by selu72, Today, 02:01 PM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_Zachary  
        Started by WHICKED, Today, 02:02 PM
        2 responses
        12 views
        0 likes
        Last Post WHICKED
        by WHICKED
         
        Started by f.saeidi, Today, 12:14 PM
        8 responses
        21 views
        0 likes
        Last Post f.saeidi  
        Started by Mikey_, 03-23-2024, 05:59 PM
        3 responses
        51 views
        0 likes
        Last Post Sam2515
        by Sam2515
         
        Started by Russ Moreland, Today, 12:54 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Erick  
        Working...
        X