the code below is a cumulative tick indicator. I experience 2 issues with it. 1: I can't drag and drop it to another panel, 2: it doesn't load to the chart after I restart Ninjatrader. I can't find any suspicious errors within the code, what can cause these errors?
namespace NinjaTrader.NinjaScript.Indicators.BaluCustom
{
public class CumulativeTick : Indicator
{
private Brush positiveBrush;
private Brush negativeBrush;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "CumulativeTick";
Calculate = Calculate.OnBarClose;
IsOverlay = false;
DisplayInDataBox = true;
DrawOnPricePanel = false;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
AddPlot(new Stroke(Brushes.Transparent, 2), PlotStyle.Bar, "CTick");
PositiveBrush = Brushes.GreenYellow; // Default positive color
NegativeBrush = Brushes.Tomato; // Default negative color
}
else if (State == State.Configure)
{
AddDataSeries("^TICK", Data.BarsPeriodType.Tick, 1, Data.MarketDataType.Last);
}
else if (State == State.DataLoaded)
{
CTick = new Series<double>(this, MaximumBarsLookBack.Infinite);
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 10 ||CurrentBars[1] < 10 )
return;
// Logic
CTick[0] = (Closes[1][0] + (CTick[1])) ;
Values[0][0]=CTick[0];
// Set color based on CTick value
PlotBrushes[0][0] = CTick[0] >= 0 ? positiveBrush : negativeBrush;
// Reset EOD
if (Bars.IsLastBarOfSession == true)
{
CTick[0] = 0;
}
}
region Properties
[Browsable(false)] // Hides the CTick plot from the properties UI
[XmlIgnore] // Prevents the CTick plot from being serialized
public Series<double> CTick { get; private set; }
[NinjaScriptProperty]
[Display(Name = "Positive Color", Order = 1, GroupName = "Plot Colors")]
public Brush PositiveBrush
{
// get; set;
get { return positiveBrush; }
set { positiveBrush = value; }
}
[NinjaScriptProperty]
[Display(Name = "Negative Color", Order = 2, GroupName = "Plot Colors")]
public Brush NegativeBrush
{
// get; set;
get { return negativeBrush; }
set { negativeBrush = value; }
}
#endregion
}
}

Comment