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 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.​
    Brandon H.NinjaTrader Customer Service

    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 mattbsea, Today, 05:44 PM
      0 responses
      4 views
      0 likes
      Last Post mattbsea  
      Started by RideMe, 04-07-2024, 04:54 PM
      6 responses
      31 views
      0 likes
      Last Post RideMe
      by RideMe
       
      Started by tkaboris, Today, 05:13 PM
      0 responses
      2 views
      0 likes
      Last Post tkaboris  
      Started by GussJ, 03-04-2020, 03:11 PM
      16 responses
      3,282 views
      0 likes
      Last Post Leafcutter  
      Started by WHICKED, Today, 12:45 PM
      2 responses
      20 views
      0 likes
      Last Post WHICKED
      by WHICKED
       
      Working...
      X