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

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 benmarkal, Yesterday, 12:52 PM
      3 responses
      22 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by helpwanted, Today, 03:06 AM
      1 response
      18 views
      0 likes
      Last Post sarafuenonly123  
      Started by Brevo, Today, 01:45 AM
      0 responses
      11 views
      0 likes
      Last Post Brevo
      by Brevo
       
      Started by aussugardefender, Today, 01:07 AM
      0 responses
      6 views
      0 likes
      Last Post aussugardefender  
      Started by pvincent, 06-23-2022, 12:53 PM
      14 responses
      244 views
      0 likes
      Last Post Nyman
      by Nyman
       
      Working...
      X