Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Series<T> implementing IEnumerable

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

    Series<T> implementing IEnumerable

    Is there any reason why Series<T> doesn't implement IEnumerable interface?
    This small change would give users all the LINQ flexibility.

    In NT7 I used DataSeries extension to circumvent it, but if there is no important reason why Series<T> doesn't implement IEnumerable I would ask for this change to happen.

    Here are the extensions I wrote for NT7:
    Code:
        public static class DataSeriesExtensions
        {
            // Example Use: var test = MyPlot.ToDoubleArray();
            public static double[] ToDoubleArray(this DataSeries series)
            {
                if (series == null) return null;
                int seriesCount = series.Count;
                double[] tempArray = new double[seriesCount];
                for (int i = 0; i < seriesCount; i++)
                    tempArray[i] = series[i];
                return tempArray;
            }
    
            // Example Use: var test = MyPlot.ToDoubleArray(14);
            public static double[] ToDoubleArray(this DataSeries series, int window)
            {
                if (series == null) return null;
                double[] tempArray = new double[window];
                for (int i = 0; i < window; i++)
                    tempArray[i] = series[i];
                return tempArray;
            }
    
            // Example Use: var test = MyPlot.ToEnumerable<double>();
            // The non windowed version doesn't work properly on bar series, eg. Close, Open, etc.)
            // As a workaround use: var test = Close.ToEnumerable<double>(CurrentBar);
            public static IEnumerable<T> ToEnumerable<T>(this IDataSeries series) //where T: IConvertible
            {
                if (series == null) return null;
                int window = series.Count;
                T[] tempArray = new T[window];
                for (int i = 0; i < window; i++)
                {
                    tempArray[i] = (T)Convert.ChangeType(series[i], typeof(T));
                }
                return tempArray;
            }
    
            // Example Use: var test = MyPlot.ToEnumerable<double>(14);
            public static IEnumerable<T> ToEnumerable<T>(this IDataSeries series, int window) //where T: IConvertible
            {
                if (series == null) return null;
                T[] tempArray = new T[window];
                for (int i = 0; i < window; i++)
                {
                    tempArray[i] = (T)Convert.ChangeType(series[i], typeof(T));
                }
                return tempArray;
            }
        }

    #2
    Interesting suggestion. Added as #325. Thanks

    Comment


      #3
      Checking if you have considered making this change?

      Comment


        #4
        Hello,
        I have checked on this feature request with our development team and currently it is still under review.
        Cody B.NinjaTrader Customer Service

        Comment


          #5
          Thank you Cody.

          Keeping my fingers crossed for this one as it brings (as a default) plenty of .NET >= 3.0 functionality that is missing - and it is quite a lot that has changed since 2006!

          From my own experience - since I started using the extensions in the original post - I keep wondering how did I manage to do all my calculations before - my code is cleaner and shorter (as I do plenty of statistics). I can keep using the extensions, but having it out of the box will help others and increase the quality of code.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Mindset, Today, 06:46 AM
          0 responses
          8 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by M4ndoo, Yesterday, 05:21 PM
          0 responses
          14 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by M4ndoo, 04-19-2026, 05:54 PM
          0 responses
          15 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by cmoran13, 04-16-2026, 01:02 PM
          0 responses
          82 views
          0 likes
          Last Post cmoran13  
          Started by PaulMohn, 04-10-2026, 11:11 AM
          0 responses
          48 views
          0 likes
          Last Post PaulMohn  
          Working...
          X