• 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

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
    DierkNinjaTrader Customer Service

    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 Dert66, Today, 12:11 PM
          0 responses
          5 views
          0 likes
          Last Post Dert66
          by Dert66
           
          Started by jjanguda, Today, 10:04 AM
          0 responses
          178 views
          0 likes
          Last Post jjanguda  
          Started by sambo81, Today, 09:20 AM
          1 response
          12 views
          0 likes
          Last Post sambo81
          by sambo81
           
          Started by TopGunNote, 05-14-2019, 01:12 PM
          3 responses
          78 views
          0 likes
          Last Post dpaulw
          by dpaulw
           
          Started by Grano, Today, 06:07 AM
          0 responses
          6 views
          0 likes
          Last Post Grano
          by Grano
           
          Working...
          X