Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Object reference

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

    Object reference

    Hi, I'm writing an indicator that adds a higher level 'min' bars to my lower level tick chart. I'm getting this error message (Error on calling 'OnBarUpdate' method for indicator 'MyBackgroundHAHMA' on bar 0: Object reference not set to an instance of an object) but I cannot determine why ... below is the code that is generating this message. any insight would be appreciated; thanks

    protected override void OnBarUpdate()
    {
    // if(CurrentBar < 2)return; //Make sure there are at least 2 bars printed before processin

    Print(" ");
    Print(instName + " MyBackgroundHAHMA: " + Time[0].ToString());
    Print(instName + " BarsInProgress: " + BarsInProgress);

    if (BarsInProgress == 1) // process Min Chart
    {
    if (CurrentBar == 0)
    {
    HA_C.Set(Close[0]);
    HA_O.Set(Open[0]);
    HA2_C.Set(Close[0]);
    HA2_O.Set(Open[0]);
    return;
    }
    // HA Thma (yellow)
    HA2_O.Set((((Open[1] + High[1] + Low[1] + Close[1]) / 4) + HA2_O[1]) / 2);
    HA2_C.Set((((Open[0] + High[0] + Low[0] + Close[0]) / 4) + HA2_O[0] + Math.Max(High[0], HA2_O[0]) + Math.Min(Low[0], HA2_O[0])) / 4);
    MyHeiken = (3 * hma1[0] - 3 * hma2[0] + hma3[0]);

    // Price Thma (red)
    MyThma = (3 * hma1t[0] - 3 * hma2t[0] + hma3t[0]);
    }



    if (BarsInProgress == 0) // process current instrument
    {
    Print(instName + " MyThma: " + MyThma + " MyHeiken: " + MyHeiken);
    if (MyThma >= MyHeiken) BackColorSeries[0] = risingColor;
    else BackColorSeries[0] = fallingColor;
    }


    #2
    pman,

    I see you commented this out :

    // if(CurrentBar < 2)return; //Make sure there are at least 2 bars printed before processin

    I would suggest keeping it or rearranging your code here.

    if ( CurrentBar < 1 )
    {
    return;
    }
    else if (CurrentBar == 1 )
    {
    HA_C.Set(Close[0]);
    HA_O.Set(Open[0]);
    HA2_C.Set(Close[0]);
    HA2_O.Set(Open[0]);
    return;
    }
    else
    {
    //everything else
    }
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      tx ... when I uncomment that section, I get this message:

      Error on calling 'OnBarUpdate' method for indicator 'MyBackgroundHAHMA' on bar 2: Object reference not set to an instance of an object.

      Comment


        #4
        pman,

        This looks like a separate issue perhaps.

        I would suggest using a Try/Catch here. These can print out what line is causing the issue to the output window.

        http://www.ninjatrader.com/support/f...ead.php?t=9825
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          ok ...did that ... tx. Isolated the problem down to this statement:

          HA2_O.Set((((Open[1] + High[1] + Low[1] + Close[1]) / 4) + HA2_O[1]) / 2);


          Error message: 10/26/2012 12:15:00 AM System.NullReferenceException: Object reference not set to an instance of an object.
          at NinjaTrader.Indicator.MyBackgroundHAHMA.OnBarUpdat e()
          Error on calling 'OnBarUpdate' method for indicator 'MyBackgroundHAHMA' on bar 2: Object reference not set to an instance of an object
          .

          Comment


            #6
            pman,

            It could be this doesn't exist yet : HA2_O[1]

            You may want to do this :

            if ( CurrentBar < 1 )
            {
            return;
            }
            else if (CurrentBar <= 2 )
            {
            HA_C.Set(Close[0]);
            HA_O.Set(Open[0]);
            HA2_C.Set(Close[0]);
            HA2_O.Set(Open[0]);
            return;
            }
            else
            {
            //everything else
            }
            Adam P.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by pman777 View Post
              Hi, I'm writing an indicator that adds a higher level 'min' bars to my lower level tick chart. I'm getting this error message (Error on calling 'OnBarUpdate' method for indicator 'MyBackgroundHAHMA' on bar 0: Object reference not set to an instance of an object) but I cannot determine why ... below is the code that is generating this message. any insight would be appreciated; thanks

              protected override void OnBarUpdate()
              {
              // if(CurrentBar < 2)return; //Make sure there are at least 2 bars printed before processin

              Print(" ");
              Print(instName + " MyBackgroundHAHMA: " + Time[0].ToString());
              Print(instName + " BarsInProgress: " + BarsInProgress);

              if (BarsInProgress == 1) // process Min Chart
              {
              if (CurrentBar == 0)
              {
              HA_C.Set(Close[0]);
              HA_O.Set(Open[0]);
              HA2_C.Set(Close[0]);
              HA2_O.Set(Open[0]);
              return;
              }
              // HA Thma (yellow)
              HA2_O.Set((((Open[1] + High[1] + Low[1] + Close[1]) / 4) + HA2_O[1]) / 2);
              HA2_C.Set((((Open[0] + High[0] + Low[0] + Close[0]) / 4) + HA2_O[0] + Math.Max(High[0], HA2_O[0]) + Math.Min(Low[0], HA2_O[0])) / 4);
              MyHeiken = (3 * hma1[0] - 3 * hma2[0] + hma3[0]);

              // Price Thma (red)
              MyThma = (3 * hma1t[0] - 3 * hma2t[0] + hma3t[0]);
              }



              if (BarsInProgress == 0) // process current instrument
              {
              Print(instName + " MyThma: " + MyThma + " MyHeiken: " + MyHeiken);
              if (MyThma >= MyHeiken) BackColorSeries[0] = risingColor;
              else BackColorSeries[0] = fallingColor;
              }
              You have a multi timeframe setup. You need to check for CurrentBar validity on both barSeries.

              Comment


                #8
                will try ... thanks!

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by op1031, Yesterday, 05:51 PM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_PaulH  
                Started by aaadetos, 05-04-2021, 09:28 AM
                1 response
                5 views
                0 likes
                Last Post Lancer
                by Lancer
                 
                Started by Stanfillirenfro, Today, 04:34 AM
                1 response
                6 views
                0 likes
                Last Post Stanfillirenfro  
                Started by Impeesa, Today, 04:31 AM
                0 responses
                4 views
                0 likes
                Last Post Impeesa
                by Impeesa
                 
                Started by knarfoe, Today, 03:41 AM
                1 response
                10 views
                0 likes
                Last Post NinjaTrader_Jason  
                Working...
                X