/// <summary> /// Load data from all files /// </summary> private void LoadData() { foreach (var file in Directory.GetFiles(DataDirectory)) { var fileName = Path.GetFileNameWithoutExtension(file); var date = DateTime.Parse(fileName.Substring(FilePrefix.Length)); _rawData.Add(date, ParseDataFile(file)); } Dates.AddRange(_rawData.Keys); }
/// <summary> /// Appends the other data to the data already in this class. It doesn't overwrite data /// for existing dates, so it can only prepend data to the start or append to the end. /// </summary> /// <param name="otherData">Data to append</param> public void AppendData(TickerData otherData) { // Prepend if (otherData.Start < Start) { // Find the index in the other data where this data starts. int copyEndIndex; for (copyEndIndex = 0; copyEndIndex < otherData.Dates.Count; copyEndIndex++) { if (otherData.Dates[copyEndIndex] >= Start) { break; } } // Insert all the new data at the front of the existing data. Dates.InsertRange(0, otherData.Dates.GetRange(0, copyEndIndex)); Open.InsertRange(0, otherData.Open.GetRange(0, copyEndIndex)); Close.InsertRange(0, otherData.Close.GetRange(0, copyEndIndex)); High.InsertRange(0, otherData.High.GetRange(0, copyEndIndex)); Low.InsertRange(0, otherData.Low.GetRange(0, copyEndIndex)); Volume.InsertRange(0, otherData.Volume.GetRange(0, copyEndIndex)); // Extras Typical.InsertRange(0, otherData.Typical.GetRange(0, copyEndIndex)); Median.InsertRange(0, otherData.Median.GetRange(0, copyEndIndex)); HigherTimeframeTrend.InsertRange(0, otherData.HigherTimeframeTrend.GetRange(0, copyEndIndex)); for (int i = 0; i < HigherTimeframeValueStrings.Length; i++) { string key = HigherTimeframeValueStrings[i]; HigherTimeframeValues[key].InsertRange(0, otherData.HigherTimeframeValues[key].GetRange(0, copyEndIndex)); } } // Append if (otherData.End > End) { // Find the index where the other data passes the end of the existing data. int copyStartIndex; for (copyStartIndex = 0; copyStartIndex < otherData.Dates.Count; copyStartIndex++) { if (otherData.Dates[copyStartIndex] > End) { break; } } // Append the new data to the end of the existing data. Dates.AddRange(otherData.Dates.GetRange(copyStartIndex, otherData.Dates.Count - copyStartIndex)); Open.AddRange(otherData.Open.GetRange(copyStartIndex, otherData.Open.Count - copyStartIndex)); Close.AddRange(otherData.Close.GetRange(copyStartIndex, otherData.Close.Count - copyStartIndex)); High.AddRange(otherData.High.GetRange(copyStartIndex, otherData.High.Count - copyStartIndex)); Low.AddRange(otherData.Low.GetRange(copyStartIndex, otherData.Low.Count - copyStartIndex)); Volume.AddRange(otherData.Volume.GetRange(copyStartIndex, otherData.Volume.Count - copyStartIndex)); // Extras Typical.AddRange(otherData.Typical.GetRange(copyStartIndex, otherData.Typical.Count - copyStartIndex)); Median.AddRange(otherData.Median.GetRange(copyStartIndex, otherData.Median.Count - copyStartIndex)); HigherTimeframeTrend.AddRange(otherData.HigherTimeframeTrend.GetRange(copyStartIndex, otherData.HigherTimeframeTrend.Count - copyStartIndex)); for (int i = 0; i < HigherTimeframeValueStrings.Length; i++) { string key = HigherTimeframeValueStrings[i]; HigherTimeframeValues[key].AddRange(otherData.HigherTimeframeValues[key].GetRange(copyStartIndex, otherData.HigherTimeframeValues[key].Count - copyStartIndex)); } } Start = Dates[0]; End = Dates[Dates.Count - 1]; NumBars = Dates.Count; SaveDates(); }
public void SetDates(List <string> dates) { Dates.Clear(); Dates.AddRange(dates); }