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 Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      589 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      342 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      103 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      555 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      552 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X