I'm developing a simple indicator that draws a line where prior day's close price is on 1 min chart. See my code below:
namespace NinjaTrader.NinjaScript.Indicators
{
public class AutoDrawLine : Indicator
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "AutoDrawLine";
Calculate = Calculate.OnEachTick;
IsOverlay = false;
DisplayInDataBox = true;
DrawOnPricePanel = 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(Brushes.CornflowerBlue, "Prior Close");
}
else if (State == State.Configure)
{
AddDataSeries(Data.BarsPeriodType.Day, 1);
}
}
protected override void OnBarUpdate()
{
if (CurrentBar < 0)
return;
Draw.HorizontalLine(this, "Prior Close", Closes[1][1], Brushes.Red);
}
}
}
Draw.HorizontalLine(this, "Prior Close", 40, Brushes.Red);
This specific value shows up. So it must be my additional data series not working. Would you please tell me how to make it work?
2. I need it to draw just one line everytime a daily bar is closed. It looks like my code will draw a lot of lines on chart everytime primary series bar is updated. Also, when a daily bar is closed, prior close price gets updated, the old line needs to be deleted. How can I make this work?
Thank you very much for your help!

Comment