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

Error on calling OnBarUpdate method on bar 0: Object reference not set to an instance

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

    Error on calling OnBarUpdate method on bar 0: Object reference not set to an instance

    Hi

    I'm currently converting an NT7 Indi to NT8. While loading the Indi into the chart, i'm getting the following error:

    Error on calling OnBarUpdate method on bar 0: Object reference not set to an instance of an object.

    The code block causing the issue must reside within this section however it's so difficult to figure that out because NT8 doesn't have an appropriated debugging mechansim for Indis.

    protected override void OnBarUpdate()
    {
    if (CurrentBars[0] == 0)
    {
    displacement = Math.Max(Displacement, -CurrentBar);
    priorUpTrend = true;
    currentUpTrend = true;
    upTrend[0] = true;

    PlotStopDot[0] = Close[0];
    PlotStopLine[0] = Close[0];

    PlotBrushes[0][-displacement] = Brushes.Transparent;
    PlotBrushes[1][-displacement] = Brushes.Transparent;

    return;
    }

    Thanks for your help.

    #2
    Hello Sweet&Sour,

    You should check that object references are not null.

    You could debug the code is add print statements such as,

    Print("Made it to line 5");

    Print("Made it to line 7");

    Etc, until you find which line is throwing the object reference error.

    You could also see this post,


    If you'd like to upload the full code I can take a look and see if anything jumps out. Or if you'd prefer to email a copy, send to platformsupport[at]ninjatrader[dot]com with Attn: Alan P in the Subject line. Also within the email please include a link to this thread, and the files.

    I look forward to your reply.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Thanks for your answer.

      Found the error. I usually check the objects if the are null or empty through the .Net Frameworks IsNullOrEmpty() method. In this case i just forgot it.

      For indicators, there is no other way to debug the code? Printing out line by line was state of the art in the 80's. NT Script is a great development enhancement however, to debug code step by step like in Visual Studio would be even much more better.

      Comment


        #4
        Originally posted by Sweet&Sour View Post
        Thanks for your answer.
        NT Script is a great development enhancement however, to debug code step by step like in Visual Studio would be even much more better.

        I guess you don't have another 10-20K for this feature, right?

        Comment


          #5
          Originally posted by senderz View Post
          I guess you don't have another 10-20K for this feature, right?
          As a professional developer for over 20 years, I'm owning an MSDN subscription which costs about 1000$/year. Price isn't the question as there is also a free VS express edition available for non professional developers. It's more a question of the integration into the VS IDE, specially into the debugging environment.
          Last edited by Sweet&Sour; 07-23-2017, 10:06 AM.

          Comment


            #6
            Hello senderz Sweet&Sour,

            You could see the following link on using VS for debugging.


            Please let us know if you need further assistance.
            Alan P.NinjaTrader Customer Service

            Comment


              #7
              since this is the first result in google search for this error msg...
              this might also help

              change your data series, time frame, bars to load / days to load
              increase that value.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Christopher_R, Today, 12:29 AM
              0 responses
              6 views
              0 likes
              Last Post Christopher_R  
              Started by sidlercom80, 10-28-2023, 08:49 AM
              166 responses
              2,235 views
              0 likes
              Last Post sidlercom80  
              Started by thread, Yesterday, 11:58 PM
              0 responses
              3 views
              0 likes
              Last Post thread
              by thread
               
              Started by jclose, Yesterday, 09:37 PM
              0 responses
              7 views
              0 likes
              Last Post jclose
              by jclose
               
              Started by WeyldFalcon, 08-07-2020, 06:13 AM
              10 responses
              1,415 views
              0 likes
              Last Post Traderontheroad  
              Working...
              X