Supported Indicators

Keltner Channels

Introduction

This indicator creates a moving average (middle band) with an upper band and lower band fixed at k average True range multiples away from the middle band.

Create Manual Indicators

You can manually create a KeltnerChannels indicator, so it doesn’t automatically update. Manual indicators let you update their values with any data you choose. The following reference table describes the KeltnerChannels constructor.

KeltnerChannels()1/2

            KeltnerChannels QuantConnect.Indicators.KeltnerChannels (
     int                 period,
     decimal             k,
     *MovingAverageType  movingAverageType
   )
        

Initializes a new instance of the KeltnerChannels class.

KeltnerChannels()2/2

            KeltnerChannels QuantConnect.Indicators.KeltnerChannels (
     string              name,
     int                 period,
     decimal             k,
     *MovingAverageType  movingAverageType
   )
        

Initializes a new instance of the KeltnerChannels class.

The following table shows the MovingAverageType enumeration members and the indicator that implements each one:

MovingAverageTypeUnderlying Indicator
SimpleSimple Moving Average
ExponentialExponential Moving Average
WildersWilder Moving Average
LinearWeightedMovingAverageLinear Weighted Moving Average
DoubleExponentialDouble Exponential Moving Average
TripleExponentialTriple Exponential Moving Average
TriangularTriangular Moving Average
T3T3 Moving Average
KamaKaufman Adaptive Moving Average
HullHull Moving Average
AlmaArnaud Legoux Moving Average

Update Manual Indicators

You can update the indicator automatically or manually.

Automatic Update

To register a manual indicator for automatic updates with the security data, call the RegisterIndicator method.


private KeltnerChannels _kch;

// In Initialize()
_kch = new KeltnerChannels(name, period, k);
_kch.Updated += IndicatorUpdateMethod;

RegisterIndicator(symbol, _kch, Resolution.Daily);

// In IndicatorUpdateMethod()
if (_kch.IsReady)
{
    var indicatorValue = _kch.Current.Value;
}
    
# In Initialize()
self.kch = KeltnerChannels(name, period, k)
self.kch.Updated += self.IndicatorUpdateMethod

self.RegisterIndicator(symbol, self.kch, Resolution.Daily)

# In IndicatorUpdateMethod()
if self.kch.IsReady:
    indicator_value = self.kch.Current.Value

To customize the data that automatically updates the indicator, see Custom Indicator Periods and Custom Indicator Values.

Manual Update

Updating your indicator manually enables you to control when the indicator is updated and what data you use to update it. To manually update the indicator, call the Update method with a TradeBar, QuoteBar, or an IndicatorDataPoint. The indicator will only be ready after you prime it with enough data.

    
private KeltnerChannels _kch;
private Symbol symbol;

// In Initialize()
_kch = new KeltnerChannels(period, k);
symbol = AddEquity("SPY").Symbol;

// In OnData()
if (data.QuoteBars.ContainsKey(_symbol))
{
    _kch.Update(data.QuoteBars[symbol]);
}
if (_kch.IsReady)
{
    var indicatorValue = _kch.Current.Value;
}
    
# In Initialize()
self.kch = KeltnerChannels(period, k)
self.symbol = self.AddEquity("SPY").Symbol

# In OnData()
if data.QuoteBars.ContainsKey(self.symbol):
    self.kch.Update(data.QuoteBars[self.symbol])
if self.kch.IsReady:
    indicator_value = self.kch.Current.Value

Create Automatic Indicators

The KCH method creates an KeltnerChannels indicator, sets up a consolidator to update the indicator, and then returns the indicator so you can use it in your algorithm.

The following reference table describes the KCH method:

KCH()1/1

            KeltnerChannels QuantConnect.Algorithm.QCAlgorithm.KCH (
    Symbol                                symbol,
    Int32                                 period,
    Decimal                               k,
    *MovingAverageType                    movingAverageType,
    *Nullable<Resolution>           resolution,
    *Func<IBaseData, IBaseDataBar>  selector
   )
        

Creates a new Keltner Channels indicator. The indicator will be automatically updated on the given resolution.


The following table shows the MovingAverageType enumeration members and the indicator that implements each one:

MovingAverageTypeUnderlying Indicator
SimpleSimple Moving Average
ExponentialExponential Moving Average
WildersWilder Moving Average
LinearWeightedMovingAverageLinear Weighted Moving Average
DoubleExponentialDouble Exponential Moving Average
TripleExponentialTriple Exponential Moving Average
TriangularTriangular Moving Average
T3T3 Moving Average
KamaKaufman Adaptive Moving Average
HullHull Moving Average
AlmaArnaud Legoux Moving Average

If you don't provide a resolution, it defaults to the security resolution. If you provide a resolution, it must be greater than or equal to the resolution of the security. For instance, if you subscribe to hourly data for a security, you should update its indicator with data that spans 1 hour or longer.

For more information about the selector argument, see Alternative Price Fields.

Get Indicator Values

To get the value of the indicator, use its Current.Value attribute.

private KeltnerChannels _kch;

// In Initialize()
var symbol = AddEquity("SPY").Symbol;
_kch = KCH(symbol, period, k);

// In OnData()
if (_kch.IsReady)
{
    var middleBand = _kch.MiddleBand.Current.Value;
    var upperBand = _kch.UpperBand.Current.Value;
    var lowerBand = _kch.LowerBand.Current.Value;
    var averageTrueRange = _kch.AverageTrueRange.Current.Value;
    var current = _kch.Current.Value;
}
# In Initialize()
symbol = self.AddEquity("SPY").Symbol
self.kch = self.KCH(symbol, period, k)

# In OnData()
if self.kch.IsReady:
    middle_band = self.kch.MiddleBand.Current.Value
    upper_band = self.kch.UpperBand.Current.Value
    lower_band = self.kch.LowerBand.Current.Value
    average_true_range = self.kch.AverageTrueRange.Current.Value
    current = self.kch.Current.Value

Visualization

To plot indicator values, in the OnData event handler, call the Plot method.

private KeltnerChannels _kch;

// In Initialize()
var symbol = AddEquity("SPY").Symbol;
_kch = KCH(symbol, period, k);

// In OnData()
if (_kch.IsReady)
{
    Plot("My Indicators", "middleband", _kch.MiddleBand);
    Plot("My Indicators", "upperband", _kch.UpperBand);
    Plot("My Indicators", "lowerband", _kch.LowerBand);
    Plot("My Indicators", "averagetruerange", _kch.AverageTrueRange);
    Plot("My Indicators", "keltnerchannels", _kch.Current);
}
# In Initialize()
symbol = self.AddEquity("SPY").Symbol
self.kch = self.KCH(symbol, period, k)

# In OnData()
if self.kch.IsReady:
    self.Plot("My Indicators", "middleband", self.kch.MiddleBand)
    self.Plot("My Indicators", "upperband", self.kch.UpperBand)
    self.Plot("My Indicators", "lowerband", self.kch.LowerBand)
    self.Plot("My Indicators", "averagetruerange", self.kch.AverageTrueRange)
    self.Plot("My Indicators", "keltnerchannels", self.kch.Current)

The following image shows the plot values in a matplotlib plot. To load algorithm plot data into the Research Environment, see Charts.

For more information about plotting indicators, see Plotting Indicators.

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: