//This namespace holds Indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
public class CumDelta : Indicator
{
private OrderFlowCumulativeDelta cumulativeDelta;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "CumDelta";
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)
{
AddDataSeries(BarsPeriodType.Tick, 1);
}
// else if (State == State.DataLoaded)
// {
// cumulativeDelta = OrderFlowCumulativeDelta(CumulativeDeltaType.BidAs k, CumulativeDeltaPeriod.Session, 0);
// }
}
protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
{
}
protected override void OnBarUpdate()
{
if (CurrentBars[0] < 5 || CurrentBars[1] < 5)
return;
if (BarsInProgress == 0)
return;
if (IsFirstTickOfBar)
{
double DeltaClose = OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).DeltaClose[0];
double DeltaOpen = OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).DeltaOpen[0];
double DeltaVelocity = DeltaOpen / DeltaClose;
Delta[0] = DeltaVelocity;
}
else if (BarsInProgress == 1)
{
// We have to update the secondary series of the cached indicator to make sure the values we get in BarsInProgress == 0 are in sync
OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).Update(OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).BarsArray[1].Count - 1, 1);
}
}
region Properties
[Browsable(false)]
[XmlIgnore]
public Series<double> Delta
{
get { return Values[0]; }
}
#endregion
}
}
Comment