My Code is pretty simple:
namespace NinjaTrader.NinjaScript.Indicators
{
public class AaIndicatorTester : Indicator
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Indicator tester";
Name = "AaIndicatorTester";
Calculate = Calculate.OnPriceChange;
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(new Stroke(Brushes.White, 20), PlotStyle.Bar, "DeltaPlot");
}
else if (State == State.Configure)
{
AddDataSeries(Data.BarsPeriodType.Tick, 1);
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress == 0)
{
if (IsFirstTickOfBar && CurrentBar > 2)
{
OrderFlowCumulativeDelta cumulativeDelta = OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Bar, 0);
double currentDeltaForBar = cumulativeDelta.DeltaClose[1];
Print("");
Print(Time[0]);
Print(currentDeltaForBar);
if (currentDeltaForBar > 0)
{
PlotBrushes[0][0] = Brushes.Green;
}
else
{
PlotBrushes[0][0] = Brushes.Red;
}
DeltaPlot[0] = currentDeltaForBar;
}
}
//else current bars index is 1 then do work on the cumulative delta
else if (BarsInProgress == 1)
{
// We have to update the secondary series of the hosted indicator to make sure the values we get in BarsInProgress == 0 are in sync
OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Bar, 0).Update(OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Bar, 0).BarsArray[1].Count - 1, 1);
}
}
#region Properties
[Browsable(false)]
[XmlIgnore]
public Series<double> DeltaPlot
{
get { return Values[0]; }
}
#endregion
}
}
As you can see an example of this in screenshot at the close of 16:43:43 bar the cumulative delta read -92, but my log was -83.
If I try to run my indicator OnEachTick, the same thing happens.
Thanks
,
tarik

Comment