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

Object reference not set to an instance of an object.

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

    Object reference not set to an instance of an object.

    Can I get an explanation of this error in my log?

    Error on calling the 'OnBarUpdate' method for indicator 'ProfitLine' on bar 0: Object reference not set to an instance of an object.

    The very first stmt in the 'OnBarUpdate' method is :
    if (Bars == null || CurrentBar < 500) return;

    so I never reference any indicator until after that. Unfortunately I do not control the ProfitLine code -- however, the indicator plots on a chart without problem. But I want to reference it in code. Help?

    #2
    Lost Trader, can you try restructuring the code like this?
    Code:
    if (Bars != null)
    {
        if (CurrentBar < 500)
            return;
    }
    As for your other query, a simple way to obtain the plot name for a certain indicator is to fire up the Strategy Wizard and use the condition builder to obtain the plot name. You can then reference this in the code. Please see the attached picture for what I'm talking about.
    Attached Files
    AustinNinjaTrader Customer Service

    Comment


      #3
      Austin, thank you. I restructured the initial code like this:
      Code:
      if (Bars == null) return;
                  else if (CurrentBar < 500) return;
      but that doesn't seem to be the problem.

      I did use the Strategy Wizard to produce code of the indicators. Thanks for confirming that! I decided to test all four indicators . . .

      Of the four, two work fine (without error) and two produce this error when I save the indicator output to a variable. And that is ALL I am doing.
      At this point I am stuck.

      Comment


        #4
        LostTrader, any way you could check with the original creator of the called ProfitLine indicator as to why you might see this error when trying to access it programmatically?
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Bertrand, I did sent them an email; however, I believe they are going to ask me for more information (e.g., what the message means). I also want to understand why the error happens so if they resist, I have information to keep pushing for resolution. They certainly didn't choose that text wording.

          Usually when NT complains about Bar 0, it is because I forgot the first line & it really is bar 0 where some indicators have no value yet. . But that is not true -- I don't even try to look at indicator values until bar 500 -- so what does the error mean?

          Comment


            #6
            LostTrader, no this error is different, don't believe you run into the CurrentBars issue...

            I'm not sure about the ProfitLine indicator code and what it tries to access as part of its programming, but this error indicators there's an empty object that is being accessed.

            Without a look at the custom code, unfortunately not possible for me to advise further.
            BertrandNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by andrewtrades, Today, 04:57 PM
            1 response
            5 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by chbruno, Today, 04:10 PM
            0 responses
            3 views
            0 likes
            Last Post chbruno
            by chbruno
             
            Started by josh18955, 03-25-2023, 11:16 AM
            6 responses
            436 views
            0 likes
            Last Post Delerium  
            Started by FAQtrader, Today, 03:35 PM
            0 responses
            7 views
            0 likes
            Last Post FAQtrader  
            Started by rocketman7, Today, 09:41 AM
            5 responses
            19 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Working...
            X