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()}")]
235 private bool _loggedForwardOnlyIndicatorError;
238 private Dictionary<SecurityIdentifier, T> _previousInput =
new Dictionary<SecurityIdentifier, T>();
256 T _previousSymbolInput =
default(T);
257 if (_previousInput.TryGetValue(input.
Symbol.
ID, out _previousSymbolInput) && input.
EndTime < _previousSymbolInput.EndTime)
259 if (!_loggedForwardOnlyIndicatorError)
261 _loggedForwardOnlyIndicatorError =
true;
263 Log.
Error($
"IndicatorBase.Update(): This is a forward only indicator: {Name} Input: {input.EndTime:u} Previous: {_previousSymbolInput.EndTime:u}. It will not be updated with this input.");
267 if (!ReferenceEquals(input, _previousSymbolInput))
274 throw new ArgumentException($
"IndicatorBase.Update() 'input' expected to be of type {typeof(T)} but is of type {input.GetType()}");
276 _previousInput[input.
Symbol.
ID] = (T)input;
297 public bool Update(DateTime time, decimal value)
304 var suggestions =
new List<string>
312 suggestions.Add(
"Update(Tick)");
315 throw new NotSupportedException($
"{GetType().Name} does not support the `Update(DateTime, decimal)` method. Use one of the following methods instead: {string.Join(",
", suggestions)}");
324 _previousInput.Clear();
334 protected abstract decimal ComputeNextValue(T input);
364 if (ReferenceEquals(obj,
null))
return false;
365 var type = obj.GetType();
367 while (type !=
null && type != typeof(
object))
369 var cur = type.IsGenericType ? type.GetGenericTypeDefinition() : type;
372 return ReferenceEquals(
this, obj);
374 type = type.BaseType;
380 var converted = obj.ConvertInvariant<decimal>();
383 catch (InvalidCastException)
396 return base.GetHashCode();