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 trilliantrader, 04-18-2024, 08:16 AM
          5 responses
          22 views
          0 likes
          Last Post trilliantrader  
          Started by Davidtowleii, Today, 12:15 AM
          0 responses
          3 views
          0 likes
          Last Post Davidtowleii  
          Started by guillembm, Yesterday, 11:25 AM
          2 responses
          9 views
          0 likes
          Last Post guillembm  
          Started by junkone, 04-21-2024, 07:17 AM
          9 responses
          68 views
          0 likes
          Last Post jeronymite  
          Started by mgco4you, Yesterday, 09:46 PM
          1 response
          12 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Working...
          X