I have use the Ninja Script Editor to write the code but I do not know how to apply the donchian channel upper and lower lines to the code.
Below is the code that I used also a chart of what I have so far.
#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
{
/// <summary>
/// Plots the break out and breakdown of any instrument.
/// </summary>
[Description("Plots the break out and breakdown of any instrument.")]
public class NopayneDonchian : Indicator
{
#region Variables
// Wizard generated variables
private int period = 20; // Default setting for Period
// User defined variables (add any user defined variables below)
#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.Orange), PlotStyle.Dot, "Breakout"));
Add(new Plot(Color.FromKnownColor(KnownColor.DarkViolet), PlotStyle.Dot, "Breakdown"));
Overlay = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
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.
Breakout.Set(High[0]);
Breakdown.Set(Low[0]);
}
#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 Breakout
{
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 Breakdown
{
get { return Values[1]; }
}
[Description("Number of bars used")]
[GridCategory("Parameters")]
public int Period
{
get { return period; }
set { period = 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 NopayneDonchian[] cacheNopayneDonchian = null;
private static NopayneDonchian checkNopayneDonchian = new NopayneDonchian();
/// <summary>
/// Plots the break out and breakdown of any instrument.
/// </summary>
/// <returns></returns>
public NopayneDonchian NopayneDonchian(int period)
{
return NopayneDonchian(Input, period);
}
/// <summary>
/// Plots the break out and breakdown of any instrument.
/// </summary>
/// <returns></returns>
public NopayneDonchian NopayneDonchian(Data.IDataSeries input, int period)
{
if (cacheNopayneDonchian != null)
for (int idx = 0; idx < cacheNopayneDonchian.Length; idx++)
if (cacheNopayneDonchian[idx].Period == period && cacheNopayneDonchian[idx].EqualsInput(input))
return cacheNopayneDonchian[idx];
lock (checkNopayneDonchian)
{
checkNopayneDonchian.Period = period;
period = checkNopayneDonchian.Period;
if (cacheNopayneDonchian != null)
for (int idx = 0; idx < cacheNopayneDonchian.Length; idx++)
if (cacheNopayneDonchian[idx].Period == period && cacheNopayneDonchian[idx].EqualsInput(input))
return cacheNopayneDonchian[idx];
NopayneDonchian indicator = new NopayneDonchian();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
indicator.Input = input;
indicator.Period = period;
Indicators.Add(indicator);
indicator.SetUp();
NopayneDonchian[] tmp = new NopayneDonchian[cacheNopayneDonchian == null ? 1 : cacheNopayneDonchian.Length + 1];
if (cacheNopayneDonchian != null)
cacheNopayneDonchian.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheNopayneDonchian = 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
{
/// <summary>
/// Plots the break out and breakdown of any instrument.
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.NopayneDonchian NopayneDonchian(int period)
{
return _indicator.NopayneDonchian(Input, period);
}
/// <summary>
/// Plots the break out and breakdown of any instrument.
/// </summary>
/// <returns></returns>
public Indicator.NopayneDonchian NopayneDonchian(Data.IDataSeries input, int period)
{
return _indicator.NopayneDonchian(input, period);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// Plots the break out and breakdown of any instrument.
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.NopayneDonchian NopayneDonchian(int period)
{
return _indicator.NopayneDonchian(Input, period);
}
/// <summary>
/// Plots the break out and breakdown of any instrument.
/// </summary>
/// <returns></returns>
public Indicator.NopayneDonchian NopayneDonchian(Data.IDataSeries input, 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.NopayneDonchian(input, period);
}
}
}
#endregion

Comment