// Usage of this indicator is described at:
// http://www.paritech.com/education/te...th/klinger.asp
//================================================== ================================================== =
// OpenSource code distributed under the CDDL v1.0 (http://www.opensource.org/licenses/cddl1.php)
//================================================== ================================================== =
//
// Enjoy this OpenSource NinjaScript v6.0 indicator! May it help bring you great amounts of profit!
// If you have profited from this code, then please consider a suitable donation of any amount to its
// Initial Developer and/or other Contributors. Contact information given below.
// Also, feel free to email enhancement suggestions to:
// Initial Developer: SBG Trading Corp., Ben Letto, www.affordableindicators.com March 7, 2008
//
//================================================== ================================================== =
#region Using declarations
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// KVO
/// </summary>
[Description(@"http://www.paritech.com/education/technical/indicators/strength/klinger.asp")]
[Gui.Design.DisplayName("KlingerOscillator")]
public class KlingerOscillator : Indicator
{
#region Variables
// Wizard generated variables
private int fastPeriod = 34; // Default setting for FastPeriod
private int slowPeriod = 55; // Default setting for SlowPeriod
// User defined variables (add any user defined variables below)
int Trend=0, PrevTrend;
double cm=0.0,PrevCM,dm=0.0,PrevDM;
DataSeries vf;
#endregion
/// <summary>
/// This method is used to configure the indicator and is called once before any bar data is loaded.
/// </summary>
protected override void Initialize()
{
Add(new Plot(Color.FromKnownColor(KnownColor.OrangeRed), PlotStyle.Line, "KO"));
Add(new Plot(Color.FromKnownColor(KnownColor.BurlyWood), PlotStyle.Line, "Signal"));
Add(new Line(Color.FromKnownColor(KnownColor.DarkRed), 0, "Zero"));
CalculateOnBarClose = true;
Overlay = false;
PriceTypeSupported = false;
vf = new DataSeries(this);
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{ if(CurrentBar<3) return;
if(High[0]+Low[0]+Close[0] > High[1]+Low[1]+Close[1]) Trend = 1; else Trend=-1;
dm = High[0]-Low[0];
if(Trend == PrevTrend) cm = PrevCM+dm; else cm = PrevDM+dm;
if(cm != 0) vf.Set(Volume[0]*2*Math.Abs((dm/cm)-1.0)*Trend*100);
KO.Set(EMA(vf,fastPeriod)[0] - EMA(vf,SlowPeriod)[0]);
Signal.Set(EMA(KO,13)[0]);
PrevTrend = Trend;
PrevCM = cm;
PrevDM = dm;
}
#region Properties
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries KO
{
get { return Values[0]; }
}
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries Signal
{
get { return Values[1]; }
}
[Description("fast ema period for volume force")]
[Category("Parameters")]
public int FastPeriod
{
get { return fastPeriod; }
set { fastPeriod = Math.Max(1, value); }
}
[Description("slow ema period for volume force")]
[Category("Parameters")]
public int SlowPeriod
{
get { return slowPeriod; }
set { slowPeriod = Math.Max(1, value); }
}
#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 KlingerOscillator[] cacheKlingerOscillator = null;
private static KlingerOscillator checkKlingerOscillator = new KlingerOscillator();
/// <summary>
/// http://www.paritech.com/education/te...th/klinger.asp
/// </summary>
/// <returns></returns>
public KlingerOscillator KlingerOscillator(int fastPeriod, int slowPeriod)
{
return KlingerOscillator(Input, fastPeriod, slowPeriod);
}
/// <summary>
/// http://www.paritech.com/education/te...th/klinger.asp
/// </summary>
/// <returns></returns>
public KlingerOscillator KlingerOscillator(Data.IDataSeries input, int fastPeriod, int slowPeriod)
{
checkKlingerOscillator.FastPeriod = fastPeriod;
fastPeriod = checkKlingerOscillator.FastPeriod;
checkKlingerOscillator.SlowPeriod = slowPeriod;
slowPeriod = checkKlingerOscillator.SlowPeriod;
if (cacheKlingerOscillator != null)
for (int idx = 0; idx < cacheKlingerOscillator.Length; idx++)
if (cacheKlingerOscillator[idx].FastPeriod == fastPeriod && cacheKlingerOscillator[idx].SlowPeriod == slowPeriod && cacheKlingerOscillator[idx].EqualsInput(input))
return cacheKlingerOscillator[idx];
KlingerOscillator indicator = new KlingerOscillator();
indicator.SetUp();
indicator.CalculateOnBarClose = CalculateOnBarClose;
indicator.Input = input;
indicator.FastPeriod = fastPeriod;
indicator.SlowPeriod = slowPeriod;
KlingerOscillator[] tmp = new KlingerOscillator[cacheKlingerOscillator == null ? 1 : cacheKlingerOscillator.Length + 1];
if (cacheKlingerOscillator != null)
cacheKlingerOscillator.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheKlingerOscillator = 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>
/// http://www.paritech.com/education/te...th/klinger.asp
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.KlingerOscillator KlingerOscillator(int fastPeriod, int slowPeriod)
{
return _indicator.KlingerOscillator(Input, fastPeriod, slowPeriod);
}
/// <summary>
/// http://www.paritech.com/education/te...th/klinger.asp
/// </summary>
/// <returns></returns>
public Indicator.KlingerOscillator KlingerOscillator(Data.IDataSeries input, int fastPeriod, int slowPeriod)
{
return _indicator.KlingerOscillator(input, fastPeriod, slowPeriod);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// http://www.paritech.com/education/te...th/klinger.asp
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.KlingerOscillator KlingerOscillator(int fastPeriod, int slowPeriod)
{
return _indicator.KlingerOscillator(Input, fastPeriod, slowPeriod);
}
/// <summary>
/// http://www.paritech.com/education/te...th/klinger.asp
/// </summary>
/// <returns></returns>
public Indicator.KlingerOscillator KlingerOscillator(Data.IDataSeries input, int fastPeriod, int slowPeriod)
{
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.KlingerOscillator(input, fastPeriod, slowPeriod);
}
}
}
#endregion
Comment