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) – 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).
handle_trade_tick(self, TradeTick tick) → void
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 BollingerBands
Bases: Indicator
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.
handle_trade_tick(self, TradeTick tick) → void
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
class EfficiencyRatio
Bases: Indicator
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).
handle_trade_tick(self, TradeTick tick) → void
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
class FuzzyCandle
Bases: object
FuzzyCandle(CandleDirection direction, CandleSize size, CandleBodySize body_size, CandleWickSize upper_wick_size, CandleWickSize lower_wick_size)
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
Bases: Indicator
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).
handle_trade_tick(self, TradeTick tick) → void
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]
class KeltnerChannel
Bases: Indicator
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).
handle_trade_tick(self, TradeTick tick) → void
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
class KeltnerPosition
Bases: Indicator
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).
handle_trade_tick(self, TradeTick tick) → void
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
class MovingAverageConvergenceDivergence
Bases: Indicator
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.
- Parameters:
- fast_period (int) – The period for the fast moving average (> 0).
- slow_period (int) – The period for the slow moving average (> 0 & > fast_sma).
- ma_type (MovingAverageType) – The moving average type for the calculations.
- price_type (PriceType) – The specified price type for extracting values from quotes.
- 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.
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.
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
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.
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
class OnBalanceVolume
Bases: Indicator
OnBalanceVolume(int period=0)
An indicator which calculates the momentum of relative positive or negative volume.
- Parameters: period (int) – The period for the indicator, zero indicates no window (>= 0).
- Raises: ValueError – If period is negative (< 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).
handle_trade_tick(self, TradeTick tick) → void
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
class Pressure
Bases: Indicator
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).
- Parameters:
- period (int) – The period for the indicator (> 0).
- ma_type (MovingAverageType) – The moving average type for the calculations.
- atr_floor (double) – The ATR floor (minimum) output value for the indicator (>= 0.).
- Raises:
- ValueError – If period is not positive (> 0).
- ValueError – If atr_floor is negative (< 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).
handle_trade_tick(self, TradeTick tick) → void
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
class RateOfChange
Bases: Indicator
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.
- Parameters:
- period (int) – The period for the indicator.
- use_log (bool) – Use log returns for value calculation.
- Raises: ValueError – If period is not > 1.
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).
handle_trade_tick(self, TradeTick tick) → void
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
class RelativeStrengthIndex
Bases: Indicator
RelativeStrengthIndex(int period, ma_type: MovingAverageType = MovingAverageType.EXPONENTIAL)
An indicator which calculates a relative strength index (RSI) across a rolling window.
- Parameters:
- ma_type (int) – The moving average type for average gain/loss.
- period (MovingAverageType) – The rolling window period for the indicator.
- 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
Abstract method (implement in subclass).
handle_trade_tick(self, TradeTick tick) → void
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
Bases: Indicator
SpreadAnalyzer(InstrumentId instrument_id, int capacity) -> None
Provides various spread analysis metrics.
- Parameters:
- instrument_id (InstrumentId) – The instrument ID for the tick updates.
- capacity (int) – The max length for the internal QuoteTick deque (determines averages).
- Raises: ValueError – If capacity is not positive (> 0).
average
The current average spread.
- Returns: double
capacity
The indicators spread capacity.
- Returns: int
current
The current spread.
- 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.
handle_trade_tick(self, TradeTick tick) → void
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.
class Stochastics
Bases: Indicator
Stochastics(int period_k, int period_d)
An oscillator which can indicate when an asset may be over bought or over sold.
- Parameters:
- period_k (int) – The period for the K line.
- period_d (int) – The period for the D line.
- Raises:
- ValueError – If period_k is not positive (> 0).
- ValueError – If period_d 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
Abstract method (implement in subclass).
handle_trade_tick(self, TradeTick tick) → void
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
class Swings
Bases: Indicator
Swings(int period)
A swing indicator which calculates and stores various swing metrics.
- Parameters: period (int) – The rolling window period for the indicator (> 0).
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).
handle_trade_tick(self, TradeTick tick) → void
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.
class VolatilityRatio
Bases: Indicator
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).
handle_trade_tick(self, TradeTick tick) → void
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
class VolumeWeightedAveragePrice
Bases: Indicator
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).
handle_trade_tick(self, TradeTick tick) → void
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
class MovingAverage
Bases: Indicator
MovingAverage(int period, list params, PriceType price_type)
The 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 quotes.
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).
handle_trade_tick(self, TradeTick tick) → void
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 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 MovingAverageType
Bases: Enum
Represents the type of moving average.
SIMPLE = 0
EXPONENTIAL = 1
WEIGHTED = 2
HULL = 3
ADAPTIVE = 4
WILDER = 5
DOUBLE_EXPONENTIAL = 6
VARIABLE_INDEX_DYNAMIC = 7
class Indicator
Bases: object
Indicator(list params)
The 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).
handle_trade_tick(self, TradeTick tick) → void
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.