I have created the simple pivot indicator below. The calculations and everything work fine but there is one issue, which is that the script never seems to enter the
if(BarsInProfgress ==1 )
public class CarterPivot : Indicator
{
double r1, r2, r3;
double s1, s2, s3;
double pivot;
double high, low, close;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "CarterPivot";
Calculate = Calculate.OnBarClose;
IsOverlay = false;
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)
{
AddDataSeries(Data.BarsPeriodType.Day, 1);
}
else if(State == State.DataLoaded)
{
high = BarsArray[1].GetHigh(BarsArray[1].Count - 2);
low = BarsArray[1].GetLow(BarsArray[1].Count - 2);
close = BarsArray[1].GetClose(BarsArray[1].Count - 2);
}
}
protected override void OnBarUpdate()
{
if(CurrentBar<3)
return;
if (BarsInProgress == 0)
{
pivot = (high + low + close) / 3;
r1 = 2 * pivot - low;
s1 = 2 * pivot - high;
r2 = pivot + (high - low);
s2 = pivot - (high - low);
r3 = r1 + (high- low);
s3 = s1 - (high - low);
int barsSince = Bars.BarsSinceNewTradingDay;
Draw.Line(this, CurrentBar+"r1", barsSince, r1, 0, r1, Brushes.Yellow);
Draw.Line(this, CurrentBar+"s1", barsSince, s1, 0, s1, Brushes.Yellow);
Draw.Line(this, CurrentBar+"r2", barsSince, r2, 0, r2, Brushes.Orange);
Draw.Line(this, CurrentBar+"s2", barsSince, s2, 0, s2, Brushes.Orange);
Draw.Line(this, CurrentBar+"pivot", barsSince, pivot, 0, pivot, Brushes.White);
}
if (BarsInProgress == 1)//Day
{
high = BarsArray[1].GetHigh(BarsArray[1].Count - 2);
low = BarsArray[1].GetLow(BarsArray[1].Count - 2);
close = BarsArray[1].GetClose(BarsArray[1].Count - 2);
}
Print(high+" "+low+" " +close);
//Print(BarsArray[1].GetHigh(BarsArray[1].Count - 1) + " "+BarsArray[1].GetHigh(BarsArray[1].Count - 2));
}
}

Comment