Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Object reference not set to an instance of an object Error

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

    Object reference not set to an instance of an object Error

    Dear support:

    I have an indicator that caculates the ratio between two instruments and use the value as a dataseries to create an oscilator. The oscilltor is ploted most of the time. But if I change to a different time frame, a different instrument, or even change the periods parameters for the oscillator will not plot and the an error is generated:

    "Object reference not set to an instance of an object."

    I have made sure that CurrentBar under OnBarUpdate is not < Periods but the issue persist.

    I could not find any references in the forum addressing this error for plotting indicators. I have seen some references regarding correlation indicator with similar issues, but did not help.

    Any chance that you could provide some info on what might be causing this error.

    Many thanks.

    #2
    Hello aligator,

    Thanks for your post.

    The error is advising that something you are accessing has not been created at the time you are accessing it. There is no specific thing I can advise regarding the source of the error.

    To determine what the source of the error is you will need to debug your indicator. This is typically done with print statements added to your code to send a print output to the New > Ninjascript Output window.

    As you do not know where the error is, you would add a print statement every few lines of code that print out the values being used in that section of code and then observe the output window when you use the indicator. The last print statement value shown in the output window would indicate the error occurs after that print statement, you can then add further print statements to zero in on the offending code.

    Here is a link to our tips on debugging: https://ninjatrader.com/support/help...script_cod.htm

    Below is a link to a forum post that demonstrates how to use prints to understand behavior.

    https://ninjatrader.com/support/foru...121#post791121

    Let us know if we may assist further.​
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Thanks NinjaTrader_BrandonH


      SOLUTION: In case others have similar issues, my specific problem was caused by using custom brushes for BackBrushes whithout using a BackBrushes[0].Freeze(); statetement. Not freezing the custom brush was sometimes causing problems in muli-threading processes and the indicator was not plotted. Now everything is fixed and fine.

      I was easier to go through logic and rewrite the indicator than debugging using write statements.

      There must be an easier way, for example, if NinjaScript detects custom brushes are used simply include a Freeze statement. This idea can be applied to other situations where fixes can be internally used to avoid mind numbing errors.

      Cheers!.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      633 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      364 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      105 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      567 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      568 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X