# 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.

## Adaptive Moving Average (AMA) ¶

class 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 quote ticks.

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.

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 quote ticks.

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

## Exponential Moving Average (EMA) ¶

class 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 quote ticks.

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.

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 quote ticks.

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

## Donchian Channel ¶

class 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.

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

## Hull Moving Average (HMA) ¶

class 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 quote ticks.

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.

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 quote ticks.

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

## Moving Average Factory ¶

class MovingAverageFactory

Bases:  object 

Provides a factory to construct different moving average indicators.

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

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.

Returns

MovingAverage

Raises

ValueError – If period is not positive (> 0).

## Simple Moving Average (SMA) ¶

class 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 quote ticks.

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.

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 quote ticks.

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

## Weighted Moving Average (WMA) ¶

class 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 quote ticks.

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.

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 quote ticks.

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]

## Average True Range (ATR) ¶

class 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 ) – The boolean flag indicating whether previous price values should be used. (note: only applicable for update() . update_mid() will need to use previous price.

• value_floor ( double ) – The floor (minimum) output value for the indicator (>= 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

Abstract method (implement in subclass).

Abstract method (implement in subclass).

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 window period.

Returns

int

reset ( self ) void

Reset the indicator.

All stateful fields are reset to their initial value.

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

Update the indicator with the given raw values.

Parameters
• high ( double ) – The high price.

• low ( double ) – The low price.

• close ( double ) – The close price.

value

The current value.

Returns

double

class BidAskMinMax ( InstrumentId instrument_id , timedelta lookback )

Given a historic lookback window of bid/ask prices, keep a running computation of the min/max values of the bid/ask prices within the window.

Parameters
• instrument_id ( InstrumentId ) – The instrument ID for inbound ticks.

• lookback ( timedelta ) – The look back duration in time.

The windowed min max prices.

Returns

WindowedMinMaxPrices

bids

The windowed min max prices.

Returns

WindowedMinMaxPrices

handle_bar ( self , Bar bar ) void

Abstract method (implement in subclass).

handle_quote_tick ( self , QuoteTick tick ) void

Update the indicator with the given tick.

Parameters

tick ( QuoteTick ) – Incoming quote tick to process

Abstract method (implement in subclass).

has_inputs

If the indicator has received inputs.

Returns

bool

initialized

If the indicator is warmed up and initialized.

Returns

bool

instrument_id

The instrument_id for inbound ticks.

Returns

InstrumentId

lookback

The look back duration in time.

Returns

timedelta

name

The name of the indicator.

Returns

str

reset ( self ) void

Reset the indicator.

All stateful fields are reset to their initial value.

class WindowedMinMaxPrices ( timedelta lookback )

Bases:  object 

Over the course of a defined lookback window, efficiently keep track of the min/max values currently in the window.

Parameters

lookback ( timedelta ) – The look back duration in time.

add_price ( self , datetime ts , Price price ) void

Given a price at a UTC timestamp, insert it into the structures and update our running min/max values.

Parameters
• ts ( datetime ) – The timestamp for the price.

• price ( Price ) – The price to add.

lookback

The look back duration in time.

Returns

timedelta

max_price

The maximum price in the window.

Returns

Price

min_price

The minimum price in the window.

Returns

Price

reset ( self ) void

Reset the indicator.

All stateful fields are reset to their initial value.

## Bollinger Bands ¶

class BollingerBands ( int period , double k , ma_type: MovingAverageType = MovingAverageType.SIMPLE )

A Bollinger Band® is a technical analysis tool defined by a set of trend lines plotted two standard deviations (positively and negatively) away from a simple moving average (SMA) of an instruments price, which can be adjusted to user preferences.

Parameters
• period ( int ) – The rolling window period for the indicator (> 0).

• k ( double ) – The standard deviation multiple for the indicator (> 0).

• ma_type ( MovingAverageType ) – The moving average type for the indicator.

Raises
• ValueError – If period is not positive (> 0).

• ValueError – If k 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 tick.

Parameters

tick ( TradeTick ) – The tick for the update.

Update the indicator with the given tick.

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

k

The standard deviation multiple.

Returns

double

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 , double close ) void

Update the indicator with the given prices.

Parameters
• high ( double ) – The high price for calculations.

• low ( double ) – The low price for calculations.

• close ( double ) – The closing price for calculations

upper

The current value of the upper band.

Returns

double

## Efficiency Ratio ¶

class EfficiencyRatio ( int period )

An indicator which calculates the efficiency ratio across a rolling window. The Kaufman Efficiency measures the ratio of the relative market speed in relation to the volatility, this could be thought of as a proxy for noise.

Parameters

period ( int ) – The rolling window period for the indicator (>= 2).

Raises

ValueError – If period is not >= 2.

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

Abstract method (implement in subclass).

Abstract method (implement in subclass).

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 window period.

Returns

int

reset ( self ) void

Reset the indicator.

All stateful fields are reset to their initial value.

update_raw ( self , double price ) void

Update the indicator with the given price.

Parameters

price ( double ) – The update price.

value

The current value.

Returns

double

## Fuzzy Candlesticks ¶

class FuzzyCandle ( CandleDirection direction , CandleSize size , CandleBodySize body_size , CandleWickSize upper_wick_size , CandleWickSize lower_wick_size )

Bases:  object 

Represents a fuzzy candle.

Parameters
• direction ( CandleDirection ) – The candle direction.

• size ( CandleSize ) – The candle fuzzy size.

• body_size ( CandleBodySize ) – The candle fuzzy body size.

• upper_wick_size ( CandleWickSize ) – The candle fuzzy upper wick size.

• lower_wick_size ( CandleWickSize ) – The candle fuzzy lower wick size.

body_size

The candles fuzzy body size.

Returns

CandleBodySize

direction

The candles close direction.

Returns

CandleDirection

lower_wick_size

The candles fuzzy lower wick size.

Returns

CandleWickSize

size

The candles fuzzy overall size.

Returns

CandleSize

upper_wick_size

The candles fuzzy upper wick size.

Returns

CandleWickSize

class FuzzyCandlesticks ( int period , double threshold1=0.5 , double threshold2=1.0 , double threshold3=2.0 , double threshold4=3.0 )

An indicator which fuzzifies bar data to produce fuzzy candlesticks. Bar data is dimensionally reduced via fuzzy feature extraction.

Parameters
• period ( int ) – The rolling window period for the indicator (> 0).

• threshold1 ( float ) – The membership function x threshold1 (>= 0).

• threshold2 ( float ) – The membership function x threshold2 (> threshold1).

• threshold3 ( float ) – The membership function x threshold3 (> threshold2).

• threshold4 ( float ) – The membership function x threshold4 (> threshold3).

handle_bar ( self , Bar bar ) void

Update the indicator with the given bar.

Parameters

bar. ( The update ) –

handle_quote_tick ( self , QuoteTick tick ) void

Abstract method (implement in subclass).

Abstract method (implement in subclass).

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 window period.

Returns

int

reset ( self ) void

Reset the indicator.

All stateful fields are reset to their initial value.

update_raw ( self , double open , double high , double low , double close ) void

Update the indicator with the given raw values.

Parameters
• open ( double ) – The open price.

• high ( double ) – The high price.

• low ( double ) – The low price.

• close ( double ) – The close price.

value

The last fuzzy candle.

Returns

FuzzyCandle

vector

The fuzzy candle represented as a vector of ints.

Returns

list[int]

## Hilbert Period ¶

class HilbertPeriod ( int period=7 )

An indicator which calculates the instantaneous period of phase-change for a market across a rolling window. One basic definition of a cycle is that the phase has a constant rate of change, i.e. A 10 bar cycle changes phase at the rate of 36 degrees per bar so that 360 degrees of phase is completed (one full cycle) every 10 bars.

Parameters

period ( int ) – The rolling window period for the indicator (> 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

Abstract method (implement in subclass).

Abstract method (implement in subclass).

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 window period.

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 raw values.

Parameters
• high ( double ) – The high price.

• low ( double ) – The low price.

value

The current value.

Returns

double

## Hilbert Signal-Noise Ratio ¶

class HilbertSignalNoiseRatio ( int period=7 , double range_floor=0.00001 , double amplitude_floor=0.001 )

An indicator which calculates the amplitude of a signal.

Parameters
• period ( int ) – The rolling window period for the indicator (> 0).

• range_floor ( double ) – The floor value for range calculations.

• amplitude_floor ( double ) – The floor value for amplitude calculations (0.001 from paper).

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

Abstract method (implement in subclass).

Abstract method (implement in subclass).

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 window period.

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 raw values.

Parameters
• high ( double ) – The high price.

• low ( double ) – The low price.

value

The last amplitude value.

Returns

double

## Hilbert Transform ¶

class HilbertTransform ( int period=7 )

An indicator which calculates a Hilbert Transform across a rolling window. The Hilbert Transform itself, is an all-pass filter used in digital signal processing. By using present and prior price differences, and some feedback, price values are split into their complex number components of real (in-phase) and imaginary (quadrature) parts.

Parameters

period ( int ) – The rolling window period for the indicator (> 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

Abstract method (implement in subclass).

Abstract method (implement in subclass).

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 window period.

Returns

int

reset ( self ) void

Reset the indicator.

All stateful fields are reset to their initial value.

update_raw ( self , double price ) void

Update the indicator with the given raw value.

Parameters

price ( double ) – The price.

value_in_phase

The last in-phase value (real part of complex number).

Returns

double

The last quadrature value (imaginary part of complex number).

Returns

double

## Keltner Channel ¶

class KeltnerChannel ( int period , double k_multiplier , ma_type: MovingAverageType = MovingAverageType.EXPONENTIAL , ma_type_atr: MovingAverageType = MovingAverageType.SIMPLE , bool use_previous=True , double atr_floor=0 )

The Keltner channel is a volatility based envelope set above and below a central moving average. Traditionally the middle band is an EMA based on the typical price (high + low + close) / 3, the upper band is the middle band plus the ATR. The lower band is the middle band minus the ATR.

Parameters
• period ( int ) – The rolling window period for the indicator (> 0).

• k_multiplier ( double ) – The multiplier for the ATR (> 0).

• ma_type ( MovingAverageType ) – The moving average type for the middle band (cannot be None).

• ma_type_atr ( MovingAverageType ) – The moving average type for the internal ATR (cannot be None).

• use_previous ( bool ) – The boolean flag indicating whether previous price values should be used.

• atr_floor ( double ) – The ATR floor (minimum) output value for the indicator (>= 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

Abstract method (implement in subclass).

Abstract method (implement in subclass).

has_inputs

If the indicator has received inputs.

Returns

bool

initialized

If the indicator is warmed up and initialized.

Returns

bool

k_multiplier

The k multiplier.

Returns

double

lower

The current value of the lower channel.

Returns

double

middle

The current value of the middle channel.

Returns

double

name

The name of the indicator.

Returns

str

period

The window period.

Returns

int

reset ( self ) void

Reset the indicator.

All stateful fields are reset to their initial value.

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

Update the indicator with the given raw values.

Parameters
• high ( double ) – The high price.

• low ( double ) – The low price.

• close ( double ) – The close price.

upper

The current value of the upper channel.

Returns

double

## Keltner Position ¶

class KeltnerPosition ( int period , double k_multiplier , ma_type: MovingAverageType = MovingAverageType.EXPONENTIAL , ma_type_atr: MovingAverageType = MovingAverageType.SIMPLE , bool use_previous=True , double atr_floor=0 )

An indicator which calculates the relative position of the given price within a defined Keltner channel. This provides a measure of the relative ‘extension’ of a market from the mean, as a multiple of volatility.

Parameters
• period ( int ) – The rolling window period for the indicator (> 0).

• k_multiplier ( double ) – The multiplier for the ATR (> 0).

• ma_type ( MovingAverageType ) – The moving average type for the middle band (cannot be None).

• ma_type_atr ( MovingAverageType ) – The moving average type for the internal ATR (cannot be None).

• use_previous ( bool ) – The boolean flag indicating whether previous price values should be used.

• atr_floor ( double ) – The ATR floor (minimum) output value for the indicator (>= 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

Abstract method (implement in subclass).

Abstract method (implement in subclass).

has_inputs

If the indicator has received inputs.

Returns

bool

initialized

If the indicator is warmed up and initialized.

Returns

bool

k_multiplier

The K multiplier.

Returns

double

name

The name of the indicator.

Returns

str

period

The window period.

Returns

int

reset ( self ) void

Reset the indicator.

All stateful fields are reset to their initial value.

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

Update the indicator with the given raw value.

Parameters
• high ( double ) – The high price.

• low ( double ) – The low price.

• close ( double ) – The close price.

value

The current value.

Returns

double

## Moving Average Convergence Divergence (MACD) ¶

class MovingAverageConvergenceDivergence ( int fast_period , int slow_period , ma_type: MovingAverageType = MovingAverageType.EXPONENTIAL , PriceType price_type=PriceType.LAST )

An indicator which calculates the difference between two moving averages. Different moving average types can be selected for the inner calculation.

fast_period

The fast moving average window period.

Returns

int

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 quote tick.

Parameters

tick ( QuoteTick ) – The update tick to handle.

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

price_type

The specified price type for extracting values from quote ticks.

Returns

PriceType

reset ( self ) void

Reset the indicator.

All stateful fields are reset to their initial value.

slow_period

The slow moving average window period.

Returns

int

update_raw ( self , double close ) void

Update the indicator with the given close price.

Parameters

close ( double ) – The close price.

value

The current value.

Returns

double

## On Balance Volume (OBV) ¶

class OnBalanceVolume ( int period=0 )

An indicator which calculates the momentum of relative positive or negative volume.

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

Abstract method (implement in subclass).

Abstract method (implement in subclass).

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 window period.

Returns

int

reset ( self ) void

Reset the indicator.

All stateful fields are reset to their initial value.

update_raw ( self , double open , double close , double volume ) void

Update the indicator with the given raw values.

Parameters
• open ( double ) – The high price.

• close ( double ) – The low price.

• volume ( double ) – The close price.

value

The current value.

Returns

double

## Pressure ¶

class Pressure ( int period , ma_type: MovingAverageType = MovingAverageType.EXPONENTIAL , double atr_floor=0 )

An indicator which calculates the relative volume (multiple of average volume) to move the market across a relative range (multiple of ATR).

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

Abstract method (implement in subclass).

Abstract method (implement in subclass).

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 window period.

Returns

int

reset ( self ) void

Reset the indicator.

All stateful fields are reset to their initial value.

update_raw ( self , double high , double low , double close , double volume ) void

Update the indicator with the given raw values.

Parameters
• high ( double ) – The high price.

• low ( double ) – The low price.

• close ( double ) – The close price.

• volume ( double ) – The volume.

value

The current value.

Returns

int

value_cumulative

The cumulative value.

Returns

int

## Rate Of Change (ROC) ¶

class RateOfChange ( int period , bool use_log=False )

An indicator which calculates the rate of change of price over a defined period. The return output can be simple or log.

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

Abstract method (implement in subclass).

Abstract method (implement in subclass).

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 window period.

Returns

int

reset ( self ) void

Reset the indicator.

All stateful fields are reset to their initial value.

update_raw ( self , double price ) void

Update the indicator with the given price.

Parameters

price ( double ) – The update price.

value

The current value.

Returns

double

## Relative Strength Index (RSI) ¶

class RelativeStrengthIndex ( int period , ma_type: MovingAverageType = MovingAverageType.EXPONENTIAL )

An indicator which calculates a relative strength index (RSI) across a rolling window.

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

Abstract method (implement in subclass).

Abstract method (implement in subclass).

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 window period.

Returns

int

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 value.

Parameters

value ( double ) – The update value.

value

The current value.

Returns

double

class SpreadAnalyzer ( InstrumentId instrument_id , int capacity )

average

Returns

double

capacity

Returns

int

current

Returns

double

handle_bar ( self , Bar bar ) void

Abstract method (implement in subclass).

handle_quote_tick ( self , QuoteTick tick ) void

Update the analyzer with the given quote tick.

Parameters

tick ( QuoteTick ) – The tick for the update.

Raises

ValueError – If tick.instrument_id does not equal the analyzers instrument ID.

Abstract method (implement in subclass).

has_inputs

If the indicator has received inputs.

Returns

bool

initialized

If the indicator is warmed up and initialized.

Returns

bool

instrument_id

The indicators instrument ID.

Returns

InstrumentId

name

The name of the indicator.

Returns

str

reset ( self ) void

Reset the indicator.

All stateful fields are reset to their initial value.

## Stochastics ¶

class Stochastics ( int period_k , int period_d )

An oscillator which can indicate when an asset may be over bought or over sold.

References

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

Abstract method (implement in subclass).

Abstract method (implement in subclass).

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_d

The D window period.

Returns

int

period_k

The K window period.

Returns

int

reset ( self ) void

Reset the indicator.

All stateful fields are reset to their initial value.

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

Update the indicator with the given raw values.

Parameters
• high ( double ) – The high price.

• low ( double ) – The low price.

• close ( double ) – The close price.

value_d

The current D line value.

Returns

double

value_k

The current K line value..

Returns

double

## Swings ¶

class Swings ( int period )

A swing indicator which calculates and stores various swing metrics.

changed

If the swing direction changed at the last bar.

Returns

bool

direction

The current swing direction.

Returns

int

duration

The current swing duration.

Returns

int

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

Abstract method (implement in subclass).

Abstract method (implement in subclass).

has_inputs

If the indicator has received inputs.

Returns

bool

high_datetime

The last swing high time.

Returns

datetime

high_price

The last swing high price.

Returns

double

initialized

If the indicator is warmed up and initialized.

Returns

bool

length

The length of the current swing.

Returns

double

low_datetime

The last swing low time.

Returns

datetime

low_price

The last swing low price.

Returns

double

name

The name of the indicator.

Returns

str

period

The window period.

Returns

int

reset ( self ) void

Reset the indicator.

All stateful fields are reset to their initial value.

since_high

The bars since the last swing high.

Returns

int

since_low

The bars since the last swing low.

Returns

int

update_raw ( self , double high , double low , datetime timestamp ) void

Update the indicator with the given raw values.

Parameters
• high ( double ) – The high price.

• low ( double ) – The low price.

• timestamp ( datetime ) – The current timestamp.

## Volatility Ratio ¶

class VolatilityRatio ( int fast_period , int slow_period , ma_type: MovingAverageType = MovingAverageType.SIMPLE , bool use_previous=True , double value_floor=0 )

An indicator which calculates the ratio of different ranges of volatility. Different moving average types can be selected for the inner ATR calculations.

Parameters
• fast_period ( int ) – The period for the fast ATR (> 0).

• slow_period ( int ) – The period for the slow ATR (> 0 & > fast_period).

• ma_type ( MovingAverageType ) – The moving average type for the ATR calculations.

• use_previous ( bool ) – The boolean flag indicating whether previous price values should be used.

• value_floor ( double ) – The floor (minimum) output value for the indicator (>= 0).

Raises
• ValueError – If fast_period is not positive (> 0).

• ValueError – If slow_period is not positive (> 0).

• ValueError – If fast_period is not < slow_period .

• ValueError – If value_floor is negative (< 0).

fast_period

The period of the fast ATR.

Returns

int

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

Abstract method (implement in subclass).

Abstract method (implement in subclass).

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

reset ( self ) void

Reset the indicator.

All stateful fields are reset to their initial value.

slow_period

The period of the slow ATR.

Returns

int

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

Update the indicator with the given raw value.

Parameters
• high ( double ) – The high price.

• low ( double ) – The low price.

• close ( double ) – The close price.

value

The current value.

Returns

double

## VWAP ¶

class VolumeWeightedAveragePrice

An indicator which calculates the volume weighted average price for the day.

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

Abstract method (implement in subclass).

Abstract method (implement in subclass).

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

reset ( self ) void

Reset the indicator.

All stateful fields are reset to their initial value.

update_raw ( self , double price , double volume , datetime timestamp ) void

Update the indicator with the given raw values.

Parameters
• price ( double ) – The update price.

• volume ( double ) – The update volume.

• timestamp ( datetime ) – The current timestamp.

value

The current value.

Returns

double

## Moving Average (Base) ¶

class MovingAverage ( int period , list params , PriceType price_type )

The abstract base class for all moving average type indicators.

Parameters
• period ( int ) – The rolling window period for the indicator (> 0).

• params ( list ) – The initialization parameters for the indicator.

• price_type ( PriceType , optional ) – The specified price type for extracting values from quote ticks.

Warning

This class should not be used directly, but through a concrete subclass.

count

The count of inputs received by the indicator.

Returns

int

handle_bar ( self , Bar bar ) void

Abstract method (implement in subclass).

handle_quote_tick ( self , QuoteTick tick ) void

Abstract method (implement in subclass).

Abstract method (implement in subclass).

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 quote ticks.

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 MovingAverageType ( value )

Bases:  enum.Enum 

Represents the type of moving average.

## Indicator (Base) ¶

class Indicator ( list params )

Bases:  object 

The abstract base class for all indicators.

Parameters

params ( list ) – The initialization parameters for the indicator.

Warning

This class should not be used directly, but through a concrete subclass.

handle_bar ( self , Bar bar ) void

Abstract method (implement in subclass).

handle_quote_tick ( self , QuoteTick tick ) void

Abstract method (implement in subclass).

Abstract method (implement in subclass).

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

reset ( self ) void

Reset the indicator.

All stateful fields are reset to their initial value.