I'm receiving an error on calling OnBarUpdate. I've the primary data series and a secondary data series as Volumetric bars. I believe it's the red highlighted portion which is causing the error. Could someone assist with a recommendation?
Thanks!
//This namespace holds Strategies in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Strategies
{
public class Name : Strategy
{
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 = 2000;
}
else if (State == State.Configure)
{
if (BarsPeriod.BarsPeriodType!=BarsPeriodType.Volumet ric)
AddVolumetric(Instrument.FullName, BarsPeriodType.Volume, UserDefinedVolume, VolumetricDeltaType.BidAsk, 1);
AddDataSeries(Data.BarsPeriodType.Tick, 1);
}
else if (State == State.DataLoaded)
{
// Indicators
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 60 || CurrentBars[1] < 1)
return;
if (Bars == null)
return;
for (int x=0; x<BarsArray.Length; x++)
if (CurrentBars[x] < 5)
return;
int idx = BarsArray.Length - 1;
NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe barsType1 = BarsArray[1].BarsType as NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe;
if (barsType1 == null || BarsInProgress != idx)
return;
var deltaSL = Math.Abs(barsType1.Volumes[CurrentBar].DeltaSl);
var deltaSH = Math.Abs(barsType1.Volumes[CurrentBar].DeltaSh);
Comment