Class SmaRTIndicator

All Implemented Interfaces:
ClockAware, Resettable, CacheableRTIndicator, RTIndicator

public class SmaRTIndicator extends AbstractDecorableIncrementalRTIndicator implements CacheableRTIndicator
Simple 2-period and N periods SMA RT Indicator
  • Constructor Details

    • SmaRTIndicator

      public SmaRTIndicator()
    • SmaRTIndicator

      public SmaRTIndicator(int periods)
    • SmaRTIndicator

      public SmaRTIndicator(RTIndicator indicator)
    • SmaRTIndicator

      public SmaRTIndicator(int periods, RTIndicator indicator)
  • Method Details

    • withDiscreteMode

      public SmaRTIndicator withDiscreteMode(boolean discreteMode)
    • reset

      public void reset()
      Specified by:
      reset in interface Resettable
      Overrides:
      reset in class AbstractDecorableIncrementalRTIndicator
    • getWindowSeries

      public WindowSeries getWindowSeries()
    • signature

      public String signature()
      Periods, averaging mode and source chain.

      discreteMode belongs here as much as the periods do: it selects between two genuinely different value series, and unlike the periods it is set after construction, which is exactly the shape of parameter a memoization key is most likely to forget. The signature is read when the indicator is registered, so reconfigure before registering, not after.

      Specified by:
      signature in interface CacheableRTIndicator
      Returns:
      the identity, or null when this instance cannot state one (an unidentifiable source, a mode the implementation does not model) and must therefore compute live
    • tickValue

      protected double tickValue(int tick, boolean init, boolean endPeriod, double newValue)
      Delegates to discrete or moving average tick computation based on the current mode.
      Overrides:
      tickValue in class AbstractIncrementalRTIndicator
      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 double nextValue(double prevValue, double newValue)
      Non-periodic (2-period) SMA: simple average of previous and new values. Used when periods=0 (no fixed period configured).
      Overrides:
      nextValue in class AbstractDecorableIncrementalRTIndicator
      Parameters:
      prevValue - the previous indicator value
      newValue - the new input value
      Returns:
      the 2-period simple moving average