The Keltner indicator attempts to locate the most important trends. The indicator is based on principles similar to those used in Envelope and Bollinger. The upper band is calculated as the moving average plus the average true range, for N periods. The lower band is the moving average minus the average true range.
As a rule, the upper band detects that the market is overbought and that correction will most probably be directed downward. The lower band means that the market is oversold and that correction will most probably be directed upward.
To initialize Keltner use one of the constructors:
Keltner – sets default values: period = 14, factor = 1.0
Keltner(Int32, Double) – sets values for period and factor
Keltner(TimeSpan, Double) – sets time period and factor
Keltner(IAverager, IAverager, Double) – sets types for averaging middle and ATR (see formula) and factor
properties to get current value.
1// Create new instance 2Keltner keltner = new Keltner(28, 2); 3 4// Number of stored values 5keltner.HistoryCapacity = 2; 6 7// Add new data point 8keltner.Add(Bars.Current.Open, Bars.Current.High, Bars.Current.Low, Bars.Current.Close, Bars.Current.Volume, CurrentTime); 9 10// Get indicator value 11double IndMiddle = keltner.MiddleChannel; 12double IndUpper = keltner.UpperChannel; 13double IndLower = keltner.LowerChannel; 14 15// Get previous values 16double IndPrevMiddle = keltner.MiddleChannel; 17double IndPrevUpper = keltner.UpperChannel; 18double IndPrevLower = keltner.LowerChannel;
Keltner channel with custom average:
1// Create new instance, 2// We will use EMA instead SMA for calculating Middle 3// and SMA instead of EMA in ATR 4Keltner keltner = new Keltner(new Ema(28), new Sma(28)); 5 6// Add new data point 7keltner.Add(Bars.Current.Open, Bars.Current.High, Bars.Current.Low, Bars.Current.Close, Bars.Current.Volume, CurrentTime); 8 9// Get indicator value 10double IndMiddle = keltner.MiddleChannel; 11double IndUpper = keltner.UpperChannel; 12double IndLower = keltner.LowerChannel;