QuantConnect Lean Algorithmic Trading Engine
Indicators > Introduction to Indicators
Introduction to Indicators

Lean has built a custom indicator system into the foundation of the engine. This has enabled us to build lots of functionality right out of the box to be more useful for quickly designing algorithms. You can access the default indicators with the QCAlgorithm helper methods (such as EMA), or create your own indicator using the foundational classes. Indicators are all located in the QuantConnect.Indicators namespace.

The simplest way to use an indicator is through its helper method:

Creating an Indicator in QCAlgorithm
Copy Code
var ema = EMA("SPY", 5, Resolution.Daily);

Key Concepts

Consolidators

Indicators can be instructed to act over any time period using the built in Consolidators. Consolidators combine arbitary periods of data together and feed the resulting object into the indicator allowing you to quickly design an algorithm which acts over a longer period without writing lots of additional code. Lean automatically creates these indicators when you call a helper method.

Registering an Indicator

Indicator classes can be used independently in your code; but in order to recieve automatic data updates they must be registered. Registering an indicator happens automatically in the helper methods, but if you're creating your own indicator you must manually register it. There are many overloads in the base class to make this a simple process.

Registering an Indicator
Copy Code
RegisterIndicator("SPY", myIndicatorObject, Resolution.Daily);

Helper Methods

All indicators helper methods in the QCAlgorithm base class to assist your coding. These methods provide a short code for the indicator and return a new, registered instance of the indicator object ready for use in your code. The helper classes are typically the acronym of the indicator name (e.g. Simple Moving Average has the helper method SMA). See a full list of these helper methods in the Indicators Reference Table.

Joining and Combining Indicators

Indicators can be chained together to find unique combinations. These joined indicators are called Composite Indicators. The extension methods available are similar to mathematical functions.

Example Description
var rsiAverage = sma.Of( rsi ); Simple moving average indicator object getting data from the relative strength index output.
var emaSum = ema5.Plus(ema20); Adds the ema5 to the ema20 and places the result in composite indicator.
var emaDelta = ema20.Minus(ema5); Subtracts the ema5 from the ema20 and returns the indicator to composite variable.
var rsiSafe = rsi.Times(0.95); Multiplies the rsi output by 95% and returns the new indicator to composite variable.
var emaAverage = ema5.Plus(ema10).Over(2); Get the average of the ema5 and ema10 as a new indicator.

For more information see the Composite Indicators documentation.

Indicators Available

A full table of indicators available and their helper methods can be found on the Indicators Reference Table page.

Indicator Overloads

Thanks to overloading in the indicator class the indicator object can be used directly in place of a decimal number. This enables use of indicators a decimals as demonstrated in the code example below.

 

See Also