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 Jon17, Today, 04:33 PM
        0 responses
        1 view
        0 likes
        Last Post Jon17
        by Jon17
         
        Started by Javierw.ok, Today, 04:12 PM
        0 responses
        4 views
        0 likes
        Last Post Javierw.ok  
        Started by timmbbo, Today, 08:59 AM
        2 responses
        10 views
        0 likes
        Last Post bltdavid  
        Started by alifarahani, Today, 09:40 AM
        6 responses
        41 views
        0 likes
        Last Post alifarahani  
        Started by Waxavi, Today, 02:10 AM
        1 response
        20 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Working...
        X