I've searched the documentation here:
and previous question here:
but it's not explicit enough.
I've found the
closeline
Closeline Ninjatrader 7 Code
#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>
/// Enter the description of your new custom indicator here
/// </summary>
[Description("Enter the description of your new custom indicator here")]
public class CloseLine : Indicator
{
#region Variables
private bool colorDot = false;
private Color upColor = Color.Lime;
private Color dnColor = Color.Red;
private Color ftColor = Color.Yellow;
#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.Yellow), PlotStyle.Dot, "DOT"));
Add(new Plot(Color.FromKnownColor(KnownColor.Yellow), PlotStyle.Line, "LINE"));
Plots[0].Pen.Width = 2;
Plots[1].Pen.Width = 2;
CalculateOnBarClose = false;
PriceTypeSupported = true;
//PriceType = PriceType.Weighted;
PaintPriceMarkers = false;
DisplayInDataBox = false;
Overlay = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if(colorDot==true)
{
if (Close[0]>Open[0] )
{
PlotColors[0][0] = upColor;
Values[0].Set(Input[0]);
}
else if (Close[0]<Open[0] )
{
PlotColors[0][0] = dnColor;
Values[0].Set(Input[0]);
}
else if (Close[0]==Open[0] )
{
PlotColors[0][0] = ftColor;
Values[0].Set(Input[0]);
}
else
Values[0].Reset();
}
else
Values[0].Set(Input[0]);
Values[1].Set(Input[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 DOT
{
get { return Values[0]; }
}
[XmlIgnore()]
[Description("Up Color")]
[Category("Color")]
[Gui.Design.DisplayNameAttribute("01. Up Color")]
public Color UpColor
{
get { return upColor; }
set { upColor = value; }
}
[Browsable(false)]
public string UpColorSerialize
{
get { return NinjaTrader.Gui.Design.SerializableColor.ToString( upColor); }
set { upColor = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
}
[XmlIgnore()]
[Description("Down Color")]
[Category("Color")]
[Gui.Design.DisplayNameAttribute("02. Down Color")]
public Color DnColor
{
get { return dnColor; }
set { dnColor = value; }
}
[Browsable(false)]
public string DnColorSerialize
{
get { return NinjaTrader.Gui.Design.SerializableColor.ToString( dnColor); }
set { dnColor = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
}
[XmlIgnore()]
[Description("Flat Color")]
[Category("Color")]
[Gui.Design.DisplayNameAttribute("02. Flat Color")]
public Color FTColor
{
get { return ftColor; }
set { ftColor = value; }
}
[Browsable(false)]
public string FtColorSerialize
{
get { return NinjaTrader.Gui.Design.SerializableColor.ToString( ftColor); }
set { ftColor = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
}
[Description("Color Dot?")]
[Category("Color")]
[Gui.Design.DisplayNameAttribute("00. Color Dot?")]
public bool ColorDot
{
get { return colorDot; }
set { colorDot = 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 CloseLine[] cacheCloseLine = null;
private static CloseLine checkCloseLine = new CloseLine();
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public CloseLine CloseLine()
{
return CloseLine(Input);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public CloseLine CloseLine(Data.IDataSeries input)
{
if (cacheCloseLine != null)
for (int idx = 0; idx < cacheCloseLine.Length; idx++)
if (cacheCloseLine[idx].EqualsInput(input))
return cacheCloseLine[idx];
lock (checkCloseLine)
{
if (cacheCloseLine != null)
for (int idx = 0; idx < cacheCloseLine.Length; idx++)
if (cacheCloseLine[idx].EqualsInput(input))
return cacheCloseLine[idx];
CloseLine indicator = new CloseLine();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
indicator.Input = input;
Indicators.Add(indicator);
indicator.SetUp();
CloseLine[] tmp = new CloseLine[cacheCloseLine == null ? 1 : cacheCloseLine.Length + 1];
if (cacheCloseLine != null)
cacheCloseLine.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheCloseLine = 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>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.CloseLine CloseLine()
{
return _indicator.CloseLine(Input);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public Indicator.CloseLine CloseLine(Data.IDataSeries input)
{
return _indicator.CloseLine(input);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.CloseLine CloseLine()
{
return _indicator.CloseLine(Input);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public Indicator.CloseLine CloseLine(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.CloseLine(input);
}
}
}
#endregion
I've tried to work from the SMA indicator (below) but not successful either.
SMA Ninjatrader 8 Code
//
// This namespace holds indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
/// <summary>
/// The SMA (Simple Moving Average) is an indicator that shows the average value of a security's price over a period of time.
/// </summary>
public class SMA : Indicator
{
private double priorSum;
private double sum;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDe scriptionSMA;
Name = NinjaTrader.Custom.Resource.NinjaScriptIndicatorNa meSMA;
IsOverlay = true;
IsSuspendedWhileInactive = true;
Period = 14;
AddPlot(Brushes.Goldenrod, NinjaTrader.Custom.Resource.NinjaScriptIndicatorNa meSMA);
}
else if (State == State.Configure)
{
priorSum = 0;
sum = 0;
}
}
protected override void OnBarUpdate()
{
if (BarsArray[0].BarsType.IsRemoveLastBarSupported)
{
if (CurrentBar == 0)
Value[0] = Input[0];
else
{
double last = Value[1] * Math.Min(CurrentBar, Period);
if (CurrentBar >= Period)
Value[0] = (last + Input[0] - Input[Period]) / Math.Min(CurrentBar, Period);
else
Value[0] = ((last + Input[0]) / (Math.Min(CurrentBar, Period) + 1));
}
}
else
{
if (IsFirstTickOfBar)
priorSum = sum;
sum = priorSum + Input[0] - (CurrentBar >= Period ? Input[Period] : 0);
Value[0] = sum / (CurrentBar < Period ? CurrentBar + 1 : Period);
}
}
#endregion

Comment