Here's my code:
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "CummulativeDelta";
Calculate = Calculate.OnEachTick;
BarsRequiredToPlot = 1;
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;
AddPlot(Brushes.Blue, "CumulativeDelta");
}
else if (State == State.Configure)
{
}
}
protected override void OnBarUpdate()
{
if (Bars == null || CurrentBar == 0)
return;
if (Bars.IsLastBarOfSession)
{
cumulativeDelta = 0.0;
previousDelta = 0.0;
}
//double currentDelta = (Volume[0] - Volume[1]) * (Close[0] > Open[0] ? 1 : -1);
double currentDelta = BuySellVolume().Buys[0] - BuySellVolume().Sells[0];
Print(BuySellVolume().Buys[0]);
double deltaDifference = currentDelta - previousDelta;
cumulativeDelta += deltaDifference;
previousDelta = currentDelta;
Value[0] = cumulativeDelta;
}
Thanks

Comment