I have a strategy that runs OK in the chart, but it gets "Object reference" error when trying to optimize it.
The error occurs here:
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 1)
return;
NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe barsType = Bars.BarsSeries.BarsType as
NinjaTrader.NinjaScript.BarsTypes.VolumetricBars Type;
Print("Step 1");
long vVolumen = barsType.Volumes[CurrentBar].TotalVolume;
Print("Step 2");
double vDeltaPorcentual = barsType.Volumes[CurrentBar].GetDeltaPercent();
Print("Step 3");
long vDelta = barsType.Volumes[CurrentBar].BarDelta;
}
When running the strategy, it prints "1", "2" and "3" in the NinjaScript Output window for each candle in the chart, but when running the optimizer it prints the following in the NinjaScript Output window:
Step 1
Strategy 'PatronesOF': Error on calling 'OnBarUpdate' method on bar 1: Object reference not set to an instance of an object.
Any suggestion?
Thanks
Comment