Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Object reference not set to an instance of an object just when optimizing.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Object reference not set to an instance of an object just when optimizing.

    Hi,

    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:
    protected override void OnBarUpdate()
    {

    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

    #2
    Hello javier.filgueira,

    The only object shown here is the barsType variable, are you using a primary series that is Volumetric?

    The other observation I can see is that you are misisng the conditions that are suggested in the help guide for working with volumetric data:

    Code:
    if (Bars == null)
    return;
    
    NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe barsType = Bars.BarsSeries.BarsType as
    NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe;
    
    if (barsType == null)
    return;

    https://ninjatrader.com/support/help...sub=volumetric



    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hello Jesse, thank you for your post.

      The chart has just one volumetric bars added. The only way I found to access level 2 data is adding the barsType variable as shown in the example.

      I added the sentences in your example as shown:
      protected override void OnBarUpdate()
      {
      if (BarsInProgress != 0)
      return;

      if (CurrentBars[0] < 1)
      return;

      if (Bars == null)
      return;

      double vTickSize = Bars.Instrument.MasterInstrument.TickSize;


      // Obtención de datos de la vela

      NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe barsType = Bars.BarsSeries.BarsType as
      NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe;

      if (barsType == null)
      return;
      Print("1");
      long vVolumen = barsType.Volumes[CurrentBar].TotalVolume;
      Print("2");
      double vDeltaPorcentual = barsType.Volumes[CurrentBar].GetDeltaPercent();
      Print("3");
      long vDelta = barsType.Volumes[CurrentBar].BarDelta;

      When adding the strategy to the chart, it works OK and shows "1", "2" and "3" in the Output window, but when running an optimization it shows: "Error on calling 'OnBarUpdate' method on bar 0: Object reference not set to an instance of an object."

      Thanks in advance for any suggestion.

      Comment


        #4
        Hello javier.filgueira,

        Yes the error means that an object you used was null. Have you tried to copy the sample from the help guide exactly as its shown? I tried that and see it working in the analyzer.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by r68cervera, Today, 05:29 AM
        0 responses
        3 views
        0 likes
        Last Post r68cervera  
        Started by geddyisodin, Today, 05:20 AM
        0 responses
        6 views
        0 likes
        Last Post geddyisodin  
        Started by JonesJoker, 04-22-2024, 12:23 PM
        6 responses
        35 views
        0 likes
        Last Post JonesJoker  
        Started by GussJ, 03-04-2020, 03:11 PM
        12 responses
        3,240 views
        0 likes
        Last Post Leafcutter  
        Started by AveryFlynn, Today, 04:57 AM
        0 responses
        7 views
        0 likes
        Last Post AveryFlynn  
        Working...
        X