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 is called before OnStartUp

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

    OnBarUpdate is called before OnStartUp

    Sometimes an indicator loaded by another indicator may run OnBarUpdate a number of times before it runs OnStartUp.

    Is there anybody here who can shed some understand on this situation so I can figure out how to work around it?

    Thanks, Ben

    #2
    Here is some code that shows a scenario that may cause the inner indicator to run its OnBarUpdate method before its OnStartUp method

    Code:
    // start indicator code extract
    
    InnerIndicator innerIndicator; // store a reference to the "inner" indicator
    
    protected override void Initialize()
    {
        // add an additional one-minute dataseries
        Add(PeriodType.Minute, 1);
    }
    
    protected override void OnStartUp()
    {
        // create the "inner" indicator on the additional one-minute series and store a reference to it
        innerIndicator = InnerIndicator(Closes[1]);
    }
    
    protected overrride void OnBarUpdate()
    {
        if (BarsInProgress != 0)
            return;
    
        // ensure the inner indicator is up to date
        innerIndicator.Update();
    
        // use data from the inner indicator
    }
    
    // end indicator code extract

    Comment


      #3
      You could count the # of objects created in the InnerIndicator to see if caching in NT is involved.

      Just be sure to decrease the count upon termination.

      Comment


        #4
        Hi Sledge, thanks for the suggestion, I have investigated caching before and found the following, correct me if I'm wrong:

        Caches are only on a per-indicator basis.
        NinjaTrader does not store a global cache of indicators.
        Each indicator stores its own private cache of indicators it has already created.
        Each indicator does not have access to indicators created and cached by other indicators.

        Comment


          #5
          Hello Ben,

          Thank you for your post.

          I have not seen any scenario that does this.

          Are you just trying to load one indicator in the first script or are there multiple ones working?
          Cal H.NinjaTrader Customer Service

          Comment


            #6
            Message deleted to avoid confusion.
            Last edited by Harry; 08-22-2014, 01:09 PM. Reason: Incorrect comment, message deleted.

            Comment


              #7
              Hi Cal, there are often multiple inner indicators loaded by the first script.

              Comment


                #8
                Originally posted by bboyle1234
                Hey Harry, interesting comment. I've been doing it for years in heaps of indicators and it seems to work (except when it doesn't). Can you expand on that? What would you do instead?
                Sorrry, I was tired when I answered and my comment was not correct, I have therefore deleted it.

                Comment


                  #9
                  Hello bboyle1234,

                  I wanted to check, when you see the OnBarUpdate run a number of times before the OnStartUp, is this only when you are storing a indicator such as you posted:

                  Code:
                  InnerIndicator innerIndicator; // store a reference to the "inner" indicator
                  I would like to try and recreate what you are experiencing, can you provide an example script for me to check, preferably limited to just the portion of the script that is causing this.

                  With what you had provided earlier I was unable to recreate this. I have attached the test I have run please review it and verify I am doing the same as you are.

                  Test2 calls Test in the same way that you had posted originally.

                  I set my chart for 10 bars to control the amount of prints, I got 20 total print statements, 10 for Test2 and 10 for Test.

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

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by ZenCortexCLICK, Today, 04:58 AM
                  0 responses
                  2 views
                  0 likes
                  Last Post ZenCortexCLICK  
                  Started by sidlercom80, 10-28-2023, 08:49 AM
                  172 responses
                  2,280 views
                  0 likes
                  Last Post sidlercom80  
                  Started by Irukandji, Yesterday, 02:53 AM
                  2 responses
                  17 views
                  0 likes
                  Last Post Irukandji  
                  Started by adeelshahzad, Today, 03:54 AM
                  0 responses
                  4 views
                  0 likes
                  Last Post adeelshahzad  
                  Started by Barry Milan, Yesterday, 10:35 PM
                  3 responses
                  13 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Working...
                  X