Indicators - Loren1166/NautilusTrader- GitHub Wiki
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
class AdaptiveMovingAverage(MovingAverage):
"""
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.
一个指标,用于计算滚动窗口内的自适应移动平均线 (AMA)。由 Perry Kaufman 开发的 AMA 是一种移动平均线,旨在考虑市场噪音和波动性。当价格波动相对较小且噪音较低时,AMA 将紧跟价格。当价格波动增加时,AMA 将增加滞后。
Parameters:
参数:
period_er (int) – The period for the internal EfficiencyRatio indicator (> 0).
period_er (int) - 内部 EfficiencyRatio 指标的周期 (> 0)。
period_alpha_fast (int) – The period for the fast smoothing constant (> 0).
period_alpha_fast (int) - 快速平滑常数的周期 (> 0)。
period_alpha_slow (int) – The period for the slow smoothing constant (> 0 < alpha_fast).
period_alpha_slow (int) - 慢速平滑常数的周期 (> 0 < alpha_fast)。
price_type (PriceType) – The specified price type for extracting values from quote ticks.
price_type (PriceType) - 用于从报价行情中提取值的指定价格类型。
"""
def __init__(self, period_er: int, period_alpha_fast: int, period_alpha_slow: int, price_type: PriceType = PriceType.LAST):
...
Properties 属性
@property
def alpha_diff(self) -> float:
"""
The alpha difference value.
alpha 差值。
Returns:
double
"""
...
@property
def alpha_fast(self) -> float:
"""
The alpha fast value.
alpha 快速值。
Returns:
double
"""
...
@property
def alpha_slow(self) -> float:
"""
The alpha slow value.
alpha 慢速值。
Returns:
double
"""
...
@property
def count(self) -> int:
"""
The count of inputs received by the indicator.
指标接收的输入计数。
Returns:
int
"""
...
@property
def has_inputs(self):
"""
If the indicator has received inputs.
指标是否已接收输入。
Returns:
bool
"""
...
@property
def initialized(self):
"""
If the indicator is warmed up and initialized.
指标是否已预热并初始化。
Returns:
bool
"""
...
@property
def name(self) -> str:
"""
The name of the indicator.
指标的名称。
Returns:
str
"""
...
@property
def period(self):
"""
The moving average period.
移动平均线周期。
Returns:
PriceType
"""
...
@property
def period_alpha_fast(self) -> float:
"""
The period of the fast smoothing constant.
快速平滑常数的周期。
Returns:
double
"""
...
@property
def period_alpha_slow(self) -> float:
"""
The period of the slow smoothing constant.
慢速平滑常数的周期。
Returns:
double
"""
...
@property
def period_er(self) -> float:
"""
The period of the internal EfficiencyRatio indicator.
内部 EfficiencyRatio 指标的周期。
Returns:
double
"""
...
@property
def price_type(self):
"""
The specified price type for extracting values from quote ticks.
用于从报价行情中提取值的指定价格类型。
Returns:
PriceType
"""
...
@property
def value(self) -> float:
"""
The current output value.
当前输出值。
Returns:
double
"""
...
Methods 方法
def handle_bar(self, bar: Bar) -> void:
"""
Update the indicator with the given bar.
使用给定的 bar 更新指标。
Parameters: bar (Bar) – The update bar to handle.
参数:bar (Bar) - 要处理的更新 bar。
"""
...
def handle_quote_tick(self, tick: QuoteTick) -> void:
"""
Update the indicator with the given quote tick.
使用给定的报价行情更新指标。
Parameters: tick (QuoteTick) – The update tick to handle.
参数:tick (QuoteTick) - 要处理的更新行情。
"""
...
def handle_trade_tick(self, tick: TradeTick) -> void:
"""
Update the indicator with the given trade tick.
使用给定的交易行情更新指标。
Parameters: tick (TradeTick) – The update tick to handle.
参数:tick (TradeTick) - 要处理的更新行情。
"""
...
def reset(self) -> void:
"""
Reset the indicator.
重置指标。
All stateful fields are reset to their initial value.
所有有状态字段都重置为其初始值。
"""
...
def update_raw(self, value: float) -> void:
"""
Update the indicator with the given raw value.
使用给定的原始值更新指标。
Parameters: value (double) – The update value.
参数:value (double) - 更新值。
"""
...
class ExponentialMovingAverage 指数移动平均线
Bases: MovingAverage
class ExponentialMovingAverage(MovingAverage):
"""
An indicator which calculates an exponential moving average across a rolling window.
一个指标,用于计算滚动窗口内的指数移动平均线。
Parameters:
参数:
period (int) – The rolling window period for the indicator (> 0).
period (int) - 指标的滚动窗口周期 (> 0)。
price_type (PriceType) – The specified price type for extracting values from quote ticks.
price_type (PriceType) - 用于从报价行情中提取值的指定价格类型。
Raises: ValueError – If period is not positive (> 0).
引发:ValueError - 如果 period 不是正数 (> 0)。
"""
def __init__(self, period: int, price_type: PriceType = PriceType.LAST):
...
Properties 属性
@property
def alpha(self) -> float:
"""
The moving average alpha value.
移动平均线的 alpha 值。
Returns:
double
"""
...
@property
def count(self) -> int:
"""
The count of inputs received by the indicator.
指标接收的输入计数。
Returns:
int
"""
...
@property
def has_inputs(self):
"""
If the indicator has received inputs.
指标是否已接收输入。
Returns:
bool
"""
...
@property
def initialized(self):
"""
If the indicator is warmed up and initialized.
指标是否已预热并初始化。
Returns:
bool
"""
...
@property
def name(self) -> str:
"""
The name of the indicator.
指标的名称。
Returns:
str
"""
...
@property
def period(self):
"""
The moving average period.
移动平均线周期。
Returns:
PriceType
"""
...
@property
def price_type(self):
"""
The specified price type for extracting values from quote ticks.
用于从报价行情中提取值的指定价格类型。
Returns:
PriceType
"""
...
@property
def value(self) -> float:
"""
The current output value.
当前输出值。
Returns:
double
"""
...
Methods 方法
def handle_bar(self, bar: Bar) -> void:
"""
Update the indicator with the given bar.
使用给定的 bar 更新指标。
Parameters: bar (Bar) – The update bar to handle.
参数:bar (Bar) - 要处理的更新 bar。
"""
...
def handle_quote_tick(self, tick: QuoteTick) -> void:
"""
Update the indicator with the given quote tick.
使用给定的报价行情更新指标。
Parameters: tick (QuoteTick) – The update tick to handle.
参数:tick (QuoteTick) - 要处理的更新行情。
"""
...
def handle_trade_tick(self, tick: TradeTick) -> void:
"""
Update the indicator with the given trade tick.
使用给定的交易行情更新指标。
Parameters: tick (TradeTick) – The update tick to handle.
参数:tick (TradeTick) - 要处理的更新行情。
"""
...
def reset(self) -> void:
"""
Reset the indicator.
重置指标。
All stateful fields are reset to their initial value.
所有有状态字段都重置为其初始值。
"""
...
def update_raw(self, value: float) -> void:
"""
Update the indicator with the given raw value.
使用给定的原始值更新指标。
Parameters: value (double) – The update value.
参数:value (double) - 更新值。
"""
...
class DonchianChannel 唐奇安通道
Bases: Indicator
class DonchianChannel(Indicator):
"""
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.
唐奇安通道是由移动平均线计算生成的三条线,它们构成了一个指标,由围绕中值或中位数波段的上下波段组成。上波段标记了 N 个周期内 instrument_id 的最高价格,而下波段标记了 N 个周期内 instrument_id 的最低价格。上下波段之间的区域代表唐奇安通道。
Parameters:
参数:
period (int) – The rolling window period for the indicator (> 0).
period (int) - 指标的滚动窗口周期 (> 0)。
Raises: ValueError – If period is not positive (> 0).
引发:ValueError - 如果 period 不是正数 (> 0)。
"""
def __init__(self, period: int):
...
Properties 属性
@property
def has_inputs(self):
"""
If the indicator has received inputs.
指标是否已接收输入。
Returns:
bool
"""
...
@property
def initialized(self):
"""
If the indicator is warmed up and initialized.
指标是否已预热并初始化。
Returns:
bool
"""
...
@property
def lower(self) -> float:
"""
The current value of the lower band.
下波段的当前值。
Returns:
double
"""
...
@property
def middle(self) -> float:
"""
The current value of the middle band.
中波段的当前值。
Returns:
double
"""
...
@property
def name(self) -> str:
"""
The name of the indicator.
指标的名称。
Returns:
str
"""
...
@property
def period(self) -> int:
"""
The period for the moving average.
移动平均线的周期。
Returns:
int
"""
...
@property
def upper(self) -> float:
"""
The current value of the upper band.
上波段的当前值。
Returns:
double
"""
...
Methods 方法
def handle_bar(self, bar: Bar) -> void:
"""
Update the indicator with the given bar.
使用给定的 bar 更新指标。
Parameters: bar (Bar) – The update bar.
参数:bar (Bar) - 更新 bar。
"""
...
def handle_quote_tick(self, tick: QuoteTick) -> void:
"""
Update the indicator with the given ticks high and low prices.
使用给定行情的高价和低价更新指标。
Parameters: tick (TradeTick) – The tick for the update.
参数:tick (TradeTick) - 用于更新的行情。
"""
...
def handle_trade_tick(self, tick: TradeTick) -> void:
"""
Update the indicator with the given ticks price.
使用给定行情的价格更新指标。
Parameters: tick (TradeTick) – The tick for the update.
参数:tick (TradeTick) - 用于更新的行情。
"""
...
def reset(self) -> void:
"""
Reset the indicator.
重置指标。
All stateful fields are reset to their initial value.
所有有状态字段都重置为其初始值。
"""
...
def update_raw(self, high: float, low: float) -> void:
"""
Update the indicator with the given prices.
使用给定的价格更新指标。
Parameters:
参数:
high (double) – The price for the upper channel.
high (double) - 上通道的价格。
low (double) – The price for the lower channel.
low (double) - 下通道的价格。
"""
...
class HullMovingAverage 赫尔移动平均线
Bases: MovingAverage
class HullMovingAverage(MovingAverage):
"""
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.
一个指标,用于计算滚动窗口内的赫尔移动平均线 (HMA)。HMA 由 Alan Hull 开发,是一种极其快速和平滑的移动平均线。
Parameters:
参数:
period (int) – The rolling window period for the indicator (> 0).
period (int) - 指标的滚动窗口周期 (> 0)。
price_type (PriceType) – The specified price type for extracting values from quote ticks.
price_type (PriceType) - 用于从报价行情中提取值的指定价格类型。
Raises: ValueError – If period is not positive (> 0).
引发:ValueError - 如果 period 不是正数 (> 0)。
"""
def __init__(self, period: int, price_type: PriceType = PriceType.LAST):
...
Properties 属性
@property
def count(self) -> int:
"""
The count of inputs received by the indicator.
指标接收的输入计数。
Returns:
int
"""
...
@property
def has_inputs(self):
"""
If the indicator has received inputs.
指标是否已接收输入。
Returns:
bool
"""
...
@property
def initialized(self):
"""
If the indicator is warmed up and initialized.
指标是否已预热并初始化。
Returns:
bool
"""
...
@property
def name(self) -> str:
"""
The name of the indicator.
指标的名称。
Returns:
str
"""
...
@property
def period(self):
"""
The moving average period.
移动平均线周期。
Returns:
PriceType
"""
...
@property
def price_type(self):
"""
The specified price type for extracting values from quote ticks.
用于从报价行情中提取值的指定价格类型。
Returns:
PriceType
"""
...
@property
def value(self) -> float:
"""
The current output value.
当前输出值。
Returns:
double
"""
...
Methods 方法
def handle_bar(self, bar: Bar) -> void:
"""
Update the indicator with the given bar.
使用给定的 bar 更新指标。
Parameters: bar (Bar) – The update bar to handle.
参数:bar (Bar) - 要处理的更新 bar。
"""
...
def handle_quote_tick(self, tick: QuoteTick) -> void:
"""
Update the indicator with the given quote tick.
使用给定的报价行情更新指标。
Parameters: tick (QuoteTick) – The update tick to handle.
参数:tick (QuoteTick) - 要处理的更新行情。
"""
...
def handle_trade_tick(self, tick: TradeTick) -> void:
"""
Update the indicator with the given trade tick.
使用给定的交易行情更新指标。
Parameters: tick (TradeTick) – The update tick to handle.
参数:tick (TradeTick) - 要处理的更新行情。
"""
...
def reset(self) -> void:
"""
Reset the indicator.
重置指标。
All stateful fields are reset to their initial value.
所有有状态字段都重置为其初始值。
"""
...
def update_raw(self, value: float) -> void:
"""
Update the indicator with the given raw value.
使用给定的原始值更新指标。
Parameters: value (double) – The update value.
参数:value (double) - 更新值。
"""
...
class MovingAverageFactory 移动平均线工厂
Bases: object
class MovingAverageFactory(object):
"""
Provides a factory to construct different moving average indicators.
提供一个工厂来构造不同的移动平均线指标。
"""
def __init__(self):
...
Methods 方法
@staticmethod
def create(period: int, ma_type: MovingAverageType, **kwargs):
"""
Create a moving average indicator corresponding to the given ma_type.
创建与给定 ma_type 对应的移动平均线指标。
Parameters:
参数:
period (int) – The period of the moving average (> 0).
period (int) - 移动平均线的周期 (> 0)。
ma_type (MovingAverageType) – The moving average type.
ma_type (MovingAverageType) - 移动平均线类型。
Return type: MovingAverage
Raises: ValueError – If period is not positive (> 0).
引发:ValueError - 如果 period 不是正数 (> 0)。
"""
...
class SimpleMovingAverage 简单移动平均线
Bases: MovingAverage
class SimpleMovingAverage(MovingAverage):
"""
An indicator which calculates a simple moving average across a rolling window.
一个指标,用于计算滚动窗口内的简单移动平均线。
Parameters:
参数:
period (int) – The rolling window period for the indicator (> 0).
period (int) - 指标的滚动窗口周期 (> 0)。
price_type (PriceType) – The specified price type for extracting values from quote ticks.
price_type (PriceType) - 用于从报价行情中提取值的指定价格类型。
Raises: ValueError – If period is not positive (> 0).
引发:ValueError - 如果 period 不是正数 (> 0)。
"""
def __init__(self, period: int, price_type: PriceType = PriceType.LAST):
...
Properties 属性
@property
def count(self) -> int:
"""
The count of inputs received by the indicator.
指标接收的输入计数。
Returns:
int
"""
...
@property
def has_inputs(self):
"""
If the indicator has received inputs.
指标是否已接收输入。
Returns:
bool
"""
...
@property
def initialized(self):
"""
If the indicator is warmed up and initialized.
指标是否已预热并初始化。
Returns:
bool
"""
...
@property
def name(self) -> str:
"""
The name of the indicator.
指标的名称。
Returns:
str
"""
...
@property
def period(self):
"""
The moving average period.
移动平均线周期。
Returns:
PriceType
"""
...
@property
def price_type(self):
"""
The specified price type for extracting values from quote ticks.
用于从报价行情中提取值的指定价格类型。
Returns:
PriceType
"""
...
@property
def value(self) -> float:
"""
The current output value.
当前输出值。
Returns:
double
"""
...
Methods 方法
def handle_bar(self, bar: Bar) -> void:
"""
Update the indicator with the given bar.
使用给定的 bar 更新指标。
Parameters: bar (Bar) – The update bar to handle.
参数:bar (Bar) - 要处理的更新 bar。
"""
...
def handle_quote_tick(self, tick: QuoteTick) -> void:
"""
Update the indicator with the given quote tick.
使用给定的报价行情更新指标。
Parameters: tick (QuoteTick) – The update tick to handle.
参数:tick (QuoteTick) - 要处理的更新行情。
"""
...
def handle_trade_tick(self, tick: TradeTick) -> void:
"""
Update the indicator with the given trade tick.
使用给定的交易行情更新指标。
Parameters: tick (TradeTick) – The update tick to handle.
参数:tick (TradeTick) - 要处理的更新行情。
"""
...
def reset(self) -> void:
"""
Reset the indicator.
重置指标。
All stateful fields are reset to their initial value.
所有有状态字段都重置为其初始值。
"""
...
def update_raw(self, value: float) -> void:
"""
Update the indicator with the given raw value.
使用给定的原始值更新指标。
Parameters: value (double) – The update value.
参数:value (double) - 更新值。
"""
...
class WeightedMovingAverage 加权移动平均线
Bases: MovingAverage
class WeightedMovingAverage(MovingAverage):
"""
An indicator which calculates a weighted moving average across a rolling window.
一个指标,用于计算滚动窗口内的加权移动平均线。
Parameters:
参数:
period (int) – The rolling window period for the indicator (> 0).
period (int) - 指标的滚动窗口周期 (> 0)。
weights (iterable) – The weights for the moving average calculation (if not None then = period).
weights (iterable) - 移动平均线计算的权重(如果不为 None,则 = period)。
price_type (PriceType) – The specified price type for extracting values from quote ticks.
price_type (PriceType) - 用于从报价行情中提取值的指定价格类型。
Raises: ValueError – If period is not positive (> 0).
引发:ValueError - 如果 period 不是正数 (> 0)。
"""
def __init__(self, period: int, weights=None, price_type: PriceType = PriceType.LAST):
...
Properties 属性
@property
def count(self) -> int:
"""
The count of inputs received by the indicator.
指标接收的输入计数。
Returns:
int
"""
...
@property
def has_inputs(self):
"""
If the indicator has received inputs.
指标是否已接收输入。
Returns:
bool
"""
...
@property
def initialized(self):
"""
If the indicator is warmed up and initialized.
指标是否已预热并初始化。
Returns:
bool
"""
...
@property
def name(self) -> str:
"""
The name of the indicator.
指标的名称。
Returns:
str
"""
...
@property
def period(self):
"""
The moving average period.
移动平均线周期。
Returns:
PriceType
"""
...
@property
def price_type(self):
"""
The specified price type for extracting values from quote ticks.
用于从报价行情中提取值的指定价格类型。
Returns:
PriceType
"""
...
@property
def value(self) -> float:
"""
The current output value.
当前输出值。
Returns:
double
"""
...
@property
def weights(self):
"""
The weights for the moving average calculation.
移动平均线计算的权重。
Returns:
np.ndarray[float64]
"""
...
Methods 方法
def handle_bar(self, bar: Bar) -> void:
"""
Update the indicator with the given bar.
使用给定的 bar 更新指标。
Parameters: bar (Bar) – The update bar to handle.
参数:bar (Bar) - 要处理的更新 bar。
"""
...
def handle_quote_tick(self, tick: QuoteTick) -> void:
"""
Update the indicator with the given quote tick.
使用给定的报价行情更新指标。
Parameters: tick (QuoteTick) – The update tick to handle.
参数:tick (QuoteTick) - 要处理的更新行情。
"""
...
def handle_trade_tick(self, tick: TradeTick) -> void:
"""
Update the indicator with the given trade tick.
使用给定的交易行情更新指标。
Parameters: tick (TradeTick) – The update tick to handle.
参数:tick (TradeTick) - 要处理的更新行情。
"""
...
def reset(self) -> void:
"""
Reset the indicator.
重置指标。
All stateful fields are reset to their initial value.
所有有状态字段都重置为其初始值。
"""
...
def update_raw(self, value: float) -> void:
"""
Update the indicator with the given raw value.
使用给定的原始值更新指标。
Parameters: value (double) – The update value.
参数:value (double) - 更新值。
"""
...
class AverageTrueRange 平均真实波动范围
Bases: Indicator
class AverageTrueRange(Indicator):
"""
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).
period (int) - 指标的滚动窗口周期 (> 0)。
ma_type (MovingAverageType) – The moving average type for the indicator (cannot be None).
ma_type (MovingAverageType) - 指标的移动平均线类型(不能为空)。
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.
use_previous (bool) - 指示是否应使用先前价格值的布尔标志。(注意:仅适用于 update()。update_mid() 将需要使用先前价格)。
value_floor (double) – The floor (minimum) output value for the indicator (>= 0).
value_floor (double) - 指标的底限(最小)输出值 (>= 0)。
"""
def __init__(self, period: int, ma_type: MovingAverageType = MovingAverageType.SIMPLE, use_previous: bool = True, value_floor: float = 0):
...
Properties 属性
@property
def has_inputs(self):
"""
If the indicator has received inputs.
指标是否已接收输入。
Returns:
bool
"""
...
@property
def initialized(self):
"""
If the indicator is warmed up and initialized.
指标是否已预热并初始化。
Returns:
bool
"""
...
@property
def name(self) -> str:
"""
The name of the indicator.
指标的名称。
Returns:
str
"""
...
@property
def period(self) -> int:
"""
The window period.
窗口周期。
Returns:
int
"""
...
@property
def value(self) -> float:
"""
The current value.
当前值。
Returns:
double
"""
...
Methods 方法
def handle_bar(self, bar: Bar) -> void:
"""
Update the indicator with the given bar.
使用给定的 bar 更新指标。
Parameters: bar (Bar) – The update bar.
参数:bar (Bar) - 更新 bar。
"""
...
def handle_quote_tick(self, tick: QuoteTick) -> void:
"""
Abstract method (implement in subclass).
抽象方法(在子类中实现)。
"""
...
def handle_trade_tick(self, tick: TradeTick) -> void:
"""
Abstract method (implement in subclass).
抽象方法(在子类中实现)。
"""
...
def reset(self) -> void:
"""
Reset the indicator.
重置指标。
All stateful fields are reset to their initial value.
所有有状态字段都重置为其初始值。
"""
...
def update_raw(self, high: float, low: float, close: float) -> void:
"""
Update the indicator with the given raw values.
使用给定的原始值更新指标。
Parameters:
参数:
high (double) – The high price.
high (double) - 最高价。
low (double) – The low price.
low (double) - 最低价。
close (double) – The close price.
close (double) - 收盘价。
"""
...
class BollingerBands 布林带
Bases: Indicator
class BollingerBands(Indicator):
"""
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.
布林带® 是一种技术分析工具,由一组趋势线定义,这些趋势线绘制在金融工具价格的简单移动平均线 (SMA) 的两个标准差(正负)之外,可以根据用户偏好进行调整。
Parameters:
参数:
period (int) – The rolling window period for the indicator (> 0).
period (int) - 指标的滚动窗口周期 (> 0)。
k (double) – The standard deviation multiple for the indicator (> 0).
k (double) - 指标的标准差倍数 (> 0)。
ma_type (MovingAverageType) – The moving average type for the indicator.
ma_type (MovingAverageType) - 指标的移动平均线类型。
Raises:
引发:
ValueError – If period is not positive (> 0).
ValueError - 如果 period 不是正数 (> 0)。
ValueError – If k is not positive (> 0).
ValueError - 如果 k 不是正数 (> 0)。
"""
def __init__(self, period: int, k: float, ma_type: MovingAverageType = MovingAverageType.SIMPLE):
...
Properties 属性
@property
def has_inputs(self):
"""
If the indicator has received inputs.
指标是否已接收输入。
Returns:
bool
"""
...
@property
def initialized(self):
"""
If the indicator is warmed up and initialized.
指标是否已预热并初始化。
Returns:
bool
"""
...
@property
def k(self) -> float:
"""
The standard deviation multiple.
标准差倍数。
Returns:
double
"""
...
@property
def lower(self) -> float:
"""
The current value of the lower band.
下波段的当前值。
Returns:
double
"""
...
```python
@property
def middle(self) -> float:
"""
The current value of the middle band.
中波段的当前值。
Returns:
double
"""
...
@property
def name(self) -> str:
"""
The name of the indicator.
指标的名称。
Returns:
str
"""
...
@property
def period(self) -> int:
"""
The period for the moving average.
移动平均线的周期。
Returns:
int
"""
...
@property
def upper(self) -> float:
"""
The current value of the upper band.
上波段的当前值。
Returns:
double
"""
...
Methods 方法
def handle_bar(self, bar: Bar) -> void:
"""
Update the indicator with the given bar.
使用给定的 bar 更新指标。
Parameters: bar (Bar) – The update bar.
参数:bar (Bar) - 更新 bar。
"""
...
def handle_quote_tick(self, tick: QuoteTick) -> void:
"""
Update the indicator with the given tick.
使用给定的行情更新指标。
Parameters: tick (TradeTick) – The tick for the update.
参数:tick (TradeTick) - 用于更新的行情。
"""
...
def handle_trade_tick(self, tick: TradeTick) -> void:
"""
Update the indicator with the given tick.
使用给定的行情更新指标。
Parameters: tick (TradeTick) – The tick for the update.
参数:tick (TradeTick) - 用于更新的行情。
"""
...
def reset(self) -> void:
"""
Reset the indicator.
重置指标。
All stateful fields are reset to their initial value.
所有有状态字段都重置为其初始值。
"""
...
def update_raw(self, high: float, low: float, close: float) -> void:
"""
Update the indicator with the given prices.
使用给定的价格更新指标。
Parameters:
参数:
high (double) – The high price for calculations.
high (double) - 用于计算的最高价。
low (double) – The low price for calculations.
low (double) - 用于计算的最低价。
close (double) – The closing price for calculations
close (double) - 用于计算的收盘价。
"""
...
class EfficiencyRatio 效率比
Bases: Indicator
class EfficiencyRatio(Indicator):
"""
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).
period (int) - 指标的滚动窗口周期 (>= 2)。
Raises: ValueError – If period is not >= 2.
引发:ValueError - 如果 period 不大于等于 2。
"""
def __init__(self, period: int):
...
Properties 属性
@property
def has_inputs(self):
"""
If the indicator has received inputs.
指标是否已接收输入。
Returns:
bool
"""
...
@property
def initialized(self):
"""
If the indicator is warmed up and initialized.
指标是否已预热并初始化。
Returns:
bool
"""
...
@property
def name(self) -> str:
"""
The name of the indicator.
指标的名称。
Returns:
str
"""
...
@property
def period(self) -> int:
"""
The window period.
窗口周期。
Returns:
int
"""
...
@property
def value(self) -> float:
"""
The current value.
当前值。
Returns:
double
"""
...
Methods 方法
def handle_bar(self, bar: Bar) -> void:
"""
Update the indicator with the given bar.
使用给定的 bar 更新指标。
Parameters: bar (Bar) – The update bar.
参数:bar (Bar) - 更新 bar。
"""
...
def handle_quote_tick(self, tick: QuoteTick) -> void:
"""
Abstract method (implement in subclass).
抽象方法(在子类中实现)。
"""
...
def handle_trade_tick(self, tick: TradeTick) -> void:
"""
Abstract method (implement in subclass).
抽象方法(在子类中实现)。
"""
...
def reset(self) -> void:
"""
Reset the indicator.
重置指标。
All stateful fields are reset to their initial value.
所有有状态字段都重置为其初始值。
"""
...
def update_raw(self, price: float) -> void:
"""
Update the indicator with the given price.
使用给定的价格更新指标。
Parameters: price (double) – The update price.
参数:price (double) - 更新价格。
"""
...
class FuzzyCandle 模糊蜡烛图
Bases: object
class FuzzyCandle(object):
"""
Represents a fuzzy candle.
表示模糊蜡烛图。
Parameters:
参数:
direction (CandleDirection) – The candle direction.
direction (CandleDirection) - 蜡烛图的方向。
size (CandleSize) – The candle fuzzy size.
size (CandleSize) - 蜡烛图的模糊大小。
body_size (CandleBodySize) – The candle fuzzy body size.
body_size (CandleBodySize) - 蜡烛图的模糊实体大小。
upper_wick_size (CandleWickSize) – The candle fuzzy upper wick size.
upper_wick_size (CandleWickSize) - 蜡烛图的模糊上影线大小。
lower_wick_size (CandleWickSize) – The candle fuzzy lower wick size.
lower_wick_size (CandleWickSize) - 蜡烛图的模糊下影线大小。
"""
def __init__(self, direction: CandleDirection, size: CandleSize, body_size: CandleBodySize, upper_wick_size: CandleWickSize, lower_wick_size: CandleWickSize):
...
Properties 属性
@property
def body_size(self):
"""
The candles fuzzy body size.
蜡烛图的模糊实体大小。
Returns:
CandleBodySize
"""
...
@property
def direction(self):
"""
The candles close direction.
蜡烛图的收盘方向。
Returns:
CandleDirection
"""
...
@property
def lower_wick_size(self):
"""
The candles fuzzy lower wick size.
蜡烛图的模糊下影线大小。
Returns:
CandleWickSize
"""
...
@property
def size(self):
"""
The candles fuzzy overall size.
蜡烛图的模糊整体大小。
Returns:
CandleSize
"""
...
@property
def upper_wick_size(self):
"""
The candles fuzzy upper wick size.
蜡烛图的模糊上影线大小。
Returns:
CandleWickSize
"""
...
class FuzzyCandlesticks 模糊蜡烛图指标
Bases: Indicator
class FuzzyCandlesticks(Indicator):
"""
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).
period (int) - 指标的滚动窗口周期 (> 0)。
threshold1 (float) – The membership function x threshold1 (>= 0).
threshold1 (float) - 隶属函数 x 阈值 1 (>= 0)。
threshold2 (float) – The membership function x threshold2 (> threshold1).
threshold2 (float) - 隶属函数 x 阈值 2 (> threshold1)。
threshold3 (float) – The membership function x threshold3 (> threshold2).
threshold3 (float) - 隶属函数 x 阈值 3 (> threshold2)。
threshold4 (float) – The membership function x threshold4 (> threshold3).
threshold4 (float) - 隶属函数 x 阈值 4 (> threshold3)。
"""
def __init__(self, period: int, threshold1: float = 0.5, threshold2: float = 1.0, threshold3: float = 2.0, threshold4: float = 3.0):
...
Properties 属性
@property
def has_inputs(self):
"""
If the indicator has received inputs.
指标是否已接收输入。
Returns:
bool
"""
...
@property
def initialized(self):
"""
If the indicator is warmed up and initialized.
指标是否已预热并初始化。
Returns:
bool
"""
...
@property
def name(self) -> str:
"""
The name of the indicator.
指标的名称。
Returns:
str
"""
...
@property
def period(self) -> int:
"""
The window period.
窗口周期。
Returns:
int
"""
...
@property
def value(self):
"""
The last fuzzy candle.
最后一个模糊蜡烛图。
Returns:
FuzzyCandle
"""
...
@property
def vector(self) -> list[int]:
"""
The fuzzy candle represented as a vector of ints.
表示为整数向量的模糊蜡烛图。
Returns:
list[int]
"""
...
Methods 方法
def handle_bar(self, bar: Bar) -> void:
"""
Update the indicator with the given bar.
使用给定的 bar 更新指标。
Parameters: bar. (The update)
参数:bar。(更新)
"""
...
def handle_quote_tick(self, tick: QuoteTick) -> void:
"""
Abstract method (implement in subclass).
抽象方法(在子类中实现)。
"""
...
def handle_trade_tick(self, tick: TradeTick) -> void:
"""
Abstract method (implement in subclass).
抽象方法(在子类中实现)。
"""
...
def reset(self) -> void:
"""
Reset the indicator.
重置指标。
All stateful fields are reset to their initial value.
所有有状态字段都重置为其初始值。
"""
...
def update_raw(self, open: float, high: float, low: float, close: float) -> void:
"""
Update the indicator with the given raw values.
使用给定的原始值更新指标。
Parameters:
参数:
open (double) – The open price.
open (double) - 开盘价。
high (double) – The high price.
high (double) - 最高价。
low (double) – The low price.
low (double) - 最低价。
close (double) – The close price.
close (double) - 收盘价。
"""
...
class KeltnerChannel 肯特纳通道
Bases: Indicator
class KeltnerChannel(Indicator):
"""
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.
肯特纳通道是一个基于波动性的包络线,设置在中心移动平均线的上方和下方。传统上,中间带是基于典型价格 (高 + 低 + 收盘) / 3 的 EMA,上带是中间带加上 ATR。下带是中间带减去 ATR。
Parameters:
参数:
period (int) – The rolling window period for the indicator (> 0).
period (int) - 指标的滚动窗口周期 (> 0)。
k_multiplier (double) – The multiplier for the ATR (> 0).
k_multiplier (double) - ATR 的乘数 (> 0)。
ma_type (MovingAverageType) – The moving average type for the middle band (cannot be None).
ma_type (MovingAverageType) - 中间带的移动平均线类型(不能为空)。
ma_type_atr (MovingAverageType) – The moving average type for the internal ATR (cannot be None).
ma_type_atr (MovingAverageType) - 内部 ATR 的移动平均线类型(不能为空)。
use_previous (bool) – The boolean flag indicating whether previous price values should be used.
use_previous (bool) - 指示是否应使用先前价格值的布尔标志。
atr_floor (double) – The ATR floor (minimum) output value for the indicator (>= 0).
atr_floor (double) - 指标的 ATR 底限(最小)输出值 (>= 0)。
"""
def __init__(self, period: int, k_multiplier: float, ma_type: MovingAverageType = MovingAverageType.EXPONENTIAL, ma_type_atr: MovingAverageType = MovingAverageType.SIMPLE, use_previous: bool = True, atr_floor: float = 0):
...
Properties 属性
@property
def has_inputs(self):
"""
If the indicator has received inputs.
指标是否已接收输入。
Returns:
bool
"""
...
@property
def initialized(self):
"""
If the indicator is warmed up and initialized.
指标是否已预热并初始化。
Returns:
bool
"""
...
@property
def k_multiplier(self) -> float:
"""
The k multiplier.
k 乘数。
Returns:
double
"""
...
@property
def lower(self) -> float:
"""
The current value of the lower channel.
下通道的当前值。
Returns:
double
"""
...
@property
def middle(self) -> float:
"""
The current value of the middle channel.
中间通道的当前值。
Returns:
double
"""
...
@property
def name(self) -> str:
"""
The name of the indicator.
指标的名称。
Returns:
str
"""
...
@property
def period(self) -> int:
"""
The window period.
窗口周期。
Returns:
int
"""
...
@property
def upper(self) -> float:
"""
The current value of the upper channel.
上通道的当前值。
Returns:
double
"""
...
Methods 方法
def handle_bar(self, bar: Bar) -> void:
"""
Update the indicator with the given bar.
使用给定的 bar 更新指标。
Parameters: bar (Bar) – The update bar.
参数:bar (Bar) - 更新 bar。
"""
...
def handle_quote_tick(self, tick: QuoteTick) -> void:
"""
Abstract method (implement in subclass).
抽象方法(在子类中实现)。
"""
...
def handle_trade_tick(self, tick: TradeTick) -> void:
"""
Abstract method (implement in subclass).
抽象方法(在子类中实现)。
"""
...
def reset(self) -> void:
"""
Reset the indicator.
重置指标。
All stateful fields are reset to their initial value.
所有有状态字段都重置为其初始值。
"""
...
def update_raw(self, high: float, low: float, close: float) -> void:
"""
Update the indicator with the given raw values.
使用给定的原始值更新指标。
Parameters:
参数:
high (double) – The high price.
high (double) - 最高价。
low (double) – The low price.
low (double) - 最低价。
close (double) – The close price.
close (double) - 收盘价。
"""
...
class KeltnerPosition 肯特纳持仓
Bases: Indicator
class KeltnerPosition(Indicator):
"""
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).
period (int) - 指标的滚动窗口周期 (> 0)。
k_multiplier (double) – The multiplier for the ATR (> 0).
k_multiplier (double) - ATR 的乘数 (> 0)。
ma_type (MovingAverageType) – The moving average type for the middle band (cannot be None).
ma_type (MovingAverageType) - 中间带的移动平均线类型(不能为空)。
ma_type_atr (MovingAverageType) – The moving average type for the internal ATR (cannot be None).
ma_type_atr (MovingAverageType) - 内部 ATR 的移动平均线类型(不能为空)。
use_previous (bool) – The boolean flag indicating whether previous price values should be used.
use_previous (bool) - 指示是否应使用先前价格值的布尔标志。
atr_floor (double) – The ATR floor (minimum) output value for the indicator (>= 0).
atr_floor (double) - 指标的 ATR 底限(最小)输出值 (>= 0)。
"""
def __init__(self, period: int, k_multiplier: float, ma_type: MovingAverageType = MovingAverageType.EXPONENTIAL, ma_type_atr: MovingAverageType = MovingAverageType.SIMPLE, use_previous: bool = True, atr_floor: float = 0):
...
Properties 属性
@property
def has_inputs(self):
"""
If the indicator has received inputs.
指标是否已接收输入。
Returns:
bool
"""
...
@property
def initialized(self):
"""
If the indicator is warmed up and initialized.
指标是否已预热并初始化。
Returns:
bool
"""
...
@property
def k_multiplier(self) -> float:
"""
The K multiplier.
K 乘数。
Returns:
double
"""
...
@property
def name(self) -> str:
"""
The name of the indicator.
指标的名称。
Returns:
str
"""
...
@property
def period(self) -> int:
"""
The window period.
窗口周期。
Returns:
int
"""
...
@property
def value(self) -> float:
"""
The current value.
当前值。
Returns:
double
"""
...
Methods 方法
def handle_bar(self, bar: Bar) -> void:
"""
Update the indicator with the given bar.
使用给定的 bar 更新指标。
Parameters: bar (Bar) – The update bar.
参数:bar (Bar) - 更新 bar。
"""
...
def handle_quote_tick(self, tick: QuoteTick) -> void:
"""
Abstract method (implement in subclass).
抽象方法(在子类中实现)。
"""
...
def handle_trade_tick(self, tick: TradeTick) -> void:
"""
Abstract method (implement in subclass).
抽象方法(在子类中实现)。
"""
...
def reset(self) -> void:
"""
Reset the indicator.
重置指标。
All stateful fields are reset to their initial value.
所有有状态字段都重置为其初始值。
"""
...
def update_raw(self, high: float, low: float, close: float) -> void:
"""
Update the indicator with the given raw value.
使用给定的原始值更新指标。
Parameters:
参数:
high (double) – The high price.
high (double) - 最高价。
low (double) – The low price.
low (double) - 最低价。
close (double) – The close price.
close (double) - 收盘价。
"""
...
class MovingAverageConvergenceDivergence 平滑异同移动平均线
Bases: Indicator
class MovingAverageConvergenceDivergence(Indicator):
"""
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).
fast_period (int) - 快速移动平均线的周期 (> 0)。
slow_period (int) – The period for the slow moving average (> 0 & > fast_sma).
slow_period (int) - 慢速移动平均线的周期 (> 0 & > fast_sma)。
ma_type (MovingAverageType) – The moving average type for the calculations.
ma_type (MovingAverageType) - 计算的移动平均线类型。
price_type (PriceType) – The specified price type for extracting values from quote ticks.
price_type (PriceType) - 用于从报价行情中提取值的指定价格类型。
Raises:
引发:
ValueError – If fast_period is not positive (> 0).
ValueError - 如果 fast_period 不是正数 (> 0)。
ValueError – If slow_period is not positive (> 0).
ValueError - 如果 slow_period 不是正数 (> 0)。
ValueError – If fast_period is not < slow_period.
ValueError - 如果 fast_period 不小于 slow_period。
"""
def __init__(self, fast_period: int, slow_period: int, ma_type: MovingAverageType = MovingAverageType.EXPONENTIAL, price_type: PriceType = PriceType.LAST):
...
Properties 属性
@property
def fast_period(self) -> int:
"""
The fast moving average window period.
快速移动平均线的窗口周期。
Returns:
int
"""
...
@property
def has_inputs(self):
"""
If the indicator has received inputs.
指标是否已接收输入。
Returns:
bool
"""
...
@property
def initialized(self):
"""
If the indicator is warmed up and initialized.
指标是否已预热并初始化。
Returns:
bool
"""
...
@property
def name(self) -> str:
"""
The name of the indicator.
指标的名称。
Returns:
str
"""
...
@property
def price_type(self):
"""
The specified price type for extracting values from quote ticks.
用于从报价行情中提取值的指定价格类型。
Returns:
PriceType
"""
...
@property
def slow_period(self) -> int:
"""
The slow moving average window period.
慢速移动平均线的窗口周期。
Returns:
int
"""
...
@property
def value(self) -> float:
"""
The current value.
当前值。
Returns:
double
"""
...
Methods 方法
def handle_bar(self, bar: Bar) -> void:
"""
Update the indicator with the given bar.
使用给定的 bar 更新指标。
Parameters: bar (Bar) – The update bar.
参数:bar (Bar) - 更新 bar。
"""
...
def handle_quote_tick(self, tick: QuoteTick) -> void:
"""
Update the indicator with the given quote tick.
使用给定的报价行情更新指标。
Parameters: tick (QuoteTick) – The update tick to handle.
参数:tick (QuoteTick) - 要处理的更新行情。
"""
...
def handle_trade_tick(self, tick: TradeTick) -> void:
"""
Update the indicator with the given trade tick.
使用给定的交易行情更新指标。
Parameters: tick (TradeTick) – The update tick to handle.
参数:tick (TradeTick) - 要处理的更新行情。
"""
...
def reset(self) -> void:
"""
Reset the indicator.
重置指标。
All stateful fields are reset to their initial value.
所有有状态字段都重置为其初始值。
"""
...
def update_raw(self, close: float) -> void:
"""
Update the indicator with the given close price.
使用给定的收盘价更新指标。
Parameters: close (double) – The close price.
参数:close (double) - 收盘价。
"""
...
class OnBalanceVolume 净额成交量
Bases: Indicator
class OnBalanceVolume(Indicator):
"""
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).
period (int) - 指标的周期,零表示没有窗口 (>= 0)。
Raises: ValueError – If period is negative (< 0).
引发:ValueError - 如果 period 为负数 (< 0)。
"""
def __init__(self, period: int = 0):
...
Properties 属性
@property
def has_inputs(self):
"""
If the indicator has received inputs.
指标是否已接收输入。
Returns:
bool
"""
...
@property
def initialized(self):
"""
If the indicator is warmed up and initialized.
指标是否已预热并初始化。
Returns:
bool
"""
...
@property
def name(self) -> str:
"""
The name of the indicator.
指标的名称。
Returns:
str
"""
...
@property
def period(self) -> int:
"""
The window period.
窗口周期。
Returns:
int
"""
...
@property
def value(self) -> float:
"""
The current value.
当前值。
Returns:
double
"""
...
Methods 方法
def handle_bar(self, bar: Bar) -> void:
"""
Update the indicator with the given bar.
使用给定的 bar 更新指标。
Parameters: bar (Bar) – The update bar.
参数:bar (Bar) - 更新 bar。
"""
...
def handle_quote_tick(self, tick: QuoteTick) -> void:
"""
Abstract method (implement in subclass).
抽象方法(在子类中实现)。
"""
...
def handle_trade_tick(self, tick: TradeTick) -> void:
"""
Abstract method (implement in subclass).
抽象方法(在子类中实现)。
"""
...
def reset(self) -> void:
"""
Reset the indicator.
重置指标。
All stateful fields are reset to their initial value.
所有有状态字段都重置为其初始值。
"""
...
def update_raw(self, open: float, close: float, volume: float) -> void:
"""
Update the indicator with the given raw values.
使用给定的原始值更新指标。
Parameters:
参数:
open (double) – The high price.
open (double) - 最高价。
close (double) – The low price.
close (double) - 最低价。
volume (double) – The close price.
volume (double) - 收盘价。
"""
...
class Pressure 压力
Bases: Indicator
class Pressure(Indicator):
"""
An indicator which calculates the relative volume (multiple of average volume) to move the market across a relative range (multiple of ATR).
一个指标,用于计算相对交易量(平均交易量的倍数)以使市场跨越相对范围(ATR 的倍数)。
Parameters:
参数:
period (int) – The period for the indicator (> 0).
period (int) - 指标的周期 (> 0)。
ma_type (MovingAverageType) – The moving average type for the calculations.
ma_type (MovingAverageType) - 计算的移动平均线类型。
atr_floor (double) – The ATR floor (minimum) output value for the indicator (>= 0.).
atr_floor (double) - 指标的 ATR 底限(最小)输出值 (>= 0.)。
Raises:
引发:
ValueError – If period is not positive (> 0).
ValueError - 如果 period 不是正数 (> 0)。
ValueError – If atr_floor is negative (< 0).
ValueError - 如果 atr_floor 为负数 (< 0)。
"""
def __init__(self, period: int, ma_type: MovingAverageType = MovingAverageType.EXPONENTIAL, atr_floor: float = 0):
...
Properties 属性
@property
def has_inputs(self):
"""
If the indicator has received inputs.
指标是否已接收输入。
Returns:
bool
"""
...
@property
def initialized(self):
"""
If the indicator is warmed up and initialized.
指标是否已预热并初始化。
Returns:
bool
"""
...
@property
def name(self) -> str:
"""
The name of the indicator.
指标的名称。
Returns:
str
"""
...
@property
def period(self) -> int:
"""
The window period.
窗口周期。
Returns:
int
"""
...
@property
def value(self) -> int:
"""
The current value.
当前值。
Returns:
int
"""
...
@property
def value_cumulative(self) -> int:
"""
The cumulative value.
累计值。
Returns:
int
"""
...
Methods 方法
def handle_bar(self, bar: Bar) -> void:
"""
Update the indicator with the given bar.
使用给定的 bar 更新指标。
Parameters: bar (Bar) – The update bar.
参数:bar (Bar) - 更新 bar。
"""
...
def handle_quote_tick(self, tick: QuoteTick) -> void:
"""
Abstract method (implement in subclass).
抽象方法(在子类中实现)。
"""
...
def handle_trade_tick(self, tick: TradeTick) -> void:
"""
Abstract method (implement in subclass).
抽象方法(在子类中实现)。
"""
...
def reset(self) -> void:
"""
Reset the indicator.
重置指标。
All stateful fields are reset to their initial value.
所有有状态字段都重置为其初始值。
"""
...
def update_raw(self, high: float, low: float, close: float, volume: float) -> void:
"""
Update the indicator with the given raw values.
使用给定的原始值更新指标。
Parameters:
参数:
high (double) – The high price.
high (double) - 最高价。
low (double) – The low price.
low (double) - 最低价。
close (double) – The close price.
close (double) - 收盘价。
volume (double) – The volume.
volume (double) - 交易量。
"""
...
class RateOfChange 变化率
Bases: Indicator
class RateOfChange(Indicator):
"""
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.
```python
period (int) - 指标的周期。
use_log (bool) – Use log returns for value calculation.
use_log (bool) - 使用对数收益率进行值计算。
Raises: ValueError – If period is not > 1.
引发:ValueError - 如果 period 不大于 1。
"""
def __init__(self, period: int, use_log: bool = False):
...
Properties 属性
@property
def has_inputs(self):
"""
If the indicator has received inputs.
指标是否已接收输入。
Returns:
bool
"""
...
@property
def initialized(self):
"""
If the indicator is warmed up and initialized.
指标是否已预热并初始化。
Returns:
bool
"""
...
@property
def name(self) -> str:
"""
The name of the indicator.
指标的名称。
Returns:
str
"""
...
@property
def period(self) -> int:
"""
The window period.
窗口周期。
Returns:
int
"""
...
@property
def value(self) -> float:
"""
The current value.
当前值。
Returns:
double
"""
...
Methods 方法
def handle_bar(self, bar: Bar) -> void:
"""
Update the indicator with the given bar.
使用给定的 bar 更新指标。
Parameters: bar (Bar) – The update bar.
参数:bar (Bar) - 更新 bar。
"""
...
def handle_quote_tick(self, tick: QuoteTick) -> void:
"""
Abstract method (implement in subclass).
抽象方法(在子类中实现)。
"""
...
def handle_trade_tick(self, tick: TradeTick) -> void:
"""
Abstract method (implement in subclass).
抽象方法(在子类中实现)。
"""
...
def reset(self) -> void:
"""
Reset the indicator.
重置指标。
All stateful fields are reset to their initial value.
所有有状态字段都重置为其初始值。
"""
...
def update_raw(self, price: float) -> void:
"""
Update the indicator with the given price.
使用给定的价格更新指标。
Parameters: price (double) – The update price.
参数:price (double) - 更新价格。
"""
...
class RelativeStrengthIndex 相对强弱指数
Bases: Indicator
class RelativeStrengthIndex(Indicator):
"""
An indicator which calculates a relative strength index (RSI) across a rolling window.
一个指标,用于计算滚动窗口内的相对强弱指数 (RSI)。
Parameters:
参数:
ma_type (int) – The moving average type for average gain/loss.
ma_type (int) - 平均收益/损失的移动平均线类型。
period (MovingAverageType) – The rolling window period for the indicator.
period (MovingAverageType) - 指标的滚动窗口周期。
Raises: ValueError – If period is not positive (> 0).
引发:ValueError - 如果 period 不是正数 (> 0)。
"""
def __init__(self, period, ma_type: MovingAverageType = MovingAverageType.EXPONENTIAL):
...
Properties 属性
@property
def has_inputs(self):
"""
If the indicator has received inputs.
指标是否已接收输入。
Returns:
bool
"""
...
@property
def initialized(self):
"""
If the indicator is warmed up and initialized.
指标是否已预热并初始化。
Returns:
bool
"""
...
@property
def name(self) -> str:
"""
The name of the indicator.
指标的名称。
Returns:
str
"""
...
@property
def period(self) -> int:
"""
The window period.
窗口周期。
Returns:
int
"""
...
@property
def value(self) -> float:
"""
The current value.
当前值。
Returns:
double
"""
...
Methods 方法
def handle_bar(self, bar: Bar) -> void:
"""
Update the indicator with the given bar.
使用给定的 bar 更新指标。
Parameters: bar (Bar) – The update bar.
参数:bar (Bar) - 更新 bar。
"""
...
def handle_quote_tick(self, tick: QuoteTick) -> void:
"""
Abstract method (implement in subclass).
抽象方法(在子类中实现)。
"""
...
def handle_trade_tick(self, tick: TradeTick) -> void:
"""
Abstract method (implement in subclass).
抽象方法(在子类中实现)。
"""
...
def reset(self) -> void:
"""
Reset the indicator.
重置指标。
All stateful fields are reset to their initial value.
所有有状态字段都重置为其初始值。
"""
...
def update_raw(self, value: float) -> void:
"""
Update the indicator with the given value.
使用给定的值更新指标。
Parameters: value (double) – The update value.
参数:value (double) - 更新值。
"""
...
class SpreadAnalyzer 价差分析器
Bases: Indicator
class SpreadAnalyzer(Indicator):
"""
Provides various spread analysis metrics.
提供各种价差分析指标。
Parameters:
参数:
instrument_id (InstrumentId) – The instrument ID for the tick updates.
instrument_id (InstrumentId) - 行情更新的金融工具 ID。
capacity (int) – The max length for the internal QuoteTick deque (determines averages).
capacity (int) - 内部 QuoteTick 双端队列的最大长度(决定平均值)。
Raises: ValueError – If capacity is not positive (> 0).
引发:ValueError - 如果 capacity 不是正数 (> 0)。
"""
def __init__(self, instrument_id: InstrumentId, capacity: int) -> None:
...
Properties 属性
@property
def average(self) -> float:
"""
The current average spread.
当前平均价差。
Returns:
double
"""
...
@property
def capacity(self) -> int:
"""
The indicators spread capacity.
指标价差容量。
Returns:
int
"""
...
@property
def current(self) -> float:
"""
The current spread.
当前价差。
Returns:
double
"""
...
@property
def has_inputs(self):
"""
If the indicator has received inputs.
指标是否已接收输入。
Returns:
bool
"""
...
@property
def initialized(self):
"""
If the indicator is warmed up and initialized.
指标是否已预热并初始化。
Returns:
bool
"""
...
@property
def instrument_id(self) -> InstrumentId:
"""
The indicators instrument ID.
指标的金融工具 ID。
Returns:
InstrumentId
"""
...
@property
def name(self) -> str:
"""
The name of the indicator.
指标的名称。
Returns:
str
"""
...
Methods 方法
def handle_bar(self, bar: Bar) -> void:
"""
Abstract method (implement in subclass).
抽象方法(在子类中实现)。
"""
...
def handle_quote_tick(self, tick: QuoteTick) -> void:
"""
Update the analyzer with the given quote tick.
使用给定的报价行情更新分析器。
Parameters: tick (QuoteTick) – The tick for the update.
参数:tick (QuoteTick) - 用于更新的行情。
Raises: ValueError – If tick.instrument_id does not equal the analyzers instrument ID.
引发:ValueError - 如果 tick.instrument_id 不等于分析器的金融工具 ID。
"""
...
def handle_trade_tick(self, tick: TradeTick) -> void:
"""
Abstract method (implement in subclass).
抽象方法(在子类中实现)。
"""
...
def reset(self) -> void:
"""
Reset the indicator.
重置指标。
All stateful fields are reset to their initial value.
所有有状态字段都重置为其初始值。
"""
...
class Stochastics 随机指标
Bases: Indicator
class Stochastics(Indicator):
"""
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_k (int) - K 线的周期。
period_d (int) – The period for the D line.
period_d (int) - D 线的周期。
Raises:
引发:
ValueError – If period_k is not positive (> 0).
ValueError - 如果 period_k 不是正数 (> 0)。
ValueError – If period_d is not positive (> 0).
ValueError - 如果 period_d 不是正数 (> 0)。
"""
def __init__(self, period_k: int, period_d: int):
...
Properties 属性
@property
def has_inputs(self):
"""
If the indicator has received inputs.
指标是否已接收输入。
Returns:
bool
"""
...
@property
def initialized(self):
"""
If the indicator is warmed up and initialized.
指标是否已预热并初始化。
Returns:
bool
"""
...
@property
def name(self) -> str:
"""
The name of the indicator.
指标的名称。
Returns:
str
"""
...
@property
def period_d(self) -> int:
"""
The D window period.
D 窗口周期。
Returns:
int
"""
...
@property
def period_k(self) -> int:
"""
The K window period.
K 窗口周期。
Returns:
int
"""
...
@property
def value_d(self) -> float:
"""
The current D line value.
当前 D 线值。
Returns:
double
"""
...
@property
def value_k(self) -> float:
"""
The current K line value..
当前 K 线值。
Returns:
double
"""
...
Methods 方法
def handle_bar(self, bar: Bar) -> void:
"""
Update the indicator with the given bar.
使用给定的 bar 更新指标。
Parameters: bar (Bar) – The update bar.
参数:bar (Bar) - 更新 bar。
"""
...
def handle_quote_tick(self, tick: QuoteTick) -> void:
"""
Abstract method (implement in subclass).
抽象方法(在子类中实现)。
"""
...
def handle_trade_tick(self, tick: TradeTick) -> void:
"""
Abstract method (implement in subclass).
抽象方法(在子类中实现)。
"""
...
def reset(self) -> void:
"""
Reset the indicator.
重置指标。
All stateful fields are reset to their initial value.
所有有状态字段都重置为其初始值。
"""
...
def update_raw(self, high: float, low: float, close: float) -> void:
"""
Update the indicator with the given raw values.
使用给定的原始值更新指标。
Parameters:
参数:
high (double) – The high price.
high (double) - 最高价。
low (double) – The low price.
low (double) - 最低价。
close (double) – The close price.
close (double) - 收盘价。
"""
...
class Swings 摆动指标
Bases: Indicator
class Swings(Indicator):
"""
A swing indicator which calculates and stores various swing metrics.
一个摆动指标,用于计算和存储各种摆动指标。
Parameters:
参数:
period (int) – The rolling window period for the indicator (> 0).
period (int) - 指标的滚动窗口周期 (> 0)。
"""
def __init__(self, period: int):
...
Properties 属性
@property
def changed(self):
"""
If the swing direction changed at the last bar.
摆动方向是否在最后一个 bar 处发生变化。
Returns:
bool
"""
...
@property
def direction(self) -> int:
"""
The current swing direction.
当前摆动方向。
Returns:
int
"""
...
@property
def duration(self) -> int:
"""
The current swing duration.
当前摆动持续时间。
Returns:
int
"""
...
@property
def has_inputs(self):
"""
If the indicator has received inputs.
指标是否已接收输入。
Returns:
bool
"""
...
@property
def high_datetime(self) -> datetime:
"""
The last swing high time.
最后一次摆动高点的时间。
Returns:
datetime
"""
...
@property
def high_price(self) -> float:
"""
The last swing high price.
最后一次摆动高点的价格。
Returns:
double
"""
...
@property
def initialized(self):
"""
If the indicator is warmed up and initialized.
指标是否已预热并初始化。
Returns:
bool
"""
...
@property
def length(self) -> float:
"""
The length of the current swing.
当前摆动的长度。
Returns:
double
"""
...
@property
def low_datetime(self) -> datetime:
"""
The last swing low time.
最后一次摆动低点的时间。
Returns:
datetime
"""
...
@property
def low_price(self) -> float:
"""
The last swing low price.
最后一次摆动低点的价格。
Returns:
double
"""
...
@property
def name(self) -> str:
"""
The name of the indicator.
指标的名称。
Returns:
str
"""
...
@property
def period(self) -> int:
"""
The window period.
窗口周期。
Returns:
int
"""
...
@property
def since_high(self) -> int:
"""
The bars since the last swing high.
自最后一次摆动高点以来的 bar 数。
Returns:
int
"""
...
@property
def since_low(self) -> int:
"""
The bars since the last swing low.
自最后一次摆动低点以来的 bar 数。
Returns:
int
"""
...
Methods 方法
def handle_bar(self, bar: Bar) -> void:
"""
Update the indicator with the given bar.
使用给定的 bar 更新指标。
Parameters: bar (Bar) – The update bar.
参数:bar (Bar) - 更新 bar。
"""
...
def handle_quote_tick(self, tick: QuoteTick) -> void:
"""
Abstract method (implement in subclass).
抽象方法(在子类中实现)。
"""
...
def handle_trade_tick(self, tick: TradeTick) -> void:
"""
Abstract method (implement in subclass).
抽象方法(在子类中实现)。
"""
...
def reset(self) -> void:
"""
Reset the indicator.
重置指标。
All stateful fields are reset to their initial value.
所有有状态字段都重置为其初始值。
"""
...
def update_raw(self, high: float, low: float, timestamp: datetime) -> void:
"""
Update the indicator with the given raw values.
使用给定的原始值更新指标。
Parameters:
参数:
high (double) – The high price.
high (double) - 最高价。
low (double) – The low price.
low (double) - 最低价。
timestamp (datetime) – The current timestamp.
timestamp (datetime) - 当前时间戳。
"""
...
class VolatilityRatio 波动率比率
Bases: Indicator
class VolatilityRatio(Indicator):
"""
An indicator which calculates the ratio of different ranges of volatility. Different moving average types can be selected for the inner ATR calculations.
一个指标,用于计算不同波动率范围的比率。可以选择不同的移动平均线类型进行内部 ATR 计算。
Parameters:
参数:
fast_period (int) – The period for the fast ATR (> 0).
fast_period (int) - 快速 ATR 的周期 (> 0)。
slow_period (int) – The period for the slow ATR (> 0 & > fast_period).
slow_period (int) - 慢速 ATR 的周期 (> 0 & > fast_period)。
ma_type (MovingAverageType) – The moving average type for the ATR calculations.
ma_type (MovingAverageType) - ATR 计算的移动平均线类型。
use_previous (bool) – The boolean flag indicating whether previous price values should be used.
use_previous (bool) - 指示是否应使用先前价格值的布尔标志。
value_floor (double) – The floor (minimum) output value for the indicator (>= 0).
value_floor (double) - 指标的底限(最小)输出值 (>= 0)。
Raises:
引发:
ValueError – If fast_period is not positive (> 0).
ValueError - 如果 fast_period 不是正数 (> 0)。
ValueError – If slow_period is not positive (> 0).
ValueError - 如果 slow_period 不是正数 (> 0)。
ValueError – If fast_period is not < slow_period.
ValueError - 如果 fast_period 不小于 slow_period。
ValueError – If value_floor is negative (< 0).
ValueError - 如果 value_floor 为负数 (< 0)。
"""
def __init__(self, fast_period: int, slow_period: int, ma_type: MovingAverageType = MovingAverageType.SIMPLE, use_previous: bool = True, value_floor: float = 0):
...
Properties 属性
@property
def fast_period(self) -> int:
"""
The period of the fast ATR.
快速 ATR 的周期。
Returns:
int
"""
...
@property
def has_inputs(self):
"""
If the indicator has received inputs.
指标是否已接收输入。
Returns:
bool
"""
...
@property
def initialized(self):
"""
If the indicator is warmed up and initialized.
指标是否已预热并初始化。
Returns:
bool
"""
...
@property
def name(self) -> str:
"""
The name of the indicator.
指标的名称。
Returns:
str
"""
...
@property
def slow_period(self) -> int:
"""
The period of the slow ATR.
慢速 ATR 的周期。
Returns:
int
"""
...
@property
def value(self) -> float:
"""
The current value.
当前值。
Returns:
double
"""
...
Methods 方法
def handle_bar(self, bar: Bar) -> void:
"""
Update the indicator with the given bar.
使用给定的 bar 更新指标。
Parameters: bar (Bar) – The update bar.
参数:bar (Bar) - 更新 bar。
"""
...
def handle_quote_tick(self, tick: QuoteTick) -> void:
"""
Abstract method (implement in subclass).
抽象方法(在子类中实现)。
"""
...
def handle_trade_tick(self, tick: TradeTick) -> void:
"""
Abstract method (implement in subclass).
抽象方法(在子类中实现)。
"""
...
def reset(self) -> void:
"""
Reset the indicator.
重置指标。
All stateful fields are reset to their initial value.
所有有状态字段都重置为其初始值。
"""
...
def update_raw(self, high: float, low: float, close: float) -> void:
"""
Update the indicator with the given raw value.
使用给定的原始值更新指标。
Parameters:
参数:
high (double) – The high price.
high (double) - 最高价。
low (double) – The low price.
low (double) - 最低价。
close (double) – The close price.
close (double) - 收盘价。
"""
...
class VolumeWeightedAveragePrice 成交量加权平均价格
Bases: Indicator
class VolumeWeightedAveragePrice(Indicator):
"""
An indicator which calculates the volume weighted average price for the day.
一个指标,用于计算当天的成交量加权平均价格。
"""
def __init__(self):
...
Properties 属性
@property
def has_inputs(self):
"""
If the indicator has received inputs.
指标是否已接收输入。
Returns:
bool
"""
...
@property
def initialized(self):
"""
If the indicator is warmed up and initialized.
指标是否已预热并初始化。
Returns:
bool
"""
...
@property
def name(self) -> str:
"""
The name of the indicator.
指标的名称。
Returns:
str
"""
...
@property
def value(self) -> float:
"""
The current value.
当前值。
Returns:
double
"""
...
Methods 方法
def handle_bar(self, bar: Bar) -> void:
"""
Update the indicator with the given bar.
使用给定的 bar 更新指标。
Parameters: bar (Bar) – The update bar.
参数:bar (Bar) - 更新 bar。
"""
...
def handle_quote_tick(self, tick: QuoteTick) -> void:
"""
Abstract method (implement in subclass).
抽象方法(在子类中实现)。
"""
...
def handle_trade_tick(self, tick: TradeTick) -> void:
"""
Abstract method (implement in subclass).
抽象方法(在子类中实现)。
"""
...
def reset(self) -> void:
"""
Reset the indicator.
重置指标。
All stateful fields are reset to their initial value.
所有有状态字段都重置为其初始值。
"""
...
def update_raw(self, price: float, volume: float, timestamp: datetime) -> void:
"""
Update the indicator with the given raw values.
使用给定的原始值更新指标。
Parameters:
参数:
price (double) – The update price.
price (double) - 更新价格。
volume (double) – The update volume.
volume (double) - 更新交易量。
timestamp (datetime) – The current timestamp.
timestamp (datetime) - 当前时间戳。
"""
...
class MovingAverage 移动平均线
Bases: Indicator
class MovingAverage(Indicator):
"""
The base class for all moving average type indicators.
所有移动平均线类型指标的基类。
Parameters:
参数:
period (int) – The rolling window period for the indicator (> 0).
period (int) - 指标的滚动窗口周期 (> 0)。
params (list) – The initialization parameters for the indicator.
params (list) - 指标的初始化参数。
price_type (PriceType , optional) – The specified price type for extracting values from quote ticks.
price_type (PriceType,可选) - 用于从报价行情中提取值的指定价格类型。
Warning:
This class should not be used directly, but through a concrete subclass.
此类不应直接使用,而应通过具体的子类使用。
"""
def __init__(self, period: int, params: list, price_type):
...
Properties 属性
@property
def count(self) -> int:
"""
The count of inputs received by the indicator.
指标接收的输入计数。
Returns:
int
"""
...
@property
def has_inputs(self):
"""
If the indicator has received inputs.
指标是否已接收输入。
Returns:
bool
"""
...
@property
def initialized(self):
"""
If the indicator is warmed up and initialized.
指标是否已预热并初始化。
Returns:
bool
"""
...
@property
def name(self) -> str:
"""
The name of the indicator.
指标的名称。
Returns:
str
"""
...
@property
def period(self):
"""
The moving average period.
移动平均线周期。
Returns:
PriceType
"""
...
@property
def price_type(self):
"""
The specified price type for extracting values from quote ticks.
用于从报价行情中提取值的指定价格类型。
Returns:
PriceType
"""
...
@property
def value(self) -> float:
"""
The current output value.
当前输出值。
Returns:
double
"""
...
Methods 方法
def handle_bar(self, bar: Bar) -> void:
"""
Abstract method (implement in subclass).
抽象方法(在子类中实现)。
"""
...
def handle_quote_tick(self, tick: QuoteTick) -> void:
"""
Abstract method (implement in subclass).
抽象方法(在子类中实现)。
"""
...
def handle_trade_tick(self, tick: TradeTick) -> void:
"""
Abstract method (implement in subclass).
抽象方法(在子类中实现)。
"""
...
def reset(self) -> void:
"""
Reset the indicator.
重置指标。
All stateful fields are reset to their initial value.
所有有状态字段都重置为其初始值。
"""
...
def update_raw(self, value: float) -> void:
"""
Update the indicator with the given raw value.
使用给定的原始值更新指标。
Parameters: value (double) – The update value.
参数:value (double) - 更新值。
"""
...
class MovingAverageType 移动平均线类型
Bases: Enum
class MovingAverageType(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
class Indicator(object):
"""
The base class for all indicators.
所有指标的基类。
Parameters:
参数:
params (list) – The initialization parameters for the indicator.
params (list) - 指标的初始化参数。
Warning:
This class should not be used directly, but through a concrete subclass.
此类不应直接使用,而应通过具体的子类使用。
"""
def __init__(self, params: list):
...
Properties 属性
@property
def has_inputs(self):
"""
If the indicator has received inputs.
指标是否已接收输入。
Returns:
bool
"""
...
@property
def initialized(self):
"""
If the indicator is warmed up and initialized.
指标是否已预热并初始化。
Returns:
bool
"""
...
@property
def name(self) -> str:
"""
The name of the indicator.
指标的名称。
Returns:
str
"""
...
Methods 方法
def handle_bar(self, bar: Bar) -> void:
"""
Abstract method (implement in subclass).
抽象方法(在子类中实现)。
"""
...
def handle_quote_tick(self, tick: QuoteTick) -> void:
"""
Abstract method (implement in subclass).
抽象方法(在子类中实现)。
"""
...
def handle_trade_tick(self, tick: TradeTick) -> void:
"""
Abstract method (implement in subclass).
抽象方法(在子类中实现)。
"""
...
def reset(self) -> void:
"""
Reset the indicator.
重置指标。
All stateful fields are reset to their initial value.
所有有状态字段都重置为其初始值。
"""
...