#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
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
{
///
/// DiNapoli Oscillator Predictor
///
[Description("DiNapoli Oscillator Predictor\nNOTE: MUST Displacement = 1")]
public class OscillatorPredictor : Indicator
{
#region Variables
// Wizard generated variables
private int period = 7; // Default setting for Period
private double maxOB = 0; // Default setting for MaxOB
private double maxOS = 0; // Default setting for MaxOS
// User defined variables (add any user defined variables below)
#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.Orange), PlotStyle.Line, "OBline"));
Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "OSline"));
Overlay = true;
}
///
/// Called on each bar update event (incoming tick)
///
protected override void OnBarUpdate()
{
if (CurrentBar < period)
{
OBline.Set(Close[0]);
OSline.Set(Close[0]);
}
else
{
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
int i;
double sumHighs = 0;
double sumLows = 0;
for(i = 1; i < period; i++) {
sumHighs += High[i];
sumLows += Low[i];
}
double OBvalue = ((period * maxOB) + sumHighs) / (period - 1);
double OSvalue = ((period * maxOS) + sumLows) / (period - 1);
OBline.Set(OBvalue);
OSline.Set(OSvalue);
}
}
#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 OBline
{
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 OSline
{
get { return Values[1]; }
}
[Description("Oscillator period")]
[GridCategory("Parameters")]
public int Period
{
get { return period; }
set { period = Math.Max(1, value); }
}
[Description("Maximum Overbought value")]
[GridCategory("Parameters")]
public double MaxOB
{
get { return maxOB; }
set { maxOB = value; }
}
[Description("Maximum Oversold value")]
[GridCategory("Parameters")]
public double MaxOS
{
get { return maxOS; }
set { maxOS = 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 OscillatorPredictor[] cacheOscillatorPredictor = null;
private static OscillatorPredictor checkOscillatorPredictor = new OscillatorPredictor();
///
/// DiNapoli Oscillator Predictor\nNOTE: MUST Displacement = 1
///
///
public OscillatorPredictor OscillatorPredictor(double maxOB, double maxOS, int period)
{
return OscillatorPredictor(Input, maxOB, maxOS, period);
}
///
/// DiNapoli Oscillator Predictor\nNOTE: MUST Displacement = 1
///
///
public OscillatorPredictor OscillatorPredictor(Data.IDataSeries input, double maxOB, double maxOS, int period)
{
if (cacheOscillatorPredictor != null)
for (int idx = 0; idx < cacheOscillatorPredictor.Length; idx++)
if (Math.Abs(cacheOscillatorPredictor[idx].MaxOB - maxOB) <= double.Epsilon && Math.Abs(cacheOscillatorPredictor[idx].MaxOS - maxOS) <= double.Epsilon && cacheOscillatorPredictor[idx].Period == period && cacheOscillatorPredictor[idx].EqualsInput(input))
return cacheOscillatorPredictor[idx];
lock (checkOscillatorPredictor)
{
checkOscillatorPredictor.MaxOB = maxOB;
maxOB = checkOscillatorPredictor.MaxOB;
checkOscillatorPredictor.MaxOS = maxOS;
maxOS = checkOscillatorPredictor.MaxOS;
checkOscillatorPredictor.Period = period;
period = checkOscillatorPredictor.Period;
if (cacheOscillatorPredictor != null)
for (int idx = 0; idx < cacheOscillatorPredictor.Length; idx++)
if (Math.Abs(cacheOscillatorPredictor[idx].MaxOB - maxOB) <= double.Epsilon && Math.Abs(cacheOscillatorPredictor[idx].MaxOS - maxOS) <= double.Epsilon && cacheOscillatorPredictor[idx].Period == period && cacheOscillatorPredictor[idx].EqualsInput(input))
return cacheOscillatorPredictor[idx];
OscillatorPredictor indicator = new OscillatorPredictor();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
indicator.Input = input;
indicator.MaxOB = maxOB;
indicator.MaxOS = maxOS;
indicator.Period = period;
Indicators.Add(indicator);
indicator.SetUp();
OscillatorPredictor[] tmp = new OscillatorPredictor[cacheOscillatorPredictor == null ? 1 : cacheOscillatorPredictor.Length + 1];
if (cacheOscillatorPredictor != null)
cacheOscillatorPredictor.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheOscillatorPredictor = tmp;
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
{
///
/// DiNapoli Oscillator Predictor\nNOTE: MUST Displacement = 1
///
///
[Gui.Design.WizardCondition("Indicator")]
public Indicator.OscillatorPredictor OscillatorPredictor(double maxOB, double maxOS, int period)
{
return _indicator.OscillatorPredictor(Input, maxOB, maxOS, period);
}
///
/// DiNapoli Oscillator Predictor\nNOTE: MUST Displacement = 1
///
///
public Indicator.OscillatorPredictor OscillatorPredictor(Data.IDataSeries input, double maxOB, double maxOS, int period)
{
return _indicator.OscillatorPredictor(input, maxOB, maxOS, period);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
///
/// DiNapoli Oscillator Predictor\nNOTE: MUST Displacement = 1
///
///
[Gui.Design.WizardCondition("Indicator")]
public Indicator.OscillatorPredictor OscillatorPredictor(double maxOB, double maxOS, int period)
{
return _indicator.OscillatorPredictor(Input, maxOB, maxOS, period);
}
///
/// DiNapoli Oscillator Predictor\nNOTE: MUST Displacement = 1
///
///
public Indicator.OscillatorPredictor OscillatorPredictor(Data.IDataSeries input, double maxOB, double maxOS, 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.OscillatorPredictor(input, maxOB, maxOS, period);
}
}
}
#endregion