Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

OnBarUpdate() not called

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

    OnBarUpdate() not called

    Hi,
    I have a custom indicator that instantiate (or embed) a few other custom/system indicators
    as follows:
    protected override void OnStartUp()
    {
    Print("Inside OnStartUp");
    _UpDown1 = RKMDCUpDown2(Color.Blue, Color.Red, MACDFast, MACDSlow, MACDSmooth);
    _Stoch1 = RKMDCStoch(barsUsedInCalc, dColor, dWidth, kColor, kWidth, pctDSmooth, pctKSmooth);
    _CCI1 = CCI(Typical, CCIPeriod);
    _KRB1 = RKMKRB();
    Print("Exiting OnStartUp");
    }

    I put some Print() statements in the OnBarUpdate() of the instantiated indicators and found that it is never called. The OnBarUpdate() is called in the top level indicator (the
    instantiating indicator). Here is the code snippet for the OnBarUpdate() of the top level:
    protected override void OnBarUpdate()
    {
    Print(" RKMEvalCTP OnBarUpdate Time: " + Time[0]);

    if (CurrentBar < 53)
    return;
    EvalCond();
    }

    I see the print statement above is executed for 53 times and then I got the following error when trying to access a DataSeries in the lower level indicator:
    Error on calling 'OnBarUpdate' method for indicator 'RKMEvalCTP' on bar 53: Object reference not set to an instance of an object.
    temp = _UpDown1.IsLongZoneArr[1];

    Thanks.

    #2
    Originally posted by rkm2011 View Post
    Hi,
    I have a custom indicator that instantiate (or embed) a few other custom/system indicators
    as follows:
    protected override void OnStartUp()
    {
    Print("Inside OnStartUp");
    _UpDown1 = RKMDCUpDown2(Color.Blue, Color.Red, MACDFast, MACDSlow, MACDSmooth);
    _Stoch1 = RKMDCStoch(barsUsedInCalc, dColor, dWidth, kColor, kWidth, pctDSmooth, pctKSmooth);
    _CCI1 = CCI(Typical, CCIPeriod);
    _KRB1 = RKMKRB();
    Print("Exiting OnStartUp");
    }

    I put some Print() statements in the OnBarUpdate() of the instantiated indicators and found that it is never called. The OnBarUpdate() is called in the top level indicator (the
    instantiating indicator). Here is the code snippet for the OnBarUpdate() of the top level:
    protected override void OnBarUpdate()
    {
    Print(" RKMEvalCTP OnBarUpdate Time: " + Time[0]);

    if (CurrentBar < 53)
    return;
    EvalCond();
    }

    I see the print statement above is executed for 53 times and then I got the following error when trying to access a DataSeries in the lower level indicator:
    Error on calling 'OnBarUpdate' method for indicator 'RKMEvalCTP' on bar 53: Object reference not set to an instance of an object.
    temp = _UpDown1.IsLongZoneArr[1];

    Thanks.
    Where did you declare _UpDown1?

    Comment


      #3
      Originally posted by rkm2011 View Post
      Hi,
      I have a custom indicator that instantiate (or embed) a few other custom/system indicators
      as follows:
      protected override void OnStartUp()
      {
      Print("Inside OnStartUp");
      _UpDown1 = RKMDCUpDown2(Color.Blue, Color.Red, MACDFast, MACDSlow, MACDSmooth);
      _Stoch1 = RKMDCStoch(barsUsedInCalc, dColor, dWidth, kColor, kWidth, pctDSmooth, pctKSmooth);
      _CCI1 = CCI(Typical, CCIPeriod);
      _KRB1 = RKMKRB();
      Print("Exiting OnStartUp");
      }

      I put some Print() statements in the OnBarUpdate() of the instantiated indicators and found that it is never called. The OnBarUpdate() is called in the top level indicator (the
      instantiating indicator). Here is the code snippet for the OnBarUpdate() of the top level:
      protected override void OnBarUpdate()
      {
      Print(" RKMEvalCTP OnBarUpdate Time: " + Time[0]);

      if (CurrentBar < 53)
      return;
      EvalCond();
      }

      I see the print statement above is executed for 53 times and then I got the following error when trying to access a DataSeries in the lower level indicator:
      Error on calling 'OnBarUpdate' method for indicator 'RKMEvalCTP' on bar 53: Object reference not set to an instance of an object.
      temp = _UpDown1.IsLongZoneArr[1];

      Thanks.
      if you increase 53 to 60, do you see "'for indicator 'RKMEvalCTP' on bar 60: Object".... ?

      what about 600?
      Last edited by sledge; 11-04-2012, 12:25 AM. Reason: type, 50->60

      Comment


        #4
        Hi Koganam,
        Here is the declaration:
        namespace NinjaTrader.Indicator
        {
        /// <summary>
        /// Enter the description of your new custom indicator here
        /// </summary>
        [Description("Enter the description of your new custom indicator here")]
        public class RKMEvalCTP : Indicator
        {
        #region Variables
        // Wizard generated variables
        private int myInput0 = 1; // Default setting for MyInput0
        // User defined variables (add any user defined variables below)
        #endregion

        int pctKSmooth = 3;
        int pctDSmooth = 3;
        int barsUsedInCalc = 5;
        int kWidth = 2;
        Color kColor = Color.Blue;
        int dWidth = 2;
        Color dColor = Color.Transparent;
        double StochThresH = 77.0;
        double StochThresL = 24.0;
        int CCIPeriod = 4;
        double StochOBThres = 78;
        double StochOSThres = 22;
        int MACDFast = 9;
        int MACDSlow = 26;
        int MACDSmooth = 6;
        RKMDCStoch _Stoch1;
        CCI _CCI1;
        RKMDCUpDown2 _UpDown1;
        RKMKRB _KRB1;

        Comment


          #5
          Originally posted by rkm2011 View Post
          Hi Koganam,
          Here is the declaration:
          namespace NinjaTrader.Indicator
          {
          /// <summary>
          /// Enter the description of your new custom indicator here
          /// </summary>
          [Description("Enter the description of your new custom indicator here")]
          public class RKMEvalCTP : Indicator
          {
          #region Variables
          // Wizard generated variables
          private int myInput0 = 1; // Default setting for MyInput0
          // User defined variables (add any user defined variables below)
          #endregion

          int pctKSmooth = 3;
          int pctDSmooth = 3;
          int barsUsedInCalc = 5;
          int kWidth = 2;
          Color kColor = Color.Blue;
          int dWidth = 2;
          Color dColor = Color.Transparent;
          double StochThresH = 77.0;
          double StochThresL = 24.0;
          int CCIPeriod = 4;
          double StochOBThres = 78;
          double StochOSThres = 22;
          int MACDFast = 9;
          int MACDSlow = 26;
          int MACDSmooth = 6;
          RKMDCStoch _Stoch1;
          CCI _CCI1;
          RKMDCUpDown2 _UpDown1;
          RKMKRB _KRB1;
          Hm. That looks correctly declared as a class variable.

          Try this for starters, so we can help isolate the issue. Change
          Code:
          temp = _UpDown1.IsLongZoneArr[1];
          to
          Code:
          temp = _UpDown1.IsLongZoneArr[0];
          Does it behave itself now?

          Comment


            #6
            Hello rkm2011,
            To assist you further can you please send a toy NinjaScript code* replicating the behavior to support[AT]ninjatrader[DOT]com

            Please append Attn:Joydeep in the subject line of the email and give a reference of this thread in the body of the email.

            I look forward to assisting you further.

            *The "toy" just means something that is a stripped down version that isn't necessarily the whole logic. It makes things easier to rout out.
            JoydeepNinjaTrader Customer Service

            Comment


              #7
              Hi Joydeep,
              In reply to your suggestion:
              if you increase 53 to 60, do you see "'for indicator 'RKMEvalCTP' on bar 60: Object".... ?
              what about 600?
              The error is still there, it just move to bar 60 and 600 instead of 53.

              Also, in this experiment:
              temp = _UpDown1.IsLongZoneArr[0];
              The error is still there.

              In the process of creating the toy code to send you, I found out about the culprit of the error.
              I appreciate if you could give me the explanation.
              The arrays (dataseries) are created in the Initialize() method as follows. Notice that the
              'IsLongZone' the the 4th calls to new.
              protected override void Initialize()
              {
              Avg = new DataSeries(this);
              Value = new DataSeries(this);
              Diff = new DataSeries(this);
              IsLongZone = new DataSeries(this);
              fastEma = new DataSeries(this);
              slowEma = new DataSeries(this);
              DC_Down = new DataSeries(this);
              DC_Up = new DataSeries(this);
              }

              I have access function
              [Browsable(false)]
              [XmlIgnore()]
              public DataSeries IsLongZoneArr
              {
              get { return Values[3]; }
              }

              Notice that the index 3 in Values.

              Now if I moved the new for IsLongZone to be the first one and I change the access function to
              Values[0], THE ERROR WENT AWAY!!!! Everything seems to work now (after moving the
              new of IsLongZone).

              Why is that?

              Thanks,
              Robert.

              Comment


                #8
                Originally posted by rkm2011 View Post
                Hi Joydeep,
                In reply to your suggestion:
                if you increase 53 to 60, do you see "'for indicator 'RKMEvalCTP' on bar 60: Object".... ?
                what about 600?
                The error is still there, it just move to bar 60 and 600 instead of 53.

                Also, in this experiment:
                temp = _UpDown1.IsLongZoneArr[0];
                The error is still there.

                In the process of creating the toy code to send you, I found out about the culprit of the error.
                I appreciate if you could give me the explanation.
                The arrays (dataseries) are created in the Initialize() method as follows. Notice that the
                'IsLongZone' the the 4th calls to new.
                protected override void Initialize()
                {
                Avg = new DataSeries(this);
                Value = new DataSeries(this);
                Diff = new DataSeries(this);
                IsLongZone = new DataSeries(this);
                fastEma = new DataSeries(this);
                slowEma = new DataSeries(this);
                DC_Down = new DataSeries(this);
                DC_Up = new DataSeries(this);
                }

                I have access function
                [Browsable(false)]
                [XmlIgnore()]
                public DataSeries IsLongZoneArr
                {
                get { return Values[3]; }
                }

                Notice that the index 3 in Values.

                Now if I moved the new for IsLongZone to be the first one and I change the access function to
                Values[0], THE ERROR WENT AWAY!!!! Everything seems to work now (after moving the
                new of IsLongZone).

                Why is that?

                Thanks,
                Robert.
                Put in strategy OnBarUpdate first statement

                if ( CurrentBar < 4) { return; }

                or

                if ( CurrentBar < BarsRequired) { return; }

                Comment


                  #9
                  Hello rkm2011,
                  Values refer to the Plot values which will be plotted on the charts. In your code you dont have any plot values, only Data Series.

                  DataSeries objects held by this collection are added by calling the Add() method.


                  Object reference not set to an instance of an object.

                  The above error indicates that you have not initialized an object.
                  JoydeepNinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by rkm2011 View Post
                    Hi Joydeep,
                    In reply to your suggestion:
                    if you increase 53 to 60, do you see "'for indicator 'RKMEvalCTP' on bar 60: Object".... ?
                    what about 600?
                    The error is still there, it just move to bar 60 and 600 instead of 53.

                    Also, in this experiment:
                    temp = _UpDown1.IsLongZoneArr[0];
                    The error is still there.

                    In the process of creating the toy code to send you, I found out about the culprit of the error.
                    I appreciate if you could give me the explanation.
                    The arrays (dataseries) are created in the Initialize() method as follows. Notice that the
                    'IsLongZone' the the 4th calls to new.
                    protected override void Initialize()
                    {
                    Avg = new DataSeries(this);
                    Value = new DataSeries(this);
                    Diff = new DataSeries(this);
                    IsLongZone = new DataSeries(this);
                    fastEma = new DataSeries(this);
                    slowEma = new DataSeries(this);
                    DC_Down = new DataSeries(this);
                    DC_Up = new DataSeries(this);
                    }

                    I have access function
                    [Browsable(false)]
                    [XmlIgnore()]
                    public DataSeries IsLongZoneArr
                    {
                    get { return Values[3]; }
                    }

                    Notice that the index 3 in Values.

                    Now if I moved the new for IsLongZone to be the first one and I change the access function to
                    Values[0], THE ERROR WENT AWAY!!!! Everything seems to work now (after moving the
                    new of IsLongZone).

                    Why is that?

                    Thanks,
                    Robert.
                    Which pretty much completely explains your problem. You created DataSeries, then correctly exposed them. However, you tried to populate the DataSeries from the NT (reserved word) Values collection which are only created if Plots are defined. You need to differentiate between Plots and user-defined DataSeries, and how to populate them.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by PhillT, Today, 02:16 PM
                    2 responses
                    6 views
                    0 likes
                    Last Post PhillT
                    by PhillT
                     
                    Started by Kaledus, Today, 01:29 PM
                    3 responses
                    10 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by frankthearm, Yesterday, 09:08 AM
                    14 responses
                    47 views
                    0 likes
                    Last Post NinjaTrader_Clayton  
                    Started by gentlebenthebear, Today, 01:30 AM
                    2 responses
                    14 views
                    0 likes
                    Last Post gentlebenthebear  
                    Started by PaulMohn, Today, 12:36 PM
                    2 responses
                    17 views
                    0 likes
                    Last Post PaulMohn  
                    Working...
                    X