예제 #1
0
        /// <summary>
        /// Gets a copy of this data from a date, to a date.
        /// </summary>
        /// <param name="start">Date to start from</param>
        /// <param name="end">Date to end at</param>
        /// <returns>New object with the data from the requested dates</returns>
        public TickerData SubSet(DateTime start, DateTime end)
        {
            TickerData copyData = new TickerData(TickerAndExchange);

            int copyStartIndex = -1;
            int copyEndIndex   = -1;

            for (int i = 0; i < Dates.Count; i++)
            {
                if (copyStartIndex == -1 && Dates[i] >= start)
                {
                    copyStartIndex = i;
                }
                if (copyEndIndex == -1 && Dates[i] >= end)
                {
                    copyEndIndex = i;
                }

                if (copyStartIndex > -1 && copyEndIndex > -1)
                {
                    break;
                }
            }

            if (copyStartIndex != -1)
            {
                if (copyEndIndex == -1 && end > Dates.Last())
                {
                    copyEndIndex = Dates.Count - 1;
                }

                int amountToCopy = (copyEndIndex - copyStartIndex) + 1;
                copyData.Dates.AddRange(Dates.GetRange(copyStartIndex, amountToCopy));
                copyData.Open.AddRange(Open.GetRange(copyStartIndex, amountToCopy));
                copyData.Close.AddRange(Close.GetRange(copyStartIndex, amountToCopy));
                copyData.High.AddRange(High.GetRange(copyStartIndex, amountToCopy));
                copyData.Low.AddRange(Low.GetRange(copyStartIndex, amountToCopy));
                copyData.Volume.AddRange(Volume.GetRange(copyStartIndex, amountToCopy));

                // Extras
                copyData.Typical.AddRange(Typical.GetRange(copyStartIndex, amountToCopy));
                copyData.Median.AddRange(Median.GetRange(copyStartIndex, amountToCopy));
                copyData.HigherTimeframeTrend.AddRange(HigherTimeframeTrend.GetRange(copyStartIndex, amountToCopy));

                for (int i = 0; i < HigherTimeframeValueStrings.Length; i++)
                {
                    string key = HigherTimeframeValueStrings[i];
                    copyData.HigherTimeframeValues[key].AddRange(HigherTimeframeValues[key].GetRange(copyStartIndex, amountToCopy));
                }

                copyData.Start   = copyData.Dates[0];
                copyData.End     = copyData.Dates[copyData.Dates.Count - 1];
                copyData.NumBars = copyData.Dates.Count;
                copyData.SaveDates();
            }

            return(copyData);
        }