#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
{
///
/// zEMA3
///
[Description("zEMA3")]
public class zEMA3 : Indicator
{
#region Variables
// Wizard generated variables
// User defined variables (add any user defined variables below)
double dAvg0 = 0;
double dAvgMir = 0;
double dAvgMir2P = 0;
double dAvgMir2M = 0;
double dDif = 0;
double dDif90m540 = 0;
double dAvg22 = 0;
double dAvg540 = 0;
double dAvgMir540 = 0;
double[] aryEMA = new double [50];
#endregion
///
/// This method is used to configure the indicator and is called once before any bar data is loaded.
///
protected override void Initialize()
{
Add(new Plot(Color.FromKnownColor(KnownColor.Blue), PlotStyle.Line, "Plot0"));
Add(new Plot(Color.FromKnownColor(KnownColor.Maroon), PlotStyle.Line, "Plot1"));
Add(new Plot(Color.FromKnownColor(KnownColor.Yellow), PlotStyle.Line, "Plot2"));
Add(new Plot(Color.FromKnownColor(KnownColor.Black), PlotStyle.Line, "Plot3"));
Add(new Plot(Color.FromKnownColor(KnownColor.Gray), PlotStyle.Line, "Plot4"));
Add(new Plot(Color.FromKnownColor(KnownColor.Gray), PlotStyle.Line, "Plot5"));
Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "Plot6"));
CalculateOnBarClose = true;
Overlay = true;
PriceTypeSupported = false;
PaintPriceMarkers = false;
}
///
/// Called on each bar update event (incoming tick)
///
protected override void OnBarUpdate()
{
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
for (int i = 48 ; i >= 0 ; i--) {
aryEMA[i+1] = aryEMA[i];
}
dAvg0 = EMA(90)[0];
aryEMA[0] = dAvg0;
Plot0.Set(dAvg0);
dAvg22 = aryEMA[22];
if ( dAvg22 != 0 ) {
dDif = dAvg0 - dAvg22;
dAvgMir = dAvg0 + dDif;
dAvgMir2P = dAvg0 + (2.0 * dDif);
dAvgMir2M = dAvg0 - (2.0 * dDif);
Plot1.Set(dAvg22);
Plot2.Set(dAvgMir);
dAvg540 = EMA(540)[0];
Plot3.Set(dAvg540);
Plot4.Set(dAvgMir2P);
Plot5.Set(dAvgMir2M);
dDif90m540 = dAvg0 - dAvg540;
dAvgMir540 = dAvg0 + dDif90m540;
Plot6.Set(dAvgMir540);
}
}
#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 Plot0
{
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 Plot1
{
get { return Values[1]; }
}
[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 Plot2
{
get { return Values[2]; }
}
[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 Plot3
{
get { return Values[3]; }
}
[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 Plot4
{
get { return Values[4]; }
}
[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 Plot5
{
get { return Values[5]; }
}
[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 Plot6
{
get { return Values[6]; }
}
#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 zEMA3[] cachezEMA3 = null;
private static zEMA3 checkzEMA3 = new zEMA3();
///
/// zEMA3
///
///
public zEMA3 zEMA3()
{
return zEMA3(Input);
}
///
/// zEMA3
///
///
public zEMA3 zEMA3(Data.IDataSeries input)
{
if (cachezEMA3 != null)
for (int idx = 0; idx < cachezEMA3.Length; idx++)
if (cachezEMA3[idx].EqualsInput(input))
return cachezEMA3[idx];
zEMA3 indicator = new zEMA3();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
indicator.Input = input;
indicator.SetUp();
zEMA3[] tmp = new zEMA3[cachezEMA3 == null ? 1 : cachezEMA3.Length + 1];
if (cachezEMA3 != null)
cachezEMA3.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cachezEMA3 = 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
{
///
/// zEMA3
///
///
[Gui.Design.WizardCondition("Indicator")]
public Indicator.zEMA3 zEMA3()
{
return _indicator.zEMA3(Input);
}
///
/// zEMA3
///
///
public Indicator.zEMA3 zEMA3(Data.IDataSeries input)
{
return _indicator.zEMA3(input);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
///
/// zEMA3
///
///
[Gui.Design.WizardCondition("Indicator")]
public Indicator.zEMA3 zEMA3()
{
return _indicator.zEMA3(Input);
}
///
/// zEMA3
///
///
public Indicator.zEMA3 zEMA3(Data.IDataSeries input)
{
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.zEMA3(input);
}
}
}
#endregion