Class RTIndicatorAdapter

java.lang.Object
com.wualabs.qtsurfer.engine.indicators.ta4j.RTIndicatorAdapter
All Implemented Interfaces:
Resettable, RTIndicator

public final class RTIndicatorAdapter extends Object implements RTIndicator
Adapts a TA4j indicator to a RTIndicator.

Always feeds the underlying BarSeries on each update(double) call using synthetic incremental timestamps to avoid syscalls and timestamp collisions.

  • Method Summary

    Modifier and Type
    Method
    Description
    double
     
    boolean
    Returns whether this indicator has received enough data to produce meaningful values.
    of(Function<org.ta4j.core.BarSeries, org.ta4j.core.Indicator<org.ta4j.core.num.Num>> indicatorFactory, int maxBarCount)
    Creates an adapter with a factory function, supporting reset().
    of(org.ta4j.core.Indicator<org.ta4j.core.num.Num> indicator)
    Convenience method for an already-constructed indicator.
    void
    Resets the adapter by rebuilding the bar series and re-applying the indicator factory.
    double
    update(double newValue)
    Appends a new bar to the underlying series and recalculates the indicator.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface RTIndicator

    getDisplayHint, getId, getMeta, isHidden, ro, update, update
  • Method Details

    • of

      public static RTIndicator of(Function<org.ta4j.core.BarSeries, org.ta4j.core.Indicator<org.ta4j.core.num.Num>> indicatorFactory, int maxBarCount)
      Creates an adapter with a factory function, supporting reset().
      Parameters:
      indicatorFactory - builds the ta4j indicator from a fresh series
      maxBarCount - maximum number of bars the series will retain
      Returns:
      a new RTIndicator backed by ta4j
    • of

      public static RTIndicator of(org.ta4j.core.Indicator<org.ta4j.core.num.Num> indicator)
      Convenience method for an already-constructed indicator. The adapter takes ownership of the indicator's series. reset() is a no-op since there is no factory to recreate the indicator.
      Parameters:
      indicator - a pre-built ta4j indicator
      Returns:
      a new RTIndicator backed by ta4j
    • isReady

      public boolean isReady()
      Description copied from interface: RTIndicator
      Returns whether this indicator has received enough data to produce meaningful values.

      During the warmup period, RTIndicator.getValue() may return 0 or a partial estimate that should not be used for trading decisions. Once this method returns true, the indicator's output is statistically valid.

      The default implementation returns true for backward compatibility. Indicators with warmup requirements should override this method.

      For composite indicators (e.g. Bollinger Bands, MACD), readiness is determined by the slowest internal component.

      Specified by:
      isReady in interface RTIndicator
      Returns:
      true if the indicator has completed its warmup period
    • getValue

      public double getValue()
      Specified by:
      getValue in interface RTIndicator
    • update

      public double update(double newValue)
      Appends a new bar to the underlying series and recalculates the indicator.

      Each call increments a monotonic tick counter to produce a synthetic timestamp (base + tickCount ms), avoiding system clock calls and guaranteeing uniqueness. Only the close price is populated; open/high/low are set to zero.

      Specified by:
      update in interface RTIndicator
      Parameters:
      newValue - the close price for the new bar
      Returns:
      the updated indicator value after appending the bar
    • reset

      public void reset()
      Resets the adapter by rebuilding the bar series and re-applying the indicator factory.

      The tick counter is zeroed so synthetic timestamps restart from the base epoch. If this adapter was created via of(Indicator), the factory simply returns the original indicator instance, making the reset a partial no-op on the indicator side.

      Specified by:
      reset in interface Resettable