using System; namespace QuanTAlib; /// /// Abstract base class for all indicators. /// Enforces a consistent contract for State, Name, WarmupPeriod, and core methods. /// public abstract class AbstractBase : ITValuePublisher { /// /// Display name for the indicator. /// public string Name { get; protected set; } = string.Empty; /// /// Number of periods before the indicator is considered "hot" (valid). /// public int WarmupPeriod { get; protected set; } /// /// Current value of the indicator. /// public TValue Last { get; protected set; } /// /// True if the indicator has enough data to produce valid results. /// public abstract bool IsHot { get; } /// /// Event triggered when a new TValue is available. /// public event TValuePublishedHandler? Pub; /// /// Helper to invoke the Pub event. /// protected void PubEvent(TValue value, bool isNew = true) { Pub?.Invoke(this, new TValueEventArgs { Value = value, IsNew = isNew }); } /// /// Initializes the indicator state using the provided history. /// /// Historical data public abstract void Prime(ReadOnlySpan source); /// /// Updates the indicator with a single value. /// /// Input value /// True if this is a new bar, False if it's an update to the last bar /// Updated value public abstract TValue Update(TValue input, bool isNew = true); /// /// Updates the indicator with a series of values. /// /// Input series /// Series of calculated values public abstract TSeries Update(TSeries source); /// /// Resets the indicator to its initial state. /// public abstract void Reset(); }