i am just starting to learn ninjascript and I would like to create a simple indicator that repaints before the candle closes, if the conditions are not met.
I place a dot with Draw.Dot() function, and if the conditions are no longer met, I want to remove that dot with RemoveDrawObject() function.
The problem is that this way my indicator doesn't even load and NT8 freezes.
Can somebody help me figure out what I am doing wrong?
Thank you

//This namespace holds Indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
public class TestIndicator : Indicator
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "TestIndicator";
Calculate = Calculate.OnEachTick;
IsOverlay = true;
DisplayInDataBox = true;
DrawOnPricePanel = true;
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;
}
else if (State == State.Configure)
{
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 4)
return;
if ( (Close[1] > Open[1])
)
{
Draw.Dot(this,"HV DtUp_1"+CurrentBar, false, 1, (Low[1] + (-2 * TickSize)) , Brushes.Blue);
}
else
{
RemoveDrawObject("HV DtUp_1"+CurrentBar);
}
if ((Close[1] < Open[1])
)
{
Draw.Dot(this,"HV DtDn_1"+CurrentBar, false, 1, (High[1] + (2 * TickSize)) , Brushes.Red);
}
else
{
RemoveDrawObject("HV DtDn_1"+CurrentBar);
}
}
}
}

Comment