Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public QuoteBasicBase Extract(int sindex, int eindex)
        {
            if (sindex < 0 || eindex > this.Count - 1 || eindex < sindex)
            {
                throw new ArgumentException(string.Format("Function {0} sindex: {1}, eindex: {2}, Count: {3}",
                                                          "Extract", sindex, eindex, this.Count));
            }

            int num   = eindex - sindex + 1;
            var quote = new QuoteBasicBase(Symbol, Interval);

            quote.Time.AddRange(Time.GetRange(sindex, num));
            quote.Open.AddRange(Open.GetRange(sindex, num));
            quote.High.AddRange(High.GetRange(sindex, num));
            quote.Low.AddRange(Low.GetRange(sindex, num));
            quote.Close.AddRange(Close.GetRange(sindex, num));
            quote.Volume.AddRange(Volume.GetRange(sindex, num));
            return(quote);
        }