Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Draw.Rectangle object reference not set to an instance not set

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

    Draw.Rectangle object reference not set to an instance not set

    Hi,

    I'm getting the error message "Indicator '': Error on calling 'OnBarUpdate' method on bar 135: Object reference not set to an instance of an object." on the below code:

    Code:
    Draw.Rectangle(this, "OpeningRange", false, 225, orHigh, 0, orLow, Brushes.Transparent, Brushes.Firebrick, 20);
    I'm not quite sure why this keeps happening.

    #2
    Hello maltese,

    Thanks for your post.

    At the time that the Draw.rectangle is executing it may be that only 135 bars have been loaded and it appears that you are trying to reference a start bars ago of 225. You would need to check that at least 225 bars have loaded before trying to execute the Draw.

    You can check how many bars by looking at the value of CurrentBar. For example:

    Code:
    if (CurrentBar > 225)
    Draw.Rectangle(this, "OpeningRange", false, 225, orHigh, 0, orLow, Brushes.Transparent, Brushes.Firebrick, 20);
    Reference: https://ninjatrader.com/support/help...currentbar.htm

    Comment


      #3
      Originally posted by NinjaTrader_Paul View Post
      Hello maltese,

      Thanks for your post.

      At the time that the Draw.rectangle is executing it may be that only 135 bars have been loaded and it appears that you are trying to reference a start bars ago of 225. You would need to check that at least 225 bars have loaded before trying to execute the Draw.

      You can check how many bars by looking at the value of CurrentBar. For example:

      Code:
      if (CurrentBar > 225)
      Draw.Rectangle(this, "OpeningRange", false, 225, orHigh, 0, orLow, Brushes.Transparent, Brushes.Firebrick, 20);
      Reference: https://ninjatrader.com/support/help...currentbar.htm
      Thanks but I tried that. The referenced code is actually in a multi-timeframe instrument and it appears that Draw.Rectangle bombs when it tries to reference a lookback greater than 256 bars even if I add the code you mentioned.

      Comment


        #4
        Hello maltese,

        Thanks for clarifying that you are using an MTF Ninjascript. In that case I recommend that you review the following sections of the helpguide and would advise to use CurrentBars instead of CurrentBar after reviewing the MTF section of the helpguide. https://ninjatrader.com/support/help...nstruments.htm

        Also, if your script has added any series<t> you may need to set the lookback period to MaximumBarsLookBack.Infinite as the default is 256. Reference: https://ninjatrader.com/support/help...rslookback.htm Note this can also set in the parameters of the applied Ninjascript.

        Comment


          #5
          Thanks I fixed it.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          571 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          330 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          548 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          549 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X