Class AbstractIncrementalRTIndicator

java.lang.Object
com.wualabs.qtsurfer.engine.indicators.core.AbstractRTIndicator
com.wualabs.qtsurfer.engine.indicators.core.AbstractIncrementalRTIndicator
All Implemented Interfaces:
Resettable, RTIndicator
Direct Known Subclasses:
AbstractDecorableIncrementalRTIndicator

public abstract class AbstractIncrementalRTIndicator extends AbstractRTIndicator
Base class for indicators that compute values incrementally from a stream of updates. Supports two modes: periodic (fixed-period tick-based) and non-periodic (incremental). In periodic mode, updates are batched into fixed-size periods and tickValue(int, boolean, boolean, double) is called on each tick; in non-periodic mode, nextValue(double, double) is called directly with the previous and new values.
  • Constructor Details

    • AbstractIncrementalRTIndicator

      public AbstractIncrementalRTIndicator()
    • AbstractIncrementalRTIndicator

      public AbstractIncrementalRTIndicator(int periods)
  • Method Details

    • reset

      public void reset()
      Specified by:
      reset in interface Resettable
      Overrides:
      reset in class AbstractRTIndicator
    • getPeriods

      public int getPeriods()
    • isPeriodic

      public boolean isPeriodic()
    • getPeriodCycles

      public long getPeriodCycles()
    • isReady

      public boolean isReady()
      A periodic indicator is ready after completing at least one full period cycle. Non-periodic indicators are always ready (they produce valid output immediately).
      Returns:
      true if the indicator has completed its warmup period
    • getLastUpdateValue

      public final double getLastUpdateValue()
    • update

      public double update(double newValue)
      Processes a new value through the incremental computation pipeline.

      Non-finite inputs (NaN or ±Infinity) are rejected up front — the previous output is held and no tick/period bookkeeping advances — so one bad tick can neither poison the accumulators nor freeze readiness (see AbstractRTIndicator.isPoison(double)).

      On the first accepted call, delegates to initValue(double) (non-periodic) or tickValue(int, boolean, boolean, double) with init=true (periodic). In periodic mode a period boundary is reached when the tick count within the current period equals the configured periods; the degenerate periods == 1 case therefore ends a period on every tick (including the first), so the indicator becomes ready immediately. In non-periodic mode, directly computes the next value from prev and new via prevNextValue(double).

      Specified by:
      update in interface RTIndicator
      Overrides:
      update in class AbstractRTIndicator
      Parameters:
      newValue - the new input value to process
      Returns:
      the computed indicator value after this update, or the held previous value if the input was non-finite
    • initValue

      protected double initValue(double initValue)
      Non periodic init value
      Parameters:
      initValue -
      Returns:
    • getPrevValue

      protected double getPrevValue()
    • tickValue

      protected double tickValue(int tick, boolean init, boolean endPeriod, double newValue)
      Hook for periodic mode updates, called once per tick within a period. Subclasses override this to implement period-aware logic (e.g., accumulate values within a period and compute the average at endPeriod). Default behavior delegates to initValue(double) on first tick or prevNextValue(double) for subsequent ticks.
      Parameters:
      tick - current tick index within the period (1-based)
      init - true only on the very first update of this indicator
      endPeriod - true when this tick completes the current period
      newValue - the new input value
      Returns:
      the computed value for this tick
    • nextValue

      protected abstract double nextValue(double prevValue, double newValue)
      Computes the next indicator value from the previous and new input values. This is the core calculation method that subclasses must implement.
      Parameters:
      prevValue - the previous indicator value (or last update value, depending on override)
      newValue - the new input value
      Returns:
      the computed indicator value
    • prevNextValue

      protected final double prevNextValue(double newValue)
      Invokes nextValue(double, double) with the current previous value and saves the raw input as lastUpdateValue for the next iteration.
      Parameters:
      newValue - the new input value
      Returns:
      the computed next value
    • setPeriods

      protected final void setPeriods(int periods)