Algorithm Reference

Indicators

Introduction

We provide more than 100 technical indicators for you to use in your algorithm. These are provided in two ways; through helper short cut methods, and as class objects. Indicators created through the short cut methods have already been wired up to receive data and are "ready to use". A full list of the indicators and their properties can be found in the reference table below.

One key indicator to learn is the Identity indicator which simply returns the value of the asset. This can be useful for combining indicators together. For example:

var pep = Identity("PEP");     // Pepsi ticker
var coke = Identity("KO");     // Coke ticker
var delta = pep.Minus(coke);   // Difference between them
pep = Identity("PEP")   # Pepsi ticker
coke = Identity("KO")   # Coke ticker
delta = IndicatorExtensions.Minus(pep, coke)   # Difference between them

Indicator Ready

Indicators are not ready when you first create them. The length of time it takes to trust the indicator values depends on the indicator period. In QuantConnect we provide a shortcut to check the indicator status. indicator.IsReady will return true when the indicator is ready to be used. eg. IsReady

	if not self.indicator.IsReady:
		return
	if (!indicator.IsReady) return;

Initializing Indicators

You can use two methods to prime technical indicators and get them ready to be used.

Algorithm Warm-Up

When we set an algorithm warm-up period, the engine pumps data in and automatically update all the indicators from before the start date (see Setting Warm Up Period). To ensure that all the indicators are ready after the algorithm warm-up period, you need to choose a lookback period that contains the required data.

def Initialize(self):
    self.AddEquity("SPY", Resolution.Hour)
    # define a 10-period daily RSI indicator with shortcut helper method
    self.rsi = self.RSI("SPY", 10,  MovingAverageType.Simple, Resolution.Daily)
    # set a warm-up period to initialize the indicator
    self.SetWarmUp(timedelta(20))
    # Warm-up the indicator with bar count
    # self.SetWarmUp(10, Resolution.Daily)
public override void Initialize()
{
	AddEquity(_symbol, Resolution.Hour);
    // define a 10-period daily RSI indicator with shortcut helper method
    _rsi = RSI(_symbol, 10,  MovingAverageType.Simple, Resolution.Daily);
    // set a warm-up period to initialize the indicator
    SetWarmUp(TimeSpan.FromDays(20));
    // Or warm up the indicator with bar count
    // SetWarmUp(10, Resolution.Daily)
}

Universe Selection does not support Warm Up and, consequently, factors that depend on indicators are not updated.

History Request Warm-Up

Alternatively, we can request for historical data to update the indicator manually (see Historical Data Requests)

def Initialize(self):
    self.AddEquity("SPY", Resolution.Hour)
    # define a 10-period daily RSI indicator with shortcut helper method
    self.rsi = self.RSI("SPY", 10,  MovingAverageType.Simple, Resolution.Daily)
    # initialize the indicator with the daily history close price
    history = self.History(["SPY"], 10, Resolution.Daily)
        for time, row in history.loc["SPY"].iterrows():
            self.rsi.Update(time, row["close"])

public override void Initialize() {
    AddEquity(_symbol, Resolution.Hour);
    // define a 10-period daily RSI indicator with shortcut helper method
    _rsi = RSI(_symbol, 10,  MovingAverageType.Simple, Resolution.Daily);
    // initialize the indicator with the daily history close price
    var history = History(_symbol, 10, Resolution.Daily);
    foreach (var bar in history) {
        _rsi.Update(bar.EndTime, bar.Close);
    }
}

Basic Indicator Usage

QCAlgorithm provides a shortcut method for each indicator available. Each method creates an indicator object, hooks it up for automatic updates and returns it to be used in your algorithm.

You can determine the specific requirements of the indicator from the reference table below.

The indicator resolution can be different from the resolution of your securities data. However, the resolution of the indicator should be equal to or higher than the resolution of your security. For most cases, this usage should be in Initialize method. If you call this method several times, it will create a new indicator that is not ready to use.

The indicator object can be implicitly used as a decimal.

To retrieve the numerical value of any indicator, you can use the Current.Value attribute of the indicator.

def Initialize(self):
    # request the hourly equity data
    self.AddEquity("SPY", Resolution.Hour)
    # define a 10-period daily RSI indicator with shortcut helper method
    self.rsi = self.RSI("SPY", 10,  MovingAverageType.Simple, Resolution.Daily)

def OnData(self, data):
    # check if this algorithm is still warming up
    if self.rsi.IsReady:
        # get the current RSI value
        rsi_value = self.rsi.Current.Value
        # get the current average gain of rsi
        average_gain = self.rsi.AverageGain.Current.Value
        # get the current average loss of rsi
        average_loss = self.rsi.AverageLoss.Current.Value
public override void Initialize() {
    AddEquity(_symbol, Resolution.Hour);
    // define a 10-period daily RSI indicator with shortcut helper method
    _rsi = RSI(_symbol, 10,  MovingAverageType.Simple, Resolution.Daily);
}

public override void OnData(Slice data) {
    // check if this algorithm is still warming up
    if(!_rsi.IsReady) return;
    
    // Once ready, get the current RSI value
    var rsiValue = _rsi;
    // get the current average gain of rsi
    var averageGain = _rsi.AverageGain;
    // get the current average loss of rsi
    var averageLoss = _rsi.AverageLoss; 
}

Custom Period Indicators

You can create an indicator object that is not bound to any automatic update and choose which data it should use. To use an indicator like this, you create an indicator with its constructor.

To see the LEAN indicator classes available and their constructor arguments, please look them up in the reference table below.

You can use two methods to update the indicator: automatic or manual.

Automatic Update

In this method, you will recreate the basic indicator usage: create an indicator with its constructor and register the indicator for automatic updates with the RegisterIndicator() method.

# request the daily equity data
self.AddEquity("SPY", Resolution.Daily)
# define a 10-period RSI indicator with indicator constructor
self.rsi = RelativeStrengthIndex(10, MovingAverageType.Simple)
# register the daily data of "SPY" to automatically update the indicator
self.RegisterIndicator("SPY", self.rsi, Resolution.Daily)
// request the daily equity data
AddEquity("SPY", Resolution.Daily);
// define a 10-period RSI indicator with indicator constructor
_rsi = new RelativeStrengthIndex(10, MovingAverageType.Simple);
// register the daily data of "SPY" to automatically update the indicator
RegisterIndicator("SPY", _rsi, Resolution.Daily);

Other than the available resolutions, you can also update the indicator with the consolidator. For details about data consolidator, please see Consolidating Data.

# request the equity data in minute resolution
self.AddEquity("SPY", Resolution.Minute)
# define a 10-period RSI indicator with indicator constructor
self.rsi = RelativeStrengthIndex(10, MovingAverageType.Simple)
# create the 30-minutes data consolidator
thirtyMinuteConsolidator = TradeBarConsolidator(timedelta(minutes=30))
self.SubscriptionManager.AddConsolidator("SPY", thirtyMinuteConsolidator)
# register the 30-minute consolidated bar data to automatically update the indicator
self.RegisterIndicator("SPY", self.rsi, thirtyMinuteConsolidator)
// request the equity data in minute resolution
AddEquity(_symbol, Resolution.Hour);
// define a 10-period RSI indicator with indicator constructor
_rsi = new RelativeStrengthIndex(10, MovingAverageType.Simple);
// create the 30-minutes data consolidator
var thirtyMinuteConsolidator = new TradeBarConsolidator(TimeSpan.FromMinutes(30));
SubscriptionManager.AddConsolidator("SPY", thirtyMinuteConsolidator);
// register the 30-minute consolidated bar data to automatically update the indicator
RegisterIndicator("SPY", _rsi,thirtyMinuteConsolidator);

Manual Update

Updating your indicator manually allows you to control which data is used and create indicators of other non-price fields. For instance, you can use the 3:30 pm price in your daily moving average instead of the after-market closing price or you may want to use the maximum temperature of the past 10 cloudy days.

The indicator objects have the Update() method that updates the state of an indicator with the given value. Depending on the different types of indicators, this value can be the time/decimal pair, a trade bar, quote bar or a custom data bar.

With this method, the indicator will only be ready after it the Update() method has been used to pump enough data. For example, a 10-period daily moving average needs to receive ten daily data points through the Update() method.

def Initialize(self):
    self.AddEquity("SPY", Resolution.Daily)
    self.rsi = RelativeStrengthIndex(10, MovingAverageType.Simple)

def OnData(self, data):
    # update the indicator value with the new input close price every day
    if data.Bars.ContainsKey("SPY"):
        self.rsi.Update(data["SPY"].EndTime, data["SPY"].Close)
    # check if the indicator is ready
    if self.rsi.IsReady:
        # get the current RSI value
        rsi_value = self.rsi.Current.Value
public override void Initialize() {
    AddEquity(_symbol, Resolution.Daily);
    _rsi = new RelativeStrengthIndex(10, MovingAverageType.Simple);
}

public override void OnData(Slice data) {
    // update the indicator value with the new input close price every day
    if (data.Bars.ContainsKey(_symbol)) {
        _rsi.Update(data[_symbol].EndTime, data[_symbol].Close);
    }
    // check if the indicator is ready
    if (_rsi.IsReady) {
    // get the current RSI value
        var rsiValue = _rsi;
    }
}

In both cases, we recommend using historical data to warm up your indicator as demonstrated in Initializing Indicators.

Updating Indicators with Custom Values

Some indicators, the data point indicators, use only a single price data in their calculations. By default, those indicators use the closing price. For equity, that price is the trade bar closing price. For other asset classes with quote bar data (bid/ask price), those indicators are calculated with the mid-price of the bid closing price and the ask closing price.

If you want to create an indicator with the other fields like Open, High, Low, Close, you can specify the selector argument in indicator helper method with the available fields.

# define a 10-period daily RSI indicator with shortcut helper method
# select the Open price to update the indicator
self.rsi = self.RSI("SPY", 10,  MovingAverageType.Simple, Resolution.Daily, Field.Open)
// define a 10-period daily RSI indicator with shortcut helper method
// select the Open price to update the indicator
_rsi = RSI("SPY", 10,  MovingAverageType.Simple, Resolution.Daily, Field.Open);

You can also apply RegisterIndicator to register the price data with the specified field.

# define a 10-period RSI with indicator constructor
self.rsi = RelativeStrengthIndex(10, MovingAverageType.Simple)
# register the daily High price data to automatically update the indicator
self.RegisterIndicator("SPY", self.rsi, Resolution.Daily, Field.High)
// define a 10-period RSI with indicator constructor
_rsi = new RelativeStrengthIndex(10, MovingAverageType.Simple);
// register the daily High price data to automatically update the indicator
RegisterIndicator("SPY", _rsi, Resolution.Daily, Field.High);

Reference Table

Indicators Usage
AccelerationBands var abands = ABANDS(Symbol symbol, int period, decimal width = 4, MovingAverageType movingAverageType = null, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.TradeBar] selector = null)
AccumulationDistribution var ad = AD(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.TradeBar] selector = null)
AccumulationDistributionOscillator var adosc = ADOSC(Symbol symbol, int fastPeriod, int slowPeriod, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.TradeBar] selector = null)
AverageDirectionalIndex var adx = ADX(Symbol symbol, int period, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
AverageDirectionalMovementIndexRating var adxr = ADXR(Symbol symbol, int period, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
ArnaudLegouxMovingAverage var alma = ALMA(Symbol symbol, int period, int sigma = 6, decimal offset = 0.85, Resolution resolution = null, Func`2[Data.IBaseData,Decimal] selector = null)
AbsolutePriceOscillator var apo = APO(Symbol symbol, int fastPeriod, int slowPeriod, MovingAverageType movingAverageType, Resolution resolution = null, Func`2[Data.IBaseData,Decimal] selector = null)
AroonOscillator var aroon = AROON(Symbol symbol, int period, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
AroonOscillator var aroon = AROON(Symbol symbol, int upPeriod, int downPeriod, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
AverageTrueRange var atr = ATR(Symbol symbol, int period, MovingAverageType type = null, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
BollingerBands var bb = BB(Symbol symbol, int period, decimal k, MovingAverageType movingAverageType = null, Resolution resolution = null, Func`2[Data.IBaseData,Decimal] selector = null)
BalanceOfPower var bop = BOP(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
CoppockCurve var cc = CC(Symbol symbol, int shortRocPeriod = 11, int longRocPeriod = 14, int lwmaPeriod = 10, Resolution resolution = null, Func`2[Data.IBaseData,Decimal] selector = null)
CommodityChannelIndex var cci = CCI(Symbol symbol, int period, MovingAverageType movingAverageType = null, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
ChandeMomentumOscillator var cmo = CMO(Symbol symbol, int period, Resolution resolution = null, Func`2[Data.IBaseData,Decimal] selector = null)
DonchianChannel var dch = DCH(Symbol symbol, int upperPeriod, int lowerPeriod, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
DonchianChannel var dch = DCH(Symbol symbol, int period, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
DoubleExponentialMovingAverage var dema = DEMA(Symbol symbol, int period, Resolution resolution = null, Func`2[Data.IBaseData,Decimal] selector = null)
DetrendedPriceOscillator var dpo = DPO(Symbol symbol, int period, Resolution resolution = null, Func`2[Data.IBaseData,Decimal] selector = null)
ExponentialMovingAverage var ema = EMA(Symbol symbol, int period, Resolution resolution = null, Func`2[Data.IBaseData,Decimal] selector = null)
FractalAdaptiveMovingAverage var frama = FRAMA(Symbol symbol, int period, int longPeriod = 198, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
HullMovingAverage var hma = HMA(Symbol symbol, int period, Resolution resolution = null, Func`2[Data.IBaseData,Decimal] selector = null)
IchimokuKinkoHyo var ichimoku = ICHIMOKU(Symbol symbol, int tenkanPeriod, int kijunPeriod, int senkouAPeriod, int senkouBPeriod, int senkouADelayPeriod, int senkouBDelayPeriod, Resolution resolution = null)
KaufmanAdaptiveMovingAverage var kama = KAMA(Symbol symbol, int period, Resolution resolution = null, Func`2[Data.IBaseData,Decimal] selector = null)
KeltnerChannels var kch = KCH(Symbol symbol, int period, decimal k, MovingAverageType movingAverageType = null, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
LogReturn var logr = LOGR(Symbol symbol, int period, Resolution resolution = null, Func`2[Data.IBaseData,Decimal] selector = null)
LeastSquaresMovingAverage var lsma = LSMA(Symbol symbol, int period, Resolution resolution = null, Func`2[Data.IBaseData,Decimal] selector = null)
LinearWeightedMovingAverage var lwma = LWMA(Symbol symbol, int period, Resolution resolution = null, Func`2[Data.IBaseData,Decimal] selector = null)
MovingAverageConvergenceDivergence var macd = MACD(Symbol symbol, int fastPeriod, int slowPeriod, int signalPeriod, MovingAverageType type = 1, Resolution resolution = null, Func`2[Data.IBaseData,Decimal] selector = null)
MeanAbsoluteDeviation var mad = MAD(Symbol symbol, int period, Resolution resolution = null, Func`2[Data.IBaseData,Decimal] selector = null)
MassIndex var mass = MASS(Symbol symbol, int emaPeriod = 9, int sumPeriod = 25, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.TradeBar] selector = null)
Maximum var max = MAX(Symbol symbol, int period, Resolution resolution = null, Func`2[Data.IBaseData,Decimal] selector = null)
MoneyFlowIndex var mfi = MFI(Symbol symbol, int period, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.TradeBar] selector = null)
MidPoint var midpoint = MIDPOINT(Symbol symbol, int period, Resolution resolution = null, Func`2[Data.IBaseData,Decimal] selector = null)
MidPrice var midprice = MIDPRICE(Symbol symbol, int period, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
Minimum var min = MIN(Symbol symbol, int period, Resolution resolution = null, Func`2[Data.IBaseData,Decimal] selector = null)
Momentum var mom = MOM(Symbol symbol, int period, Resolution resolution = null, Func`2[Data.IBaseData,Decimal] selector = null)
MomersionIndicator var momersion = MOMERSION(Symbol symbol, int minPeriod, int fullPeriod, Resolution resolution = null, Func`2[Data.IBaseData,Decimal] selector = null)
MomentumPercent var momp = MOMP(Symbol symbol, int period, Resolution resolution = null, Func`2[Data.IBaseData,Decimal] selector = null)
NormalizedAverageTrueRange var natr = NATR(Symbol symbol, int period, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
OnBalanceVolume var obv = OBV(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.TradeBar] selector = null)
PercentagePriceOscillator var ppo = PPO(Symbol symbol, int fastPeriod, int slowPeriod, MovingAverageType movingAverageType, Resolution resolution = null, Func`2[Data.IBaseData,Decimal] selector = null)
ParabolicStopAndReverse var psar = PSAR(Symbol symbol, decimal afStart = 0.02, decimal afIncrement = 0.02, decimal afMax = 0.2, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
RegressionChannel var rc = RC(Symbol symbol, int period, decimal k, Resolution resolution = null, Func`2[Data.IBaseData,Decimal] selector = null)
RateOfChange var roc = ROC(Symbol symbol, int period, Resolution resolution = null, Func`2[Data.IBaseData,Decimal] selector = null)
RateOfChangePercent var rocp = ROCP(Symbol symbol, int period, Resolution resolution = null, Func`2[Data.IBaseData,Decimal] selector = null)
RateOfChangeRatio var rocr = ROCR(Symbol symbol, int period, Resolution resolution = null, Func`2[Data.IBaseData,Decimal] selector = null)
RelativeStrengthIndex var rsi = RSI(Symbol symbol, int period, MovingAverageType movingAverageType = 2, Resolution resolution = null, Func`2[Data.IBaseData,Decimal] selector = null)
SimpleMovingAverage var sma = SMA(Symbol symbol, int period, Resolution resolution = null, Func`2[Data.IBaseData,Decimal] selector = null)
StandardDeviation var std = STD(Symbol symbol, int period, Resolution resolution = null, Func`2[Data.IBaseData,Decimal] selector = null)
Stochastic var sto = STO(Symbol symbol, int period, int kPeriod, int dPeriod, Resolution resolution = null)
Stochastic var sto = STO(Symbol symbol, int period, Resolution resolution = null)
Sum var sum = SUM(Symbol symbol, int period, Resolution resolution = null, Func`2[Data.IBaseData,Decimal] selector = null)
SwissArmyKnife var swiss = SWISS(Symbol symbol, int period, Double delta, SwissArmyKnifeTool tool, Resolution resolution = null, Func`2[Data.IBaseData,Decimal] selector = null)
T3MovingAverage var t3 = T3(Symbol symbol, int period, decimal volumeFactor = 0.7, Resolution resolution = null, Func`2[Data.IBaseData,Decimal] selector = null)
TripleExponentialMovingAverage var tema = TEMA(Symbol symbol, int period, Resolution resolution = null, Func`2[Data.IBaseData,Decimal] selector = null)
TrueRange var tr = TR(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
TriangularMovingAverage var trima = TRIMA(Symbol symbol, int period, Resolution resolution = null, Func`2[Data.IBaseData,Decimal] selector = null)
Trix var trix = TRIX(Symbol symbol, int period, Resolution resolution = null, Func`2[Data.IBaseData,Decimal] selector = null)
UltimateOscillator var ultosc = ULTOSC(Symbol symbol, int period1, int period2, int period3, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
Variance var var = VAR(Symbol symbol, int period, Resolution resolution = null, Func`2[Data.IBaseData,Decimal] selector = null)
VolumeWeightedAveragePriceIndicator var vwap = VWAP(Symbol symbol, int period, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.TradeBar] selector = null)
IntradayVwap var vwap = VWAP(Symbol symbol)
WilliamsPercentR var wilr = WILR(Symbol symbol, int period, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
WilderMovingAverage var wwma = WWMA(Symbol symbol, int period, Resolution resolution = null, Func`2[Data.IBaseData,Decimal] selector = null)
Candlesticks Patterns Usage
TwoCrows var twocrows = CandlestickPatterns.TwoCrows(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
ThreeBlackCrows var threeblackcrows = CandlestickPatterns.ThreeBlackCrows(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
ThreeInside var threeinside = CandlestickPatterns.ThreeInside(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
ThreeLineStrike var threelinestrike = CandlestickPatterns.ThreeLineStrike(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
ThreeOutside var threeoutside = CandlestickPatterns.ThreeOutside(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
ThreeStarsInSouth var threestarsinsouth = CandlestickPatterns.ThreeStarsInSouth(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
ThreeWhiteSoldiers var threewhitesoldiers = CandlestickPatterns.ThreeWhiteSoldiers(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
AbandonedBaby var abandonedbaby = CandlestickPatterns.AbandonedBaby(Symbol symbol, decimal penetration = 0.3, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
AdvanceBlock var advanceblock = CandlestickPatterns.AdvanceBlock(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
BeltHold var belthold = CandlestickPatterns.BeltHold(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
Breakaway var breakaway = CandlestickPatterns.Breakaway(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
ClosingMarubozu var closingmarubozu = CandlestickPatterns.ClosingMarubozu(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
ConcealedBabySwallow var concealedbabyswallow = CandlestickPatterns.ConcealedBabySwallow(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
Counterattack var counterattack = CandlestickPatterns.Counterattack(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
DarkCloudCover var darkcloudcover = CandlestickPatterns.DarkCloudCover(Symbol symbol, decimal penetration = 0.5, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
Doji var doji = CandlestickPatterns.Doji(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
DojiStar var dojistar = CandlestickPatterns.DojiStar(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
DragonflyDoji var dragonflydoji = CandlestickPatterns.DragonflyDoji(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
Engulfing var engulfing = CandlestickPatterns.Engulfing(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
EveningDojiStar var eveningdojistar = CandlestickPatterns.EveningDojiStar(Symbol symbol, decimal penetration = 0.3, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
EveningStar var eveningstar = CandlestickPatterns.EveningStar(Symbol symbol, decimal penetration = 0.3, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
GapSideBySideWhite var gapsidebysidewhite = CandlestickPatterns.GapSideBySideWhite(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
GravestoneDoji var gravestonedoji = CandlestickPatterns.GravestoneDoji(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
Hammer var hammer = CandlestickPatterns.Hammer(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
HangingMan var hangingman = CandlestickPatterns.HangingMan(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
Harami var harami = CandlestickPatterns.Harami(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
HaramiCross var haramicross = CandlestickPatterns.HaramiCross(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
HighWaveCandle var highwavecandle = CandlestickPatterns.HighWaveCandle(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
Hikkake var hikkake = CandlestickPatterns.Hikkake(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
HikkakeModified var hikkakemodified = CandlestickPatterns.HikkakeModified(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
HomingPigeon var homingpigeon = CandlestickPatterns.HomingPigeon(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
IdenticalThreeCrows var identicalthreecrows = CandlestickPatterns.IdenticalThreeCrows(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
InNeck var inneck = CandlestickPatterns.InNeck(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
InvertedHammer var invertedhammer = CandlestickPatterns.InvertedHammer(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
Kicking var kicking = CandlestickPatterns.Kicking(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
KickingByLength var kickingbylength = CandlestickPatterns.KickingByLength(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
LadderBottom var ladderbottom = CandlestickPatterns.LadderBottom(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
LongLeggedDoji var longleggeddoji = CandlestickPatterns.LongLeggedDoji(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
LongLineCandle var longlinecandle = CandlestickPatterns.LongLineCandle(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
Marubozu var marubozu = CandlestickPatterns.Marubozu(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
MatchingLow var matchinglow = CandlestickPatterns.MatchingLow(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
MatHold var mathold = CandlestickPatterns.MatHold(Symbol symbol, decimal penetration = 0.5, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
MorningDojiStar var morningdojistar = CandlestickPatterns.MorningDojiStar(Symbol symbol, decimal penetration = 0.3, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
MorningStar var morningstar = CandlestickPatterns.MorningStar(Symbol symbol, decimal penetration = 0.3, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
OnNeck var onneck = CandlestickPatterns.OnNeck(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
Piercing var piercing = CandlestickPatterns.Piercing(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
RickshawMan var rickshawman = CandlestickPatterns.RickshawMan(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
RiseFallThreeMethods var risefallthreemethods = CandlestickPatterns.RiseFallThreeMethods(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
SeparatingLines var separatinglines = CandlestickPatterns.SeparatingLines(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
ShootingStar var shootingstar = CandlestickPatterns.ShootingStar(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
ShortLineCandle var shortlinecandle = CandlestickPatterns.ShortLineCandle(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
SpinningTop var spinningtop = CandlestickPatterns.SpinningTop(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
StalledPattern var stalledpattern = CandlestickPatterns.StalledPattern(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
StickSandwich var sticksandwich = CandlestickPatterns.StickSandwich(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
Takuri var takuri = CandlestickPatterns.Takuri(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
TasukiGap var tasukigap = CandlestickPatterns.TasukiGap(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
Thrusting var thrusting = CandlestickPatterns.Thrusting(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
Tristar var tristar = CandlestickPatterns.Tristar(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
UniqueThreeRiver var uniquethreeriver = CandlestickPatterns.UniqueThreeRiver(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
UpsideGapTwoCrows var upsidegaptwocrows = CandlestickPatterns.UpsideGapTwoCrows(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)
UpDownGapThreeMethods var updowngapthreemethods = CandlestickPatterns.UpDownGapThreeMethods(Symbol symbol, Resolution resolution = null, Func`2[Data.IBaseData,Data.Market.IBaseDataBar] selector = null)

// 1. Using basic indicator at the same resolution as source security:
// TIP -> You can use string "IBM" or the security.Symbol object
var ema = EMA("IBM", 14);
var rsi = RSI("IBM", 14);

//2. Using indicator at different (higher) resolution to the source security:
var emaDaily = EMA("IBM", 14, Resolution.Daily);

//3. Indicator of a different property (default is close of bar/data):
// TIP -> You can use helper methods Field.Open, Field.High etc on the indicator selector:
var emaDailyHigh = EMA("IBM", 14, Resolution.Daily, point => ((TradeBar) point).High);

//4. Using the indicators:
//4.1  Setup in initialize:
_emaFast = EMA("IBM", 14);
_emaSlow = EMA("IBM", 28);

//4.2 Use in OnData:
if (_emaSlow.IsReady && _emaFast.IsReady) {
   if (_emaFast > _emaSlow) {
       //Long.
   } else if (_emaFast < _emaSlow) {
       //Short.
   } 
}

//NOTE. Some indicators require tradebars (ATR, AROON) so your selector must return a TradeBar object for those indicators.
# 1. Using basic indicator at the same resolution as source security:
self.ema = self.EMA("IBM", 14)
self.rsi = self.RSI("IBM", 14)

#2. Using indicator at different (higher) resolution to the source security:
self.emaDaily = self.EMA("IBM", 14, Resolution.Daily)

#3. Indicator of a different property (default is close of bar/data):
self.emaDailyHigh = self.EMA("IBM", 14, Resolution.Daily, Field.High)


#4. Using the indicators:
#4.1  Setup in initialize: make sure you've asked for the data for the asset.
self.AddEquity("IBM")
self.emaFast = self.EMA("IBM", 14);
self.emaSlow = self.EMA("IBM", 28);

#4.2 Consume the indicators in OnData.
if self.emaSlow.IsReady and self.emaFast.IsReady:
    if self.emaFast.Current.Value > self.emaSlow.Current.Value:
        self.Debug("Long")
    elif self.emaFast.Current.Value < self.emaSlow.Current.Value:
        self.Debug("Short")

Indicator Extensions

Indicators are composable - meaning they can be chained together to create unique combinations much like lego blocks. We support several indicator extensions as outlined below:

Extension Example Usage
.Plus()
var emaSum = ema5.Plus(ema20);
Add a fixed value or indicator value to another indicator
.Minus()
var emaDelta = ema20.Minus(ema5);
Find the difference between two indicators
.Times()
var rsiSafe = rsi.Times(0.95);
Multiply one indicator or constant value by another.
.Over()
var emaAverage = ema5.Plus(ema10).Over(2);
Divide indicator chain by constant or indicator.
.Of()
var sma = new SimpleMovingAverage("SPY", 14);
var rsiAverage= sma.Of( rsi );
Feed an indicator output into input of another.
.SMA(int period)
var rsiAvg = rsi.SMA(10);
Of extension helper for SMA method.
.EMA(int period)
var rsiAvg = rsi.EMA(10);
Of extension helper for EMA method.
.MAX(int period)
var rsiMax = rsi.MAX(10);
Of extension helper for MAX method, get max in i-samples.
.MIN(int period)
var rsiMin = rsi.MIN(10);
Of extension helper for MIN method, get min in i-samples.

Extension Example Usage
.Plus()
emaSum = IndicatorExtensions.Plus(ema20, ema5)
Add a fixed value or indicator value to another indicator
.Minus()
emaDelta = IndicatorExtensions.Minus(ema5, ema20)
Find the difference between two indicators
.Times()
rsiSafe = IndicatorExtensions.Times(rsi, 0.95)
Multiply one indicator or constant value by another.
.Over()
emaAverage = IndicatorExtensions.Over(IndicatorExtensions.Plus(ema10, ema5), 2)
Divide indicator chain by constant or indicator.
.Of()
sma = SimpleMovingAverage("SPY", 14)
rsiAverage= IndicatorExtensions.Of(rsi, sma)
Feed an indicator output into input of another.
.SMA(int period)
rsiAvg = IndicatorExtensions.SMA(rsi, 10)
Of extension helper for SMA method.
.EMA(int period)
rsiAvg = IndicatorExtensions.EMA(rsi, 10)
Of extension helper for EMA method.
.MAX(int period)
rsiMax = IndicatorExtensions.MAX(rsi, 10)
Of extension helper for MAX method, get max in i-samples.
.MIN(int period)
rsiMin = IndicatorExtensions.MIN(rsi, 10)
Of extension helper for MIN method, get min in i-samples.

public class IndicatorTests : QCAlgorithm
{
    //Save off reference to indicator objects
    RelativeStrengthIndex _rsi;
    SimpleMovingAverage _rsiSMA;

    public override void Initialize()
    {
       //In addition to other initialize logic:
       _rsi = RSI("SPY", 14); // Creating a RSI
       _rsiSMA = _rsi.SMA(3); // Creating the SMA on the RSI
    }
    
    public override void OnData(Slice data)
    {
       Plot("RSI", _rsi, _rsiSMA);
    }
}
class IndicatorTests(QCAlgorithm):
    def Initialize():
       # In addition to other initialize logic:
       self.rsi = self.RSI("SPY", 14)                     # Creating a RSI
       self.rsiSMA = IndicatorExtensions.SMA(self.rsi, 3) # Creating the SMA on the RSI
       self.PlotIndicator("RSI", self.rsi, self.rsiSMA)

Plotting Indicators

We provide a helper method which aims to make plotting indicators simple. For further information on the charting API please see our Charting section.

Plot(string chart, Indicator[] indicators)
self.Plot(string chart, Indicator[] indicators)

Note that not all indicators share the same base type(T) so may not work together as some indicators require points where others require TradeBars.

//Plot array of indicator objects; extending "Indicator" type.
Plot("Indicators", sma, rsi); 

//Plot array of indicator objects; extending "TradeBarIndicator" type.
Plot("Indicators", atr, aroon); 

//For complex plotting it might be easiest to simply plot your indicators individually.
#Plot array of indicator objects; extending "Indicator" type.
self.Plot("Indicators", sma, rsi); 

#Plot array of indicator objects; extending "TradeBarIndicator" type.
self.Plot("Indicators", atr, aroon); 

#Currently, there is a limit of 4 indicators for each Plot call
#For complex plotting it might be easiest to simply plot your indicators individually.

You can also see our Tutorials and Videos. You can also get in touch with us via Chat.

Did you find this page Helpful ?