Skip to main content
Version: latest

Indicators

The indicator subpackage provides a set of efficient indicators and analyzers.

These are classes which can be used for signal discovery and filtering. The idea is to use the provided indicators as is, or as inspiration for a trader to implement their own proprietary indicator algorithms with the platform.

class AdaptiveMovingAverage

Bases: MovingAverage

AdaptiveMovingAverage(int period_er, int period_alpha_fast, int period_alpha_slow, PriceType price_type=PriceType.LAST) An indicator which calculates an adaptive moving average (AMA) across a rolling window. Developed by Perry Kaufman, the AMA is a moving average designed to account for market noise and volatility. The AMA will closely follow prices when the price swings are relatively small and the noise is low. The AMA will increase lag when the price swings increase.

  • Parameters:
    • period_er (int) – The period for the internal EfficiencyRatio indicator (> 0).
    • period_alpha_fast (int) – The period for the fast smoothing constant (> 0).
    • period_alpha_slow (int) – The period for the slow smoothing constant (> 0 < alpha_fast).
    • price_type (PriceType) – The specified price type for extracting values from quotes.

alpha_diff

The alpha difference value.

  • Returns: double

alpha_fast

The alpha fast value.

  • Returns: double

alpha_slow

The alpha slow value.

  • Returns: double

count

The count of inputs received by the indicator.

  • Returns: int

handle_bar(self, Bar bar) → void

Update the indicator with the given bar.

  • Parameters: bar (Bar) – The update bar to handle.

handle_quote_tick(self, QuoteTick tick) → void

Update the indicator with the given quote tick.

  • Parameters: tick (QuoteTick) – The update tick to handle.

handle_trade_tick(self, TradeTick tick) → void

Update the indicator with the given trade tick.

  • Parameters: tick (TradeTick) – The update tick to handle.

has_inputs

If the indicator has received inputs.

  • Returns: bool

initialized

If the indicator is warmed up and initialized.

  • Returns: bool

name

The name of the indicator.

  • Returns: str

period

The moving average period.

  • Returns: PriceType

period_alpha_fast

The period of the fast smoothing constant.

  • Returns: double

period_alpha_slow

The period of the slow smoothing constant.

  • Returns: double

period_er

The period of the internal EfficiencyRatio indicator.

  • Returns: double

price_type

The specified price type for extracting values from quotes.

  • Returns: PriceType

reset(self) → void

Reset the indicator.

All stateful fields are reset to their initial value.

update_raw(self, double value) → void

Update the indicator with the given raw value.

  • Parameters: value (double) – The update value.

value

The current output value.

  • Returns: double

class ExponentialMovingAverage

Bases: MovingAverage

ExponentialMovingAverage(int period, PriceType price_type=PriceType.LAST) An indicator which calculates an exponential moving average across a rolling window.

  • Parameters:
    • period (int) – The rolling window period for the indicator (> 0).
    • price_type (PriceType) – The specified price type for extracting values from quotes.
  • Raises: ValueError – If period is not positive (> 0).

alpha

The moving average alpha value.

  • Returns: double

count

The count of inputs received by the indicator.

  • Returns: int

handle_bar(self, Bar bar) → void

Update the indicator with the given bar.

  • Parameters: bar (Bar) – The update bar to handle.

handle_quote_tick(self, QuoteTick tick) → void

Update the indicator with the given quote tick.

  • Parameters: tick (QuoteTick) – The update tick to handle.

handle_trade_tick(self, TradeTick tick) → void

Update the indicator with the given trade tick.

  • Parameters: tick (TradeTick) – The update tick to handle.

has_inputs

If the indicator has received inputs.

  • Returns: bool

initialized

If the indicator is warmed up and initialized.

  • Returns: bool

name

The name of the indicator.

  • Returns: str

period

The moving average period.

  • Returns: PriceType

price_type

The specified price type for extracting values from quotes.

  • Returns: PriceType

reset(self) → void

Reset the indicator.

All stateful fields are reset to their initial value.

update_raw(self, double value) → void

Update the indicator with the given raw value.

  • Parameters: value (double) – The update value.

value

The current output value.

  • Returns: double

class DonchianChannel

Bases: Indicator

DonchianChannel(int period) Donchian Channels are three lines generated by moving average calculations that comprise an indicator formed by upper and lower bands around a mid-range or median band. The upper band marks the highest price of a instrument_id over N periods while the lower band marks the lowest price of a instrument_id over N periods. The area between the upper and lower bands represents the Donchian Channel.

  • Parameters: period (int) – The rolling window period for the indicator (> 0).
  • Raises: ValueError – If period is not positive (> 0).

handle_bar(self, Bar bar) → void

Update the indicator with the given bar.

  • Parameters: bar (Bar) – The update bar.

handle_quote_tick(self, QuoteTick tick) → void

Update the indicator with the given ticks high and low prices.

  • Parameters: tick (TradeTick) – The tick for the update.

handle_trade_tick(self, TradeTick tick) → void

Update the indicator with the given ticks price.

  • Parameters: tick (TradeTick) – The tick for the update.

has_inputs

If the indicator has received inputs.

  • Returns: bool

initialized

If the indicator is warmed up and initialized.

  • Returns: bool

lower

The current value of the lower band.

  • Returns: double

middle

The current value of the middle band.

  • Returns: double

name

The name of the indicator.

  • Returns: str

period

The period for the moving average.

  • Returns: int

reset(self) → void

Reset the indicator.

All stateful fields are reset to their initial value.

update_raw(self, double high, double low) → void

Update the indicator with the given prices.

  • Parameters:
    • high (double) – The price for the upper channel.
    • low (double) – The price for the lower channel.

upper

The current value of the upper band.

  • Returns: double

class HullMovingAverage

Bases: MovingAverage

HullMovingAverage(int period, PriceType price_type=PriceType.LAST) An indicator which calculates a Hull Moving Average (HMA) across a rolling window. The HMA, developed by Alan Hull, is an extremely fast and smooth moving average.

  • Parameters:
    • period (int) – The rolling window period for the indicator (> 0).
    • price_type (PriceType) – The specified price type for extracting values from quotes.
  • Raises: ValueError – If period is not positive (> 0).

count

The count of inputs received by the indicator.

  • Returns: int

handle_bar(self, Bar bar) → void

Update the indicator with the given bar.

  • Parameters: bar (Bar) – The update bar to handle.

handle_quote_tick(self, QuoteTick tick) → void

Update the indicator with the given quote tick.

  • Parameters: tick (QuoteTick) – The update tick to handle.

handle_trade_tick(self, TradeTick tick) → void

Update the indicator with the given trade tick.

  • Parameters: tick (TradeTick) – The update tick to handle.

has_inputs

If the indicator has received inputs.

  • Returns: bool

initialized

If the indicator is warmed up and initialized.

  • Returns: bool

name

The name of the indicator.

  • Returns: str

period

The moving average period.

  • Returns: PriceType

price_type

The specified price type for extracting values from quotes.

  • Returns: PriceType

reset(self) → void

Reset the indicator.

All stateful fields are reset to their initial value.

update_raw(self, double value) → void

Update the indicator with the given raw value.

  • Parameters: value (double) – The update value.

value

The current output value.

  • Returns: double

class MovingAverageFactory

Bases: object

Provides a factory to construct different moving average indicators.

static create(int period, ma_type: MovingAverageType, **kwargs) → MovingAverage

Create a moving average indicator corresponding to the given ma_type.

  • Parameters:
    • period (int) – The period of the moving average (> 0).
    • ma_type (MovingAverageType) – The moving average type.
  • Return type: MovingAverage
  • Raises: ValueError – If period is not positive (> 0).

class SimpleMovingAverage

Bases: MovingAverage

SimpleMovingAverage(int period, PriceType price_type=PriceType.LAST) An indicator which calculates a simple moving average across a rolling window.

  • Parameters:
    • period (int) – The rolling window period for the indicator (> 0).
    • price_type (PriceType) – The specified price type for extracting values from quotes.
  • Raises: ValueError – If period is not positive (> 0).

count

The count of inputs received by the indicator.

  • Returns: int

handle_bar(self, Bar bar) → void

Update the indicator with the given bar.

  • Parameters: bar (Bar) – The update bar to handle.

handle_quote_tick(self, QuoteTick tick) → void

Update the indicator with the given quote tick.

  • Parameters: tick (QuoteTick) – The update tick to handle.

handle_trade_tick(self, TradeTick tick) → void

Update the indicator with the given trade tick.

  • Parameters: tick (TradeTick) – The update tick to handle.

has_inputs

If the indicator has received inputs.

  • Returns: bool

initialized

If the indicator is warmed up and initialized.

  • Returns: bool

name

The name of the indicator.

  • Returns: str

period

The moving average period.

  • Returns: PriceType

price_type

The specified price type for extracting values from quotes.

  • Returns: PriceType

reset(self) → void

Reset the indicator.

All stateful fields are reset to their initial value.

update_raw(self, double value) → void

Update the indicator with the given raw value.

  • Parameters: value (double) – The update value.

value

The current output value.

  • Returns: double

class WeightedMovingAverage

Bases: MovingAverage

WeightedMovingAverage(int period, weights=None, PriceType price_type=PriceType.LAST) An indicator which calculates a weighted moving average across a rolling window.

  • Parameters:
    • period (int) – The rolling window period for the indicator (> 0).
    • weights (iterable) – The weights for the moving average calculation (if not None then = period).
    • price_type (PriceType) – The specified price type for extracting values from quotes.
  • Raises: ValueError – If period is not positive (> 0).

count

The count of inputs received by the indicator.

  • Returns: int

handle_bar(self, Bar bar) → void

Update the indicator with the given bar.

  • Parameters: bar (Bar) – The update bar to handle.

handle_quote_tick(self, QuoteTick tick) → void

Update the indicator with the given quote tick.

  • Parameters: tick (QuoteTick) – The update tick to handle.

handle_trade_tick(self, TradeTick tick) → void

Update the indicator with the given trade tick.

  • Parameters: tick (TradeTick) – The update tick to handle.

has_inputs

If the indicator has received inputs.

  • Returns: bool

initialized

If the indicator is warmed up and initialized.

  • Returns: bool

name

The name of the indicator.

  • Returns: str

period

The moving average period.

  • Returns: PriceType

price_type

The specified price type for extracting values from quotes.

  • Returns: PriceType

reset(self) → void

Reset the indicator.

All stateful fields are reset to their initial value.

update_raw(self, double value) → void

Update the indicator with the given raw value.

  • Parameters: value (double) – The update value.

value

The current output value.

  • Returns: double

weights

The weights for the moving average calculation.

  • Returns: np.ndarray[float64]

class AverageTrueRange

Bases: Indicator

AverageTrueRange(int period, ma_type: MovingAverageType = MovingAverageType.SIMPLE, bool use_previous=True, double value_floor=0) An indicator which calculates the average true range across a rolling window. Different moving average types can be selected for the inner calculation.

  • Parameters:
    • period (int) – The rolling window period for the indicator (> 0).
    • ma_type (MovingAverageType) – The moving average type for the indicator (cannot be None).
    • use_previous (bool)