18 using System.Diagnostics;
20 using System.Collections.Generic;
22 using System.Collections;
36 public ISet<IDataConsolidator>
Consolidators {
get; } =
new HashSet<IDataConsolidator>();
69 public string Name {
get;
protected set; }
74 public long Samples {
get;
internal set; }
94 public abstract void Reset();
121 Updated?.Invoke(
this, consolidated);
130 public abstract bool Update(
IBaseData input);
166 IEnumerator IEnumerable.GetEnumerator()
168 return GetEnumerator();
177 return Current.
Value.ToStringInvariant(
"#######0.0####");
186 return $
"{Name} - {this}";
198 if (ReferenceEquals(other,
null))
219 throw new ArgumentException(
"Object must be of type " + GetType().GetBetterTypeName());
231 [DebuggerDisplay(
"{ToDetailedString()}")]
237 private Dictionary<SecurityIdentifier, T> _previousInput =
new Dictionary<SecurityIdentifier, T>();
255 T _previousSymbolInput =
default(T);
256 if (_previousInput.TryGetValue(input.
Symbol.
ID, out _previousSymbolInput) && input.
EndTime < _previousSymbolInput.EndTime)
259 Log.
Error($
"This is a forward only indicator: {Name} Input: {input.EndTime:u} Previous: {_previousSymbolInput.EndTime:u}. It will not be updated with this input.");
262 if (!ReferenceEquals(input, _previousSymbolInput))
269 throw new ArgumentException($
"IndicatorBase.Update() 'input' expected to be of type {typeof(T)} but is of type {input.GetType()}");
271 _previousInput[input.
Symbol.
ID] = (T)input;
292 public bool Update(DateTime time, decimal value)
299 var suggestions =
new List<string>
307 suggestions.Add(
"Update(Tick)");
310 throw new NotSupportedException($
"{GetType().Name} does not support the `Update(DateTime, decimal)` method. Use one of the following methods instead: {string.Join(",
", suggestions)}");
319 _previousInput.Clear();
329 protected abstract decimal ComputeNextValue(T input);
359 if (ReferenceEquals(obj,
null))
return false;
360 var type = obj.GetType();
362 while (type !=
null && type != typeof(
object))
364 var cur = type.IsGenericType ? type.GetGenericTypeDefinition() : type;
367 return ReferenceEquals(
this, obj);
369 type = type.BaseType;
375 var converted = obj.ConvertInvariant<decimal>();
378 catch (InvalidCastException)
391 return base.GetHashCode();