I am trying to use a secondary volumetric bars series in a custom ninjatrader indicator and for the first step I am trying to mirror the built in cvd indicator. In the code below BarsInProgress == 1 is never hit and my print statement doesnt show. This results in Values[0][0] always being 0. What am I doing wrong? Any help is appreciated!
namespace NinjaTrader.NinjaScript.Indicators.RenkoVolumeIndicators
{
public class customCVD : Indicator
{
private double accumulator;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "customCVD";
Calculate = Calculate.OnEachTick;
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;
AddPlot(Brushes.Blue, "Delta");
}
else if (State == State.Configure)
{
AddVolumetric(Bars.Instrument.MasterInstrument.Name, BarsPeriodType.Tick, 1, VolumetricDeltaType.BidAsk, 1);
}
else if (State == State.DataLoaded)
{
accumulator = 0;
}
}
protected override void OnBarUpdate()
{
if (CurrentBar < 1) return;
NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType barsType = BarsArray[1].BarsType as
NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType;
if (barsType == null)
return;
//Print(barsType.Volumes[0].BarDelta);
//On volumetric bars update
if (BarsInProgress == 1)
{
// Calculate delta for this tick
double tickDelta = barsType.Volumes[CurrentBar].BarDelta; // askVol - bidVol;
Print("Cumulative delta (bar): " + barsType.Volumes[CurrentBar].BarDelta);
// Accumulate
accumulator += tickDelta;
}
else if (BarsInProgress == 0)
{
// Set the value for this Renko bar
Values[0][0] = accumulator;
// Reset accumulator for the next Renko bar
accumulator = 0;
}
}
}
}