---
title: "Indicators"
description: "A tutorial on how to contribute a custom indicator to Lean algorithmic trading engine."
canonical: https://www.quantconnect.com/docs/v2/lean-engine/contributions/indicators
markdown: https://www.quantconnect.com/docs/v2/lean-engine/contributions/indicators.md
language: python
source: https://github.com/QuantConnect/Documentation/tree/master/06%20LEAN%20Engine/02%20Contributions/03%20Indicators
modified: 2026-10-30
index: https://www.quantconnect.com/llms.txt
---

# Indicators

[Documentation](https://www.quantconnect.com/docs/v2.md) > [LEAN Engine](https://www.quantconnect.com/docs/v2/lean-engine.md) > Contributions > Indicators

> Code examples are shown in Python. Append `?lang=csharp` to this URL for the C# version of this page.

## Introduction

LEAN currently supports over 100 [indicators](https://www.quantconnect.com/docs/v2/writing-algorithms/indicators/supported-indicators.md). This page explains how to contribute a new indicator to the open-source project by making a pull request to Lean. Before you get started, familiarize yourself with our [contributing guidelines](https://github.com/QuantConnect/Lean/blob/master/CONTRIBUTING.md), and review [previous contributions](https://github.com/QuantConnect/Lean/pull/8454) to understand our standards. If you don't already have a new indicator in mind that you want to contribute, see [the GitHub Issues in the Lean repository](https://github.com/QuantConnect/Lean/issues?q=is%3Aopen+is%3Aissue+label%3Aindicator) for a list of indicators that community members have requested. Before you begin, create a GitHub Issue with a description of your proposed indicator, links to relevant resources, and source of [third-party values](https://www.quantconnect.com/docs/v2/lean-engine/contributions/indicators.md).

## Get Third-Party Values

As a quantitative algorithmic trading engine, accuracy and reliability are very important to LEAN. When you submit a new indicator to the LEAN, you must include third-party source values are required as reference points in your pull request to contrast the values output by your indicator implementation. This requirement validates that your indicator implementation is correct. The following sections explain some examples of acceptable third-party sources.

### Renowned Open-source Projects

Developed and maintained by expert teams, these sources undergo rigorous testing and optimization, ensuring accurate calculations. The transparent nature of open-source projects allows for community scrutiny, resulting in bug fixes and continuous improvements. Open-source projects provide thorough information on how the indicator values are calculated, which provides excellent reproducibility. Thus, we accept values from these projects with high confidence. Example projects include [TA-Lib](https://ta-lib.org/) and [QuantLib](https://www.quantlib.org/).

### Highly Credible Websites

Similar reasons apply to these websites as well. The site should be either the original source or a very popular trading data provider, such that we have confidence in their accuracy and reliability. These sources might provide structured data samples, like a `JSON` response, `CSV`/Excel file, or scripts for calculating the indicator values.

## Define the Class

To add a new indicator to Lean, add a class file to the `Lean / Indicators` directory. Indicators are classified as either a data point, bar, or `TradeBar` indicator. Their classification depends on the class they inherit and the type of data they receive. The following sections explain how to implement each type. Regardless of the indicator type, the class must define the following properties:

| Property | Type | Description |
| --- | --- | --- |
| `WarmUpPeriod` | `int` | The minimum number of data entries required to calculate an accurate indicator value. |
| `IsReady` | `bool` | A flag that states whether the indicator has sufficient data to generate values. |

The class must also define a `ComputeNextValue` method, which accepts some data and returns the indicator value. As shown in the following sections, the data/arguments that this method receives depends on the indicator type.

On rare occassions, some indicators can produce invalid values. For example, a moving average can produce unexpected values due to extreme quotes. In cases like these, override the `ValidateAndComputeNextValue` method to return an `IndicatorResult` with an `IndicatorStatus` enumeration. If the `IndicatorStatus` states the value is invalid, it won't be passed to the main algorithm. The `IndicatorStatus` enumeration has the following members:

*Members of `QuantConnect.Indicators.IndicatorStatus` (JSON): https://www.quantconnect.com/services/inspector?type=T:QuantConnect.Indicators.IndicatorStatus&language=python*

To enable the algorithm to warm up the indicator with the `WarmUpIndicator` method, inherit the `IIndicatorWarmUpPeriodProvider` interface.

If your indicator requires a moving average, see the [Extra Steps for Moving Averages Types](https://www.quantconnect.com/docs/v2/lean-engine/contributions/indicators.md#10-Extra-Steps-for-Moving-Average-Types) as you complete the following tutorial.

### Data Point Indicators

Data point indicators use `IndicatorDataPoint` objects to compute their value. These types of indicators can inherit the `IndicatorBase<IndicatorDataPoint>` or `WindowIndicator<IndicatorDataPoint>` class. The `WindowIndicator<IndicatorDataPoint>` class has several members to help you compute indicator values over multiple periods.

To view some example data point indicators that inherit the `IndicatorBase<IndicatorDataPoint>` class, see the implementation of the following indicators in the LEAN repository:

- [SharpeRatio](https://github.com/QuantConnect/Lean/blob/master/Indicators/SharpeRatio.cs)
- [DetrendedPriceOscillator](https://github.com/QuantConnect/Lean/blob/master/Indicators/DetrendedPriceOscillator.cs)
- [HullMovingAverage](https://github.com/QuantConnect/Lean/blob/master/Indicators/HullMovingAverage.cs)

To view some example data point indicators that inherit the `WindowIndicator<IndicatorDataPoint>` class, see the implementation of the following indicators in the LEAN repository:

- [SimpleMovingAverage](https://github.com/QuantConnect/Lean/blob/master/Indicators/SimpleMovingAverage.cs)
- [Momentum](https://github.com/QuantConnect/Lean/blob/master/Indicators/Momentum.cs)
- [Maximum](https://github.com/QuantConnect/Lean/blob/master/Indicators/Maximum.cs)

### Bar Indicators

Bar indicators use `QuoteBar` or `TradeBar` objects to compute their value. Since Forex and CFD securities don't have `TradeBar` data, they use bar indicators. Candlestick patterns are examples of bar indicators.

To view some example bar indicators, see the implementation of the following indicators in the LEAN repository:

- [WilliamsPercentR](https://github.com/QuantConnect/Lean/blob/master/Indicators/WilliamsPercentR.cs)
- [AverageTrueRange](https://github.com/QuantConnect/Lean/blob/master/Indicators/AverageTrueRange.cs)
- [Stochastics](https://github.com/QuantConnect/Lean/blob/master/Indicators/Stochastic.cs)

### TradeBar Indicators

`TradeBar` indicators use `TradeBar` objects to compute their value. Some `TradeBar` indicators use the volume property of the `TradeBar` to compute their value.

To view some example `TradeBar` indicators, see the implementation of the following indicators in the LEAN repository:

- [Beta](https://github.com/QuantConnect/Lean/blob/master/Indicators/Beta.cs)
- [AdvanceDeclineIndicator](https://github.com/QuantConnect/Lean/blob/master/Indicators/AdvanceDeclineIndicator.cs)
- [MassIndex](https://github.com/QuantConnect/Lean/blob/master/Indicators/MassIndex.cs)

## Define the Helper Method

The preceding indicator class is sufficient to instatiate a [manual version](https://www.quantconnect.com/docs/v2/writing-algorithms/indicators/manual-indicators.md) of the indicator. To enable users to create an [automatic version](https://www.quantconnect.com/docs/v2/writing-algorithms/indicators/automatic-indicators.md) of the indicator, add a new method to the `Lean / Algorithm / QCAlgorithm.Indicators.cs` file. Name the method a short abbreviation of the indicator's full name. In the method definition, call the `InitializeIndicator` method to create a [consolidator](https://www.quantconnect.com/docs/v2/writing-algorithms/consolidating-data/getting-started.md) and register the indicator for automatic updates with the consolidated data.

## Add Unit Tests

Unit tests ensure your indicator functions correctly and produces accurate values. Follow these steps to add unit tests for your indicator:

1. Save the [third-party values](https://www.quantconnect.com/docs/v2/lean-engine/contributions/indicators.md#02-Get-Third-Party-Values) in the `Lean / Tests / TestData` directory as a `CSV` file.
2. In the `Lean / Tests / QuantConnect.Tests.csproj` file, reference the new data file.
3. Create a `Lean / Tests / Indicators / <IndicatorName>Tests.cs` file with the following content:
4. Set the values of the `TestFileName` and `TestColumnName` attributes to the `CSV` file name and the column name of the testing values in the CSV file of third-party values, respectively.
5. Add test cases.
   Test if the constructor, `IsReady` flag, and `Reset` method work. If there are other custom calculation methods in your indicator class, add a tests for them.

The following example shows the testing class structure:

For a full example, see [SimpleMovingAverageTests.cs](https://github.com/QuantConnect/Lean/blob/master/Tests/Indicators/SimpleMovingAverageTests.cs) in the LEAN repository.

## Add Documentation

Follow these steps to document the indicator you're contributing:

1. In the [`Documentation / Resources / indicators / IndicatorImageGenerator.py`](https://github.com/QuantConnect/Documentation/blob/master/Resources/indicators/IndicatorImageGenerator.py) file, add the indicator to one of the following dictionaries:
- `indicators` if the indicator only involves one symbol and doesn't depend on other indicators
- `special_indicators` if the indicator involves multiple symbols or it's a composite indicator
- `option_indicators` if the indicator is an Option-related indicator (for example, Option greeks indicators)

The following code block explains the format of the key-value pairs of the dictionaries:

```python
'<hyphenated-title-case-of-the-indicator>': IndicatorInfo(
    <PythonConstructor>(<python-constructor-arguments>),
    '<CSharpHelperMethod>(<csharp-helper-method-arguments>)',
    'self.<python_helper_method>(<python-helper-method-arguments>)'
),
```

The fourth argument to the `IndicatorInfo` constructor defines which of the indicator's properties to plot on each subplot in the [Visualization](https://www.quantconnect.com/docs/v2/writing-algorithms/indicators/supported-indicators/regression-channel.md#03-Visualization) section of the documentation. By default, its value is `[['current']]`, which plots the `current` property on a single subplot. In this argument, each element in the list you pass defines which properties to plot on each subplot. Group properties that are on the same scale together so they show up on the same subplot. For example, the `AbsolutePriceOscillator` uses `[['fast', 'slow'], ['current', 'histogram', 'signal']]` to plot the `fast` and `slow` properties on the first subplot and plot the `current`, `histogram`, and `signal` properties on the second subplot.

- Save the file.
- Run the [`Documentation / code-generators / indicator_reference_code_generator.py`](https://github.com/QuantConnect/Documentation/blob/master/code-generators/indicator_reference_code_generator.py) file.

This script generates the indicator reference page. For an example, see [Simple Moving Average](https://www.quantconnect.com/docs/v2/writing-algorithms/indicators/supported-indicators/simple-moving-average.md).

- Submit a pull request to the [Documentation repository](https://github.com/QuantConnect/Documentation/) with your changes.

## Extra Steps for Moving Average Types

A moving average is a special type of indicator that smoothes out the fluctuations in a security's price or market data. It calculates the average value of a security's price over a specified period with a special smoothing function, helping traders to identify trends and reduce noise. Moving averages can also be used in conjunction with other technical indicators to make more informed trading decisions and identify potential support or resistance levels in the market. LEAN has extra abstraction interface for indicators to implement a specific type of moving average. The `MovingAverageType` enumeration currently has the following members:

*Members of `QuantConnect.Indicators.MovingAverageType` (JSON): https://www.quantconnect.com/services/inspector?type=T:QuantConnect.Indicators.MovingAverageType&language=python*

If you are contributing an indicator that requires a new moving average type, follow these additional steps:

1. In the `Lean / Indicators / MovingAverageType.cs` file, define a new `MovingAverageType` enumeration member.
2. In the `Lean / Indicators / MovingAverageTypeExtensions.cs` file, add a new case of your custom moving average indicator in each `AsIndicator` method.
3. In the `Lean / Tests/ Indicators / MovingAverageTypeExtensionsTests.cs` file, add a new test case of your custom moving average indicator that asserts the indicator is correctly instantiated through the abstraction methods.
