Class AbstractIncrementalRTIndicator
- All Implemented Interfaces:
Resettable, RTIndicator
- Direct Known Subclasses:
AbstractDecorableIncrementalRTIndicator
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal doublelongintprotected doubleprotected doubleinitValue(double initValue) Non periodic init valuebooleanbooleanisReady()A periodic indicator is ready after completing at least one full period cycle.protected abstract doublenextValue(double prevValue, double newValue) Computes the next indicator value from the previous and new input values.protected final doubleprevNextValue(double newValue) InvokesnextValue(double, double)with the current previous value and saves the raw input aslastUpdateValuefor the next iteration.voidreset()protected final voidsetPeriods(int periods) protected doubletickValue(int tick, boolean init, boolean endPeriod, double newValue) Hook for periodic mode updates, called once per tick within a period.doubleupdate(double newValue) Processes a new value through the incremental computation pipeline.Methods inherited from class AbstractRTIndicator
equals, getDisplayHint, getMeta, getValue, hashCode, hide, isPoison, setValue, toString, toString, withDisplayHint, withMeta
-
Constructor Details
-
AbstractIncrementalRTIndicator
public AbstractIncrementalRTIndicator() -
AbstractIncrementalRTIndicator
public AbstractIncrementalRTIndicator(int periods)
-
-
Method Details
-
reset
public void reset()- Specified by:
resetin interfaceResettable- Overrides:
resetin classAbstractRTIndicator
-
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:
trueif 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) ortickValue(int, boolean, boolean, double)withinit=true(periodic). In periodic mode a period boundary is reached when the tick count within the current period equals the configuredperiods; the degenerateperiods == 1case 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 viaprevNextValue(double).- Specified by:
updatein interfaceRTIndicator- Overrides:
updatein classAbstractRTIndicator- 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 toinitValue(double)on first tick orprevNextValue(double)for subsequent ticks.- Parameters:
tick- current tick index within the period (1-based)init- true only on the very first update of this indicatorendPeriod- true when this tick completes the current periodnewValue- 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) InvokesnextValue(double, double)with the current previous value and saves the raw input aslastUpdateValuefor the next iteration.- Parameters:
newValue- the new input value- Returns:
- the computed next value
-
setPeriods
protected final void setPeriods(int periods)
-