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

New Instance of Custom Indicator in OnBarUpdate Section

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

    New Instance of Custom Indicator in OnBarUpdate Section

    Hi, I am trying to understand a piece of code in a custom indicator. The guy calls another custom indicator in OnbarUpdate as follows:

    protected override void OnBarUpdate()
    {
    customInd XX = customInd(parm1, parm2, parm3);
    XX.Update();
    ...... uses public XX methods later ... which is fine I understand all that.

    What's the point of putting the customInd declaration in the OBU ? Wouldn't it be more efficient to put it into Initialize ? I understand that if I change the parameters real time then this would be reflected in the customInd call, but a boolean test could handle that without having to go through the customInd XX = statement on every tick.

    Also, are multiple instances of the customInd created ? Thus adding to the inefficiency of the parent indicator?

    thanks in advance

    #2
    The problem with placing this in Initialize is that Initialize() may be called at times when you wouldn't expect.

    Depending on what the parm1/2/3 are you may be able to put this in a conditional statement that would only make it be called once. From what I can see here its my understanding this XX was done to visually simplify the code but may not have a performance impact.
    Last edited by NinjaTrader_Lance; 06-03-2013, 09:13 AM.
    LanceNinjaTrader Customer Service

    Comment


      #3
      thanks Lance

      so Ninja/C# recognizes that XX is already created and skips the customInd XX = statement, or creates a new instance and throws away the old one?

      I think you are right about the visual simplification.

      Comment


        #4
        Originally posted by I_Quant View Post
        Hi, I am trying to understand a piece of code in a custom indicator. The guy calls another custom indicator in OnbarUpdate as follows:

        protected override void OnBarUpdate()
        {
        customInd XX = customInd(parm1, parm2, parm3);
        XX.Update();
        ...... uses public XX methods later ... which is fine I understand all that.

        What's the point of putting the customInd declaration in the OBU ? Wouldn't it be more efficient to put it into Initialize ? I understand that if I change the parameters real time then this would be reflected in the customInd call, but a boolean test could handle that without having to go through the customInd XX = statement on every tick.

        Also, are multiple instances of the customInd created ? Thus adding to the inefficiency of the parent indicator?

        thanks in advance
        You are correct. That is inefficiently instantiating the indicator on each tick.

        Much better would be to:
        Code:
        Declare a named instance of the indicator;
        Assign that instance, parameters (assuming that they would not change) in OnStartUp();
        Run Update() in the getter for the particular properties that you want to access.
        If the parameters would change, you can assign the new parameters in OnBarUpdate(), but then you are simply assigning to a named instance, not recreating it on every tick.

        Comment


          #5
          yup; I can sort out out the parameters separately

          many thanks to you both

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by ender_wiggum, Today, 09:50 AM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by rajendrasubedi2023, Today, 09:50 AM
          1 response
          10 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by geotrades1, Today, 10:02 AM
          0 responses
          4 views
          0 likes
          Last Post geotrades1  
          Started by bmartz, Today, 09:30 AM
          1 response
          8 views
          0 likes
          Last Post NinjaTrader_Erick  
          Started by geddyisodin, Today, 05:20 AM
          3 responses
          25 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Working...
          X