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

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

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

        Comment


          #5
          Thanks I fixed it.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Mongo, Today, 11:05 AM
          4 responses
          14 views
          0 likes
          Last Post Mongo
          by Mongo
           
          Started by traderqz, Today, 12:06 AM
          7 responses
          13 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by Skifree, Today, 03:41 AM
          5 responses
          13 views
          0 likes
          Last Post Skifree
          by Skifree
           
          Started by traderqz, Yesterday, 09:06 AM
          5 responses
          34 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by guillembm, Today, 11:25 AM
          1 response
          6 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X