I'm working on a strategy where Cumulative Delta would reset to 0 if a large volume where to occur and the beginning of a session. Would the code below be able to reset the cumulative delta to 0, especially the areas highlighted in red?
Thanks!
namespace NinjaTrader.NinjaScript.Strategies
{
public class Name : Strategy
{
private VOL VOL1;
private double CD;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "Name";
Calculate = Calculate.OnBarClose;
EntriesPerDirection = 3;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = false;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 0;
StartBehavior = StartBehavior.WaitUntilFlat;
TimeInForce = TimeInForce.Gtc;
TraceOrders = false;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
StopTargetHandling = StopTargetHandling.PerEntryExecution;
BarsRequiredToTrade = 20;
// Disable this property for performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = true;
UserDefinedVolume = 10000;
}
else if (State == State.Configure)
{
AddDataSeries(Data.BarsPeriodType.Tick, 1);
}
else if (State == State.DataLoaded)
{
ClearOutputWindow();
VOL1 = VOL(Closes[0]);
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 10)
return;
if (BarsInProgress == 0)
{
// Print the close of the cumulative delta bar with a delta type of Bid Ask and with a Session period
CD = OrderFlowCumulativeDelta(BarsArray[0], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).DeltaClose[0];
}
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);
}
// Reset the tradeCounter value at the first tick of the first bar of each session.
if (Bars.IsFirstBarOfSession && IsFirstTickOfBar)
{
CD = 0;
}
if (VOL1[0]>UserDefinedVolume)
{
CD = 0;
}
if (ToTime(Times[0][0]) >= StartTradingTime)
{
if (CD > UserDefinedVolume)
EnterLong();
if (CD < -UserDefinedVolume)
EnterShort();
}
Comment