/// <summary> /// Adds all items in the list to the internal data items list. /// If the first items are continuation of the previous added timeframe, then a change notification is raised for the changed items. /// Then all remaining items are added and only one notification is raised for all of them. /// </summary> /// <param name="items"></param> public void AddData(IList<IDataItem> items) { if((items == null) || (items.Count == 0)) throw new ArgumentException(); List<IDataItem> newItems = null; IDataItem oldItem = null; int index; DateTime date; double open, high, low, close; long volume; if ((_dataItems.Count > 0) && (TimeFrameDurations.Start(Timeframe, _dataItems[_dataItems.Count - 1].Date) == TimeFrameDurations.Start(Timeframe, items[0].Date))) { oldItem = _dataItems[_dataItems.Count - 1]; //date = oldItem.Date; date = TimeFrameDurations.Start(Timeframe, _dataItems[_dataItems.Count - 1].Date); open = oldItem.Open; high = oldItem.High; low = oldItem.Low; close = oldItem.Close; volume = oldItem.Volume; index = 0; while ((index < items.Count) && TimeFrameDurations.Start(Timeframe, date) == TimeFrameDurations.Start(Timeframe, items[index].Date)) { //date = items[index].Date; high = Math.Max(high, items[index].High); low = Math.Min(low, items[index].Low); close = items[index].Close; volume += items[index].Volume; index++; } IDataItem newItem = new DataItem(date, open, high, low, close, volume); _dataItems[_dataItems.Count - 1] = newItem; OnDataChanged(oldItem, newItem); } else index = 0; if (index < items.Count) newItems = new List<IDataItem>(); while(index < items.Count) { //date = items[index].Date; date = TimeFrameDurations.Start(Timeframe, items[index].Date); date = items[index].Date; open = items[index].Open; high = items[index].High; low = items[index].Low; close = items[index].Close; volume = items[index].Volume; index++; while ((index < items.Count) && TimeFrameDurations.Start(Timeframe, date) == TimeFrameDurations.Start(Timeframe, items[index].Date)) { //date = items[index].Date; high = Math.Max(high, items[index].High); low = Math.Min(low, items[index].Low); close = items[index].Close; volume += items[index].Volume; index++; } newItems.Add(new DataItem(date, open, high, low, close, volume)); } if ((newItems != null) && (newItems.Count > 0)) OnDataAdded(newItems); }
public void AddData(IDataItem item) { if ((_dataItems.Count > 0) && TimeFrameDurations.Start(Timeframe, _dataItems[_dataItems.Count - 1].Date) == TimeFrameDurations.Start(Timeframe, item.Date)) { IDataItem oldItem = _dataItems[_dataItems.Count - 1]; IDataItem newItem = new DataItem(TimeFrameDurations.Start(Timeframe, item.Date), oldItem.Open, Math.Max(oldItem.High, item.High), Math.Min(oldItem.Low, item.Low), item.Close); _dataItems[_dataItems.Count - 1] = newItem; OnDataChanged(oldItem, newItem); } else { List<IDataItem> items = new List<IDataItem>(); items.Add(item); OnDataAdded(items); } }