Skip to content

IndicatorExtensions

QuantConnect.Indicators.IndicatorExtensions

Bases: Object

Provides extension methods for Indicator

ema

ema(
    left: Any,
    period: int,
    smoothing_factor: Optional[float] = None,
    wait_for_first_to_ready: bool = True,
) -> ExponentialMovingAverage
ema(
    left: IndicatorBase,
    period: int,
    smoothing_factor: Optional[float] = None,
    wait_for_first_to_ready: bool = True,
) -> ExponentialMovingAverage

Creates a new ExponentialMovingAverage indicator with the specified period and smoothing_factor from the left indicator

Parameters:

Name Type Description Default
left Any | IndicatorBase

The ExponentialMovingAverage indicator will be created using the data from left

required
period int

The period of the ExponentialMovingAverage indicators

required
smoothing_factor Optional[float]

The percentage of data from the previous value to be carried into the next value

None
wait_for_first_to_ready bool

True to only send updates to the second if left.IsReady returns true, false to always send updates

True

Returns:

Type Description
ExponentialMovingAverage

A reference to the ExponentialMovingAverage indicator to allow for method chaining.

max

max(
    left: Any,
    period: int,
    wait_for_first_to_ready: bool = True,
) -> Maximum
max(
    left: IIndicator,
    period: int,
    wait_for_first_to_ready: bool = True,
) -> Maximum

Creates a new Maximum indicator with the specified period from the left indicator

Parameters:

Name Type Description Default
left Any | IIndicator

The Maximum indicator will be created using the data from left

required
period int

The period of the Maximum indicator

required
wait_for_first_to_ready bool

True to only send updates to the second if left.IsReady returns true, false to always send updates

True

Returns:

Type Description
Maximum

A reference to the Maximum indicator to allow for method chaining.

min

min(
    left: Any,
    period: int,
    wait_for_first_to_ready: bool = True,
) -> Minimum
min(
    left: IndicatorBase,
    period: int,
    wait_for_first_to_ready: bool = True,
) -> Minimum

Creates a new Minimum indicator with the specified period from the left indicator

Parameters:

Name Type Description Default
left Any | IndicatorBase

The Minimum indicator will be created using the data from left

required
period int

The period of the Minimum indicator

required
wait_for_first_to_ready bool

True to only send updates to the second if left.IsReady returns true, false to always send updates

True

Returns:

Type Description
Minimum

A reference to the Minimum indicator to allow for method chaining.

minus

minus(left: Any, constant: float) -> CompositeIndicator
minus(
    left: Any, right: Any, name: str = None
) -> CompositeIndicator
minus(
    left: IndicatorBase, constant: float
) -> CompositeIndicator
minus(
    left: IndicatorBase, right: IndicatorBase, name: str
) -> CompositeIndicator

Signature descriptions:

  • Creates a new CompositeIndicator such that the result will be the difference of the left and constant

  • Creates a new CompositeIndicator such that the result will be the difference of the left and right

Parameters:

Name Type Description Default
left Any | IndicatorBase

The left indicator

required
constant Optional[float]

The subtrahend

None
right Optional[Any | IndicatorBase]

The right indicator

None
name Optional[str]

The name of this indicator

None

Returns:

Type Description
CompositeIndicator

The difference of the left and right indicators.

over

over(left: Any, constant: float) -> CompositeIndicator
over(
    left: Any, right: Any, name: str = None
) -> CompositeIndicator
over(
    left: IndicatorBase, constant: float
) -> CompositeIndicator
over(
    left: IndicatorBase, right: IndicatorBase, name: str
) -> CompositeIndicator

Signature descriptions:

  • Creates a new CompositeIndicator such that the result will be the ratio of the left to the constant

  • Creates a new CompositeIndicator such that the result will be the ratio of the left to the right

Parameters:

Name Type Description Default
left Any | IndicatorBase

The left indicator

required
constant Optional[float]

The constant value denominator

None
right Optional[Any | IndicatorBase]

The right indicator

None
name Optional[str]

The name of this indicator

None

Returns:

Type Description
CompositeIndicator

The ratio of the left to the right indicator.

plus

plus(left: Any, constant: float) -> CompositeIndicator
plus(
    left: Any, right: Any, name: str = None
) -> CompositeIndicator
plus(
    left: IndicatorBase, constant: float
) -> CompositeIndicator
plus(
    left: IndicatorBase, right: IndicatorBase, name: str
) -> CompositeIndicator

Signature descriptions:

  • Creates a new CompositeIndicator such that the result will be the sum of the left and the constant

  • Creates a new CompositeIndicator such that the result will be the sum of the left and right

Parameters:

Name Type Description Default
left Any | IndicatorBase

The left indicator

required
constant Optional[float]

The addend

None
right Optional[Any | IndicatorBase]

The right indicator

None
name Optional[str]

The name of this indicator

None

Returns:

Type Description
CompositeIndicator

The sum of the left and right indicators.

sma

sma(
    left: Any,
    period: int,
    wait_for_first_to_ready: bool = True,
) -> SimpleMovingAverage
sma(
    left: IndicatorBase,
    period: int,
    wait_for_first_to_ready: bool = True,
) -> SimpleMovingAverage

Initializes a new instance of the SimpleMovingAverage class with the specified name and period from the left indicator

Parameters:

Name Type Description Default
left Any | IndicatorBase

The SimpleMovingAverage indicator will be created using the data from left

required
period int

The period of the SMA

required
wait_for_first_to_ready bool

True to only send updates to the second if first.IsReady returns true, false to always send updates to second

True

Returns:

Type Description
SimpleMovingAverage

The reference to the SimpleMovingAverage indicator to allow for method chaining.

times

times(left: Any, constant: float) -> CompositeIndicator
times(
    left: Any, right: Any, name: str = None
) -> CompositeIndicator
times(
    left: IndicatorBase, constant: float
) -> CompositeIndicator
times(
    left: IndicatorBase, right: IndicatorBase, name: str
) -> CompositeIndicator

Signature descriptions:

  • Creates a new CompositeIndicator such that the result will be the product of the left and the constant

  • Creates a new CompositeIndicator such that the result will be the product of the left to the right

Parameters:

Name Type Description Default
left Any | IndicatorBase

The left indicator

required
constant Optional[float]

The constant value to multiple by

None
right Optional[Any | IndicatorBase]

The right indicator

None
name Optional[str]

The name of this indicator

None

Returns:

Type Description
CompositeIndicator

The product of the left to the right indicators.

weighted_by

weighted_by(
    value: Any, weight: Any, period: int
) -> CompositeIndicator
weighted_by(
    value: IndicatorBase, weight: IndicatorBase, period: int
) -> CompositeIndicator

Creates a new CompositeIndicator such that the result will be average of a first indicator weighted by a second one

Parameters:

Name Type Description Default
value Any | IndicatorBase

Indicator that will be averaged

required
weight Any | IndicatorBase

Indicator that provides the average weights

required
period int

Average period

required

Returns:

Type Description
CompositeIndicator

Indicator that results of the average of first by weights given by second.

of

of(
    second: Any,
    first: Any,
    wait_for_first_to_ready: bool = True,
) -> IndicatorBase

Configures the second indicator to receive automatic updates from the first by attaching an event handler to first.DataConsolidated

Parameters:

Name Type Description Default
second Any

The indicator that receives data from the first

required
first Any

The indicator that sends data via DataConsolidated even to the second

required
wait_for_first_to_ready bool

True to only send updates to the second if first.IsReady returns true, false to always send updates to second

True

Returns:

Type Description
IndicatorBase

The reference to the second indicator to allow for method chaining.

update

update(
    indicator: IndicatorBase[IndicatorDataPoint],
    time: Union[datetime, date],
    value: float,
) -> bool

Updates the state of this indicator with the given value and returns true if this indicator is ready, false otherwise

Parameters:

Name Type Description Default
indicator IndicatorBase[IndicatorDataPoint]

The indicator to be updated

required
time Union[datetime, date]

The time associated with the value

required
value float

The value to use to update this indicator

required

Returns:

Type Description
bool

True if this indicator is ready, false otherwise.