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

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 Stanfillirenfro, Yesterday, 09:19 AM
          7 responses
          51 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by TraderCro, 04-12-2024, 11:36 AM
          4 responses
          69 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Mindset, Yesterday, 02:04 AM
          1 response
          15 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by agclub, 04-21-2024, 08:57 PM
          4 responses
          18 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by Irukandji, Today, 04:58 AM
          0 responses
          6 views
          0 likes
          Last Post Irukandji  
          Working...
          X