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))
280 throw new ArgumentException($
"IndicatorBase.Update() 'input' expected to be of type {typeof(T)} but is of type {input.GetType()}");
283 _previousInput[input.
Symbol.
ID] = (T)input;
304 public bool Update(DateTime time, decimal value)
311 var suggestions =
new List<string>
319 suggestions.Add(
"Update(Tick)");
322 throw new NotSupportedException($
"{GetType().Name} does not support the `Update(DateTime, decimal)` method. Use one of the following methods instead: {string.Join(",
", suggestions)}");
331 _previousInput.Clear();
341 protected abstract decimal ComputeNextValue(T input);
371 if (ReferenceEquals(obj,
null))
return false;
372 var type = obj.GetType();
374 while (type !=
null && type != typeof(
object))
376 var cur = type.IsGenericType ? type.GetGenericTypeDefinition() : type;
379 return ReferenceEquals(
this, obj);
381 type = type.BaseType;
387 var converted = obj.ConvertInvariant<decimal>();
390 catch (InvalidCastException)
403 return base.GetHashCode();