• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

need help to fix code for System.ArgumentOutOfRangeException:

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

    need help to fix code for System.ArgumentOutOfRangeException:

    i use a multi timeframe indicator and i am always having exceptions in this code on historical data as there might not be enough datapoints.

    Code:
    if (Highs[2][0] > Highs[1][1])
                            {
    
                              // do something
                            }

    Parameter name: index
    System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index
    at System.Collections.ArrayList.get_Item(Int32 index)
    at NinjaTrader.Data.MemBars.GetOpen(Int32 index)
    at NinjaTrader.Data.Bars.GetHigh(Int32 index)
    at NinjaTrader.Indicator.DataSeriesHelper.get_Item(In t32 barsAgo)


    i cannot use the following logic as the bars with missing data varies based on the instrument and i dont have a common ground.
    if (CurrentBar < somebar)
    return;

    NT support pointed to this link but i cannot get my head on clear as to how to fix the code,
    http://ninjatrader.com/support/forum...ead.php?t=3170

    how do i check in my Highs[1] to see if data exists before doing the comparision?

    #2
    Hello junkone,

    This code shows that you are attempting to check if the high of the most recent bar on the 3rd data series is greater than the previous bar on the 2nd data series.

    To confirm, you have added at least 2 additional series using the AddDataSeries() call, is this correct?

    To check the bar that the other series are on use:

    if (CurrentBars[2] > 0 && CurrentBars[1] > 1)

    If the current bar number on the 3rd series is greater than 0 (meaning there is at least 1 bar) and the current bar number of the 2nd series is greater than 1 (meaning there is at least 2 bars).

    Below is a link to the help guide on CurrentBars.
    http://ninjatrader.com/support/helpG...urrentbars.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      voila, i am so excited. it works and i can rest in peace without the exceptions flooding my logs

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by jgfirefn, Today, 02:26 AM
      0 responses
      2 views
      0 likes
      Last Post jgfirefn  
      Started by Gerik, Yesterday, 10:58 PM
      1 response
      4 views
      0 likes
      Last Post NinjaTrader_ChrisSch  
      Started by Gerik, Yesterday, 11:27 PM
      0 responses
      4 views
      0 likes
      Last Post Gerik
      by Gerik
       
      Started by Bionian, Yesterday, 11:14 PM
      0 responses
      2 views
      0 likes
      Last Post Bionian
      by Bionian
       
      Vps by stooby
      Started by stooby, Yesterday, 08:32 PM
      0 responses
      14 views
      0 likes
      Last Post stooby
      by stooby
       
      Working...
      X