Class SmaRTIndicator
java.lang.Object
com.wualabs.qtsurfer.engine.indicators.core.AbstractRTIndicator
com.wualabs.qtsurfer.engine.indicators.core.AbstractIncrementalRTIndicator
com.wualabs.qtsurfer.engine.indicators.core.AbstractDecorableIncrementalRTIndicator
com.wualabs.qtsurfer.engine.indicators.averages.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 Summary
ConstructorsConstructorDescriptionSmaRTIndicator(int periods) SmaRTIndicator(int periods, RTIndicator indicator) SmaRTIndicator(RTIndicator indicator) -
Method Summary
Modifier and TypeMethodDescriptionprotected doublenextValue(double prevValue, double newValue) Non-periodic (2-period) SMA: simple average of previous and new values.voidreset()Periods, averaging mode and source chain.protected doubletickValue(int tick, boolean init, boolean endPeriod, double newValue) Delegates to discrete or moving average tick computation based on the current mode.withDiscreteMode(boolean discreteMode) Methods inherited from class AbstractDecorableIncrementalRTIndicator
getIndicator, setClockSupplier, updateMethods inherited from class AbstractIncrementalRTIndicator
getLastUpdateValue, getPeriodCycles, getPeriods, getPrevValue, initValue, isPeriodic, isReady, prevNextValue, setPeriodsMethods inherited from class AbstractRTIndicator
equals, getDisplayHint, getMeta, getValue, hashCode, hide, isPoison, setValue, toString, toString, withDisplayHint, withMeta
-
Constructor Details
-
SmaRTIndicator
public SmaRTIndicator() -
SmaRTIndicator
public SmaRTIndicator(int periods) -
SmaRTIndicator
-
SmaRTIndicator
-
-
Method Details
-
withDiscreteMode
-
reset
public void reset()- Specified by:
resetin interfaceResettable- Overrides:
resetin classAbstractDecorableIncrementalRTIndicator
-
getWindowSeries
-
signature
Periods, averaging mode and source chain.discreteModebelongs 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:
signaturein interfaceCacheableRTIndicator- Returns:
- the identity, or
nullwhen 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:
tickValuein classAbstractIncrementalRTIndicator- 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 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:
nextValuein classAbstractDecorableIncrementalRTIndicator- Parameters:
prevValue- the previous indicator valuenewValue- the new input value- Returns:
- the 2-period simple moving average
-