Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Need Help with not Plotting

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

    Need Help with not Plotting

    I created this simple indicator to plot when low is less than low 1 bar ago.
    The problem I'm having is that it works fine until I change the data series to either a 6 or 7 range chart, then it doesn't plot. All other ranges are fine. Can someone tell me how to fix this? Why only those 2 data series have problems? It is a very simple example.


    protected override void OnBarUpdate()
    {
    // Use this method for calculating your indicator values. Assign a value to each
    // plot below by replacing 'Close[0]' with your own formula.
    Plot0.Set(RSI(14,1)[0]);

    // This is the problem code....6 or 7 Range does not plot all others are fine
    double L0 = Low[0];
    double L1 = Low[1];
    if (L0 < L1 ) BackColor = Color.Green;

    #2
    Hello tgraser,

    Welcome to the NinjaTrader Support Forums!

    Do you receive an error inside of the Log tab of the Control Center when they do not plot? If so what is the error message.

    Happy to be of further assistance.
    JCNinjaTrader Customer Service

    Comment


      #3
      Hi JC,

      Yes this is what is in the log when I set range to 6 or 7:

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

      Comment


        #4
        Hello tgraser,

        Thanks for the information.

        This error is because in "OnBarUpdate()" is trying to access the data series that does not have enough bars to calculate. More information about making sure you have enough bars can be found at the following link.


        This can be fixed by adding in a check to "CurrentBar" to make sure we have enough for the calculations in "OnBarUpdate()". Example:


        Code:
        protected override void OnBarUpdate()
        {
                if(CurrentBar < 15)
                {
                                      return;
                }
                //Rest of Code
        }

        The "if(CurrentBar < 15)" makes sure that there is at least 15 bars worth of data before starting your calculation. This ensures that we are not trying to access data that has not been created yet.

        Happy to be of further assistance.
        JCNinjaTrader Customer Service

        Comment


          #5
          Jc,

          Thank you for the help, that fixed it.

          It is a little weird though that only those two ranges(6 & 7) had problems, below 6 and above 7 everything was fine, no errors.

          Again, thanks for the help.
          Take care.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          574 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          333 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
          553 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          551 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X