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

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,


    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 judysamnt7, 03-13-2023, 09:11 AM
      4 responses
      59 views
      0 likes
      Last Post DynamicTest  
      Started by ScottWalsh, Today, 06:52 PM
      4 responses
      36 views
      0 likes
      Last Post ScottWalsh  
      Started by olisav57, Today, 07:39 PM
      0 responses
      7 views
      0 likes
      Last Post olisav57  
      Started by trilliantrader, Today, 03:01 PM
      2 responses
      21 views
      0 likes
      Last Post helpwanted  
      Started by cre8able, Today, 07:24 PM
      0 responses
      10 views
      0 likes
      Last Post cre8able  
      Working...
      X