• 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

ISeries<double> Count does not match Collection Count

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

    ISeries<double> Count does not match Collection Count

    I am running into an issue with ISeries<double> that the collection size does not match the count. here is output from my immediate window. Note it tells me I have more than 400 elements in the array by count, but It only actually has 41.

    Close.Count
    490
    Close[0]
    6.84
    Close[91]
    'Close[91]' threw an exception of type 'System.ArgumentOutOfRangeException'
    ActualValue: null
    Data: {System.Collections.ListDictionaryInternal}
    HResult: -2146233086
    HelpLink: null
    InnerException: null
    Message: "Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index"
    ParamName: "index"
    Source: "mscorlib"
    StackTrace: " at System.ThrowHelper.ThrowArgumentOutOfRangeExceptio n(ExceptionArgument argument, ExceptionResource resource)\r\n at NinjaTrader.Data.BarsSeries.GetClose(Int32 index)\r\n at NinjaTrader.Data.Bars.GetClose(Int32 index)\r\n at NinjaTrader.NinjaScript.PriceSeries.get_Item(Int32 barsAgo)"
    TargetSite: {Void ThrowArgumentOutOfRangeException(System.ExceptionA rgument, System.ExceptionResource)}

    Any help would be appreciated.

    #2
    Hello filopearson,

    From the given information I wouldn't be sure what may have happened in that test however using the Count of the Close series is not a value which normally has any use. What was the intention in your test? Can you provide a specific example of why the Count was needed here?

    What is the value of the CurrentBar at the time of the error? If you used 91 as a BarsAgo but were not past bar 91 in processing you would get this type of error.


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      I'm trying to iterate to get a collection of values to determine local highs and lows:

      var rollingHigh = double.MinValue;
      var rollingLow = double.MaxValue;
      double thisHigh = double.MaxValue;
      double thisLow = double.MinValue;
      var maxLookback = Math.Min(IntervalsBetweenChecks + 1, Math.Min(Close.Count - 1, Open.Count - 1));
      var forindex = maxLookback;
      try
      {

      for (var bar = maxLookback - 1; bar >= StartBar; bar--)
      {
      if (Close[bar] > Open[bar])
      {
      thisHigh = Close[bar];
      thisLow = Open[bar];
      }
      else
      {
      thisHigh = Open[bar];
      thisLow = Close[bar];
      }
      if (thisHigh > rollingHigh)
      rollingHigh = thisHigh;
      if (thisLow < rollingLow)
      rollingLow = thisLow;
      forindex--;
      }
      double? addLow = thisLow - rollingLow > .1 ? rollingLow : null as double?;
      double? addHigh = rollingHigh - thisHigh > .1 ? rollingHigh : null as double?;

      if (addLow != null || addHigh != null)
      ThisDayHighLows.Add(new HighLow
      {
      High = addHigh,
      Low = addLow,
      Date = Time[StartBar]
      });
      }
      catch(Exception ex)
      {
      // swollow
      }

      Comment


        #4
        and mispelling swallow

        Comment


          #5
          Hello filopearson,

          Yes in this case the Count would not be relevant, you need to check that you are past the CurrentBar if you want to use that amount of BarsAgo.

          For example if you are on bar 0 in processing you cannot access data beyond 0 BarsAgo. Once you are on bar 10 in processing you can access up to 10 BarsAgo. On bar 0 you will know the Count of the series however because you are not beyond that point you cant access that data yet. You would not be able to iterate the Count of the series using a BarsAgo until you have reached that count in processing.

          To use the count directly or iterate this before you process data you would need to use the indexes instead of BarsAgo by using GetValueAt. https://ninjatrader.com/support/help...getvalueat.htm Close.GetValueAt(i)

          I look forward to being of further assistance.
          JesseNinjaTrader Customer Service

          Comment


            #6
            ok I think I see what you're saying. It's only partially loaded and I ultimately look at CurrentBar for collection count, is that correct?

            Comment


              #7
              Hello filopearson,

              Correct, when using NinjaScript you are relying on the events of your script to drive logic so looping is not frequently needed. Your script starts processing on bar 0 and then continues from that point on for each bar. For ongoing calculations you would just do that on each OnBarUpdate event and reference whatever prior data was needed to further the calculation. You can see this happening in indicators like the SMA.You can also see handling for when there is limited data such as bar 0, later when more data is avaialbe different calculations are used that include the prior data.

              If you need to loop over the data you can but you need to remember to do it the right way, the BarsAgo system specifically relates to where you are in processing right now. The CurrentBar tells you where you are in time or in processing right now so that would be used as a Count in most cases, the count until now.



              I look forward to being of further assistance.
              JesseNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by gemini42, Today, 01:53 AM
              1 response
              4 views
              0 likes
              Last Post NinjaTrader_ShawnB  
              Started by asmmbillah, Today, 04:42 PM
              2 responses
              10 views
              0 likes
              Last Post asmmbillah  
              Started by JAtrades, Today, 02:44 PM
              3 responses
              12 views
              0 likes
              Last Post NinjaTrader_ShawnB  
              Started by mr_trade, Today, 01:32 PM
              1 response
              11 views
              0 likes
              Last Post Emma1
              by Emma1
               
              Started by sgordet, Today, 10:44 AM
              1 response
              13 views
              0 likes
              Last Post bltdavid  
              Working...
              X