public class SampleLastEveryTick : Indicator
{
private Series<double> sjClose;
private double close;
private int activeBar = 0;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = "Test Indicatro";
Name = "SampleLastEveryTick";
BarsRequiredToPlot = 0;
Calculate = Calculate.OnEachTick;
DrawOnPricePanel = false;
IsOverlay = false;
DisplayInDataBox = true;
}
else if(State == State.Configure){
AddDataSeries("MSFT");
sjClose = new Series<double>(this);
}
}
protected override void OnMarketData(MarketDataEventArgs e)
{
if(BarsInProgress == 0)return;
if(e.MarketDataType == MarketDataType.Last)
{
close = e.Price;
}
}
protected override void OnBarUpdate()
{
if(BarsInProgress != 0)return;
if (CurrentBar < activeBar) //CurrentBar is -1
return;
if (CurrentBar > activeBar)
{
Print(sjClose[1]);
activeBar = CurrentBar;
}
sjClose[0] = close;
}
[Browsable(false)]
[XmlIgnore]
public Series<double> SjClose
{
get {return sjClose;}
}
}
public class CallBuySell : Indicator
{
SampleLastEveryTick GUEST = null;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "CallBuySell";
Calculate = Calculate.OnEachTick;
IsOverlay = false;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
IsSuspendedWhileInactive = true;
}
else if(State == State.Configure){
AddDataSeries("MSFT");
}
else if (State == State.DataLoaded)
{
GUEST = SampleLastEveryTick();
}
}
protected override void OnBarUpdate()
{
if (CurrentBar < 0)return;
Print(GUEST.SjClose[0]);
}
}
Error on calling 'OnBarUpdate' method on bar 0: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

Comment