Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

What is PoF chart necessary BarsRequiredToPlot

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

    What is PoF chart necessary BarsRequiredToPlot

    I'm getting this error while trying to create an indicator on a chart like PoF, it seems the bars required to plot is variable, how can I accurately check if I have the green light to start plotting on this kind of chart?

    Indicator 'SampleTest': Error on calling 'OnBarUpdate' method on bar -1: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
    Code:
    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion
    
    //This namespace holds Indicators in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class SampleTest: Indicator
    {
      protected override void OnStateChange()
      {
        if (State == State.SetDefaults)
        {
        Description = @"Enter the description for your new custom Indicator here.";
        Name = "SampleTest";
        Calculate = Calculate.OnEachTick;
        IsOverlay = true;
        DisplayInDataBox = true;
        DrawOnPricePanel = true;
        DrawHorizontalGridLines = true;
        DrawVerticalGridLines = true;
        PaintPriceMarkers = true;
        ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
        //Disable this property if your indicator requires custom values that cumulate with each new market data event.
        //See Help Guide for additional information.
        IsSuspendedWhileInactive = true;
        }
        else if (State == State.Configure)
        {
        AddDataSeries(Data.BarsPeriodType.Minute, 1);
        }
      }
    
     protected override void OnBarUpdate()
     {
       if (CurrentBar < BarsRequiredToPlot ||
       CurrentBars[1] < BarsRequiredToPlot)
       return;
    
       Print(Times[0][0]);
     }
    }
    }

    #2
    Hello Waxavi,

    Please try changing the condition you have to use CurrentBars for both:

    Code:
    if (CurrentBars[0] < BarsRequiredToPlot ||
    CurrentBars[1] < BarsRequiredToPlot)
    return;
    The code you have now is using CurrentBar which is mapped to whichever BarsInProgress is being called so the condition will not include the primary sometimes.

    That would be the only item that I can see from the given code that may be incorrect.

    Comment


      #3
      Hello Jesse,

      That seemed to do the trick, thank you.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      633 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      364 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      105 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      567 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      568 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X