#region Using declarations
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
using System.Xml.Serialization;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// Keltner Channel. The Keltner Channel is a similar indicator to Bollinger Bands. Here the midline is a standard moving average with the upper and lower bands offset by the SMA of the difference between the high and low of the previous bars. The offset multiplier as well as the SMA period is configurable.
/// </summary>
[Description("The Keltner Channel is a similar indicator to Bollinger Bands. Here the midline is a standard moving average with the upper and lower bands offset by the SMA of the difference between the high and low of the previous bars. The offset multiplier as well as the SMA period is configurable.")]
public class BLineKeltnerChannel : Indicator
{
#region Variables
}
#region Properties
/// <summary>
/// </summary>
[Description("Numbers of bars used for calculations")]
[Category("Parameters")]
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public int Period
{
get { return period; }
set { period = Math.Max(1, value); }
}
/// <summary>
/// </summary>
[Description("Transperancy of Bands 1 - 10")]
[Category("Parameters")]
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public int OpacityBands
{
get { return opacityBands; }
set { opacityBands = Math.Min(10, value); }
}
/// <summary>
/// </summary>
[Description("Transperancy of Band Touches 1 - 10")]
[Category("Parameters")]
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public int OpacityTouch
{
get { return opacityTouch; }
set { opacityTouch = Math.Min(10, value); }
}
/// <summary>
/// </summary>
[Description("How much to expand the upper and lower band from the normal offset")]
[Category("Parameters")]
[Gui.Design.DisplayNameAttribute("Offset multiplier")]
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public double OffsetMultiplier
{
get { return offsetMultiplier; }
set { offsetMultiplier = Math.Max(0.01, value); }
}
[Description("How much to expand the second upper and lower band from the normal offset")]
[Category("Parameters")]
[Gui.Design.DisplayNameAttribute("Offset multiplier Two")]
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public double OffsetMultiplier2
{
get { return offsetMultiplier2; }
set { offsetMultiplier2 = Math.Max(0.01, value); }
}
[Description("Color of Keltner Bands")]
[Category("Parameters")]
[Gui.Design.DisplayNameAttribute("Band Color")]
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public Color ColorBands
{
get { return colorBands; }
set { colorBands = value; }
}
[Description("Color of Upper Touch of Bands")]
[Category("Parameters")]
[Gui.Design.DisplayNameAttribute("Band Touch Upper Color")]
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public Color ColorTouchUpper
{
get { return colorTouchUpper; }
set { colorTouchUpper = value; }
}
[Description("Color of Lower Touch of Bands")]
[Category("Parameters")]
[Gui.Design.DisplayNameAttribute("Band Touch Lower Color")]
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public Color ColorTouchLower
{
get { return colorTouchLower; }
set { colorTouchLower = value; }
}
/// <summary>
/// </summary>
[Browsable(false)]
[XmlIgnore()]
public DataSeries Upper
{
get { return Values[0]; }
}
/// <summary>
/// </summary>
[Browsable(false)]
[XmlIgnore()]
public DataSeries Lower
{
get { return Values[1]; }
}
[Browsable(false)]
[XmlIgnore()]
public DataSeries UpperSecond
{
get { return Values[2]; }
}
/// <summary>
/// </summary>
[Browsable(false)]
[XmlIgnore()]
public DataSeries LowerSecond
{
get { return Values[3]; }
}
#endregion
}
}
#region NinjaScript generated code. Neither change nor remove.
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
public partial class Indicator : IndicatorBase
{
private BLineKeltnerChannel[] cacheBLineKeltnerChannel = null;
private static BLineKeltnerChannel checkBLineKeltnerChannel = new BLineKeltnerChannel();
/// <summary>
/// The Keltner Channel is a similar indicator to Bollinger Bands. Here the midline is a standard moving average with the upper and lower bands offset by the SMA of the difference between the high and low of the previous bars. The offset multiplier as well as the SMA period is configurable.
/// </summary>
/// <returns></returns>
public BLineKeltnerChannel BLineKeltnerChannel(Color colorBands, Color colorTouchLower, Color colorTouchUpper, double offsetMultiplier, double offsetMultiplier2, int opacityBands, int opacityTouch, int period)
{
return BLineKeltnerChannel(Input, colorBands, colorTouchLower, colorTouchUpper, offsetMultiplier, offsetMultiplier2, opacityBands, opacityTouch, period);
}
/// <summary>
/// The Keltner Channel is a similar indicator to Bollinger Bands. Here the midline is a standard moving average with the upper and lower bands offset by the SMA of the difference between the high and low of the previous bars. The offset multiplier as well as the SMA period is configurable.
/// </summary>
/// <returns></returns>
public BLineKeltnerChannel BLineKeltnerChannel(Data.IDataSeries input, Color colorBands, Color colorTouchLower, Color colorTouchUpper, double offsetMultiplier, double offsetMultiplier2, int opacityBands, int opacityTouch, int period)
{
checkBLineKeltnerChannel.ColorBands = colorBands;
colorBands = checkBLineKeltnerChannel.ColorBands;
checkBLineKeltnerChannel.ColorTouchLower = colorTouchLower;
colorTouchLower = checkBLineKeltnerChannel.ColorTouchLower;
checkBLineKeltnerChannel.ColorTouchUpper = colorTouchUpper;
colorTouchUpper = checkBLineKeltnerChannel.ColorTouchUpper;
checkBLineKeltnerChannel.OffsetMultiplier = offsetMultiplier;
offsetMultiplier = checkBLineKeltnerChannel.OffsetMultiplier;
checkBLineKeltnerChannel.OffsetMultiplier2 = offsetMultiplier2;
offsetMultiplier2 = checkBLineKeltnerChannel.OffsetMultiplier2;
checkBLineKeltnerChannel.OpacityBands = opacityBands;
opacityBands = checkBLineKeltnerChannel.OpacityBands;
checkBLineKeltnerChannel.OpacityTouch = opacityTouch;
opacityTouch = checkBLineKeltnerChannel.OpacityTouch;
checkBLineKeltnerChannel.Period = period;
period = checkBLineKeltnerChannel.Period;
if (cacheBLineKeltnerChannel != null)
for (int idx = 0; idx < cacheBLineKeltnerChannel.Length; idx++)
if (cacheBLineKeltnerChannel[idx].ColorBands == colorBands && cacheBLineKeltnerChannel[idx].ColorTouchLower == colorTouchLower && cacheBLineKeltnerChannel[idx].ColorTouchUpper == colorTouchUpper && Math.Abs(cacheBLineKeltnerChannel[idx].OffsetMultiplier - offsetMultiplier) <= double.Epsilon && Math.Abs(cacheBLineKeltnerChannel[idx].OffsetMultiplier2 - offsetMultiplier2) <= double.Epsilon && cacheBLineKeltnerChannel[idx].OpacityBands == opacityBands && cacheBLineKeltnerChannel[idx].OpacityTouch == opacityTouch && cacheBLineKeltnerChannel[idx].Period == period && cacheBLineKeltnerChannel[idx].EqualsInput(input))
return cacheBLineKeltnerChannel[idx];
BLineKeltnerChannel indicator = new BLineKeltnerChannel();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
indicator.Input = input;
indicator.ColorBands = colorBands;
indicator.ColorTouchLower = colorTouchLower;
indicator.ColorTouchUpper = colorTouchUpper;
indicator.OffsetMultiplier = offsetMultiplier;
indicator.OffsetMultiplier2 = offsetMultiplier2;
indicator.OpacityBands = opacityBands;
indicator.OpacityTouch = opacityTouch;
indicator.Period = period;
indicator.SetUp();
BLineKeltnerChannel[] tmp = new BLineKeltnerChannel[cacheBLineKeltnerChannel == null ? 1 : cacheBLineKeltnerChannel.Length + 1];
if (cacheBLineKeltnerChannel != null)
cacheBLineKeltnerChannel.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheBLineKeltnerChannel = tmp;
Indicators.Add(indicator);
return indicator;
}
}
}
// This namespace holds all market analyzer column definitions and is required. Do not change it.
namespace NinjaTrader.MarketAnalyzer
{
public partial class Column : ColumnBase
{
/// <summary>
/// The Keltner Channel is a similar indicator to Bollinger Bands. Here the midline is a standard moving average with the upper and lower bands offset by the SMA of the difference between the high and low of the previous bars. The offset multiplier as well as the SMA period is configurable.
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.BLineKeltnerChannel BLineKeltnerChannel(Color colorBands, Color colorTouchLower, Color colorTouchUpper, double offsetMultiplier, double offsetMultiplier2, int opacityBands, int opacityTouch, int period)
{
return _indicator.BLineKeltnerChannel(Input, colorBands, colorTouchLower, colorTouchUpper, offsetMultiplier, offsetMultiplier2, opacityBands, opacityTouch, period);
}
/// <summary>
/// The Keltner Channel is a similar indicator to Bollinger Bands. Here the midline is a standard moving average with the upper and lower bands offset by the SMA of the difference between the high and low of the previous bars. The offset multiplier as well as the SMA period is configurable.
/// </summary>
/// <returns></returns>
public Indicator.BLineKeltnerChannel BLineKeltnerChannel(Data.IDataSeries input, Color colorBands, Color colorTouchLower, Color colorTouchUpper, double offsetMultiplier, double offsetMultiplier2, int opacityBands, int opacityTouch, int period)
{
return _indicator.BLineKeltnerChannel(input, colorBands, colorTouchLower, colorTouchUpper, offsetMultiplier, offsetMultiplier2, opacityBands, opacityTouch, period);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// The Keltner Channel is a similar indicator to Bollinger Bands. Here the midline is a standard moving average with the upper and lower bands offset by the SMA of the difference between the high and low of the previous bars. The offset multiplier as well as the SMA period is configurable.
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.BLineKeltnerChannel BLineKeltnerChannel(Color colorBands, Color colorTouchLower, Color colorTouchUpper, double offsetMultiplier, double offsetMultiplier2, int opacityBands, int opacityTouch, int period)
{
return _indicator.BLineKeltnerChannel(Input, colorBands, colorTouchLower, colorTouchUpper, offsetMultiplier, offsetMultiplier2, opacityBands, opacityTouch, period);
}
/// <summary>
/// The Keltner Channel is a similar indicator to Bollinger Bands. Here the midline is a standard moving average with the upper and lower bands offset by the SMA of the difference between the high and low of the previous bars. The offset multiplier as well as the SMA period is configurable.
/// </summary>
/// <returns></returns>
public Indicator.BLineKeltnerChannel BLineKeltnerChannel(Data.IDataSeries input, Color colorBands, Color colorTouchLower, Color colorTouchUpper, double offsetMultiplier, double offsetMultiplier2, int opacityBands, int opacityTouch, int period)
{
if (InInitialize && input == null)
throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");
return _indicator.BLineKeltnerChannel(input, colorBands, colorTouchLower, colorTouchUpper, offsetMultiplier, offsetMultiplier2, opacityBands, opacityTouch, period);
}
}
}
#endregion
Thanks Cory!
These are way better than what's-his-faces bands.
Thanks.
thanks
thanks
Very useful in Trading range market. Thank you
Thank you. Very helpful for me.
Thanks for this, cory. I actually now enjoy watching the BBs.