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 Mestor, 03-10-2023, 01:50 AM
          16 responses
          388 views
          0 likes
          Last Post z.franck  
          Started by rtwave, 04-12-2024, 09:30 AM
          4 responses
          31 views
          0 likes
          Last Post rtwave
          by rtwave
           
          Started by yertle, Yesterday, 08:38 AM
          7 responses
          29 views
          0 likes
          Last Post yertle
          by yertle
           
          Started by bmartz, 03-12-2024, 06:12 AM
          2 responses
          22 views
          0 likes
          Last Post bmartz
          by bmartz
           
          Started by funk10101, Today, 12:02 AM
          0 responses
          7 views
          0 likes
          Last Post funk10101  
          Working...
          X