Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator throws an exception

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

    Indicator throws an exception

    This is a very simple code: HIdentified is an indicator that return 1 when One of the Instrument makes a high while LIdentified return 1 when one of the instruments makes a low. I am seeing and exception
    : "10/26/2011 10:51:17 PM Default Error on calling 'OnBarUpdate' method for indicator 'WForEntry' on bar 0: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart. "

    CODE: WForEntry - using 5 min tick bars
    protected override void Initialize()
    {
    //Add Comparison Product
    Add(ComparisonProduct, PeriodType.Minute, TimePeriod);

    Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "WForEntryPlot"));
    Overlay = false;
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress == 0)
    {
    if(HIdentified(comparisonProduct,5)[0] == 1)
    {
    WForEntryPlot.Set(Lows[0][1] - 1 * TickMultiplier);
    dataSetTime = Time[0];

    }
    else if ((LIdentified(comparisonProduct, 5).Count > 0)&& (LIdentified(comparisonProduct, 5)[0] == 1))
    {
    WForEntryPlot.Set(Highs[0][1] + 1 * TickMultiplier);
    dataSetTime = Time[0];
    }

    if(dataSetTime != Time[0])
    {
    WForEntryPlot.Set(0);
    }
    }


    }

    #2
    Hello,

    You're likely running into an issue explained in the following forum post from our Tips section:

    http://www.ninjatrader.com/support/f...ead.php?t=3170

    Please try adding the following snippet to the beginning of your code in OnBarUpdate()

    if (Current Bar < 1)
    return;

    You need to ensure you have enough bars on the chart to calculate correctly.
    MatthewNinjaTrader Product Management

    Comment


      #3
      That worked

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      134 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      75 views
      1 like
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      119 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      114 views
      1 like
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      92 views
      0 likes
      Last Post CarlTrading  
      Working...
      X