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() and Update()

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

    OnBarUpdate() and Update()

    I am creating an indicator which has methods/properties for querying to be used by other strategies/indicators. Following patterns of other indicators and the documentation referenced here https://ninjatrader.com/support/helpGuides/nt8/en-us/ I call Update in these properties/methods. I noticed that OnBarUpdate is being called redundantly.

    I am curious what mechanism is required for Update() to not call OnBarUpdate per the documentation "If the values are already up to date, the Update() method will not be run".

    #2
    Hello ntbone,

    You have linked the landing page of the help guide.

    Are you referring to the Update() method linked below?


    Update() triggers OnBarUpdate().

    If you have a property that is not a series, then this property should trigger OnBarUpdate() to run before being returned.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Yes, I am referring to Update. It explicitly mentions "If the values are already up to date, the Update() method will not be run". I have found though that Update() seems to trigger OnBarUpdate() regardless of whether its already been run once for a given tick etc... when called from another indicator. I am not sure what that sentence of the documentation is referring to.

      Comment


        #4
        Hello ntbone,

        How do you know OnBarUpdate() is triggering more than once?

        I've tested printing a counter in OnBarUpdate() from a hosted script property that calls update that is pulled to a host script.

        I'm only seeing OnBarUpdate() print once.

        (edit) added CurrentBar as per ntbone suggestion, ..because of course CurrentBar..)
        Attached Files
        Last edited by NinjaTrader_ChelseaB; 07-16-2019, 07:06 AM.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I put print statements in the host script's OnBarUpdate at the beginning and the end. Then I call properties on the hosted script (anything that calls Update()). I then put print statements also in the hosted script OnBarUpdate. I will see that the hosted script OnBarUpdate will have multiple calls to OnBarUpdate nested inside the print statements of the host script. I was also using on each tick for the host script.

          Comment


            #6
            Hello ntbone,

            If you add multiple prints you will see multiple prints.

            Without modifying the test script I have provided you are you seeing there are multiple calls to OnBarUpdate for the same bar?

            With Calculate.OnEachTick, each bar will update multiple times.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              The print output I get looks approximately as follows

              Host OnBarUpdate started
              Call method of hosted script that calls Update -> Hosted OnBarUpdate called
              Call different method of hosted script that calls Update -> Hosted OnBarUpdate called
              Host OnBarUpdate ended

              If Update was doing as described in the documentation, "If the values are already up to date, the Update() method will not be run", the second call to Update would not be triggering OnBarUpdate. In this case I have not added multiple print statements to Hosted OnBarUpdate. OnBarUpdate is being called multiple times. I have also confirmed this with break points.

              I also understand that Calculate.OnEachTick will result in each bar getting updated multiple times, however, the hosted script shouldn't see more updates than the host script that is triggering its OnBarUpdate via Update() method.

              Comment


                #8
                Hello ntbone,

                On my end using my test script I am getting one print per bar update.

                I would like to schedule a call with you so that you may demonstrate using the test script I have provided you with no modifications that OnBarUpdate() is triggering multiple prints for the same bar and that the output you are experiencing is different than the output I am experiencing when using the exact same test script with no modifications.

                I will not be able to assist with using visual studio and break points to test this.

                Please send an email to platformsupport [at] ninjatrader [dot] com. In the email please include a link to this forum thread.

                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  I just tried to reproduce this and was unable to with a test script. I'll have to investigate my other script to determine why it might be doing this. I'll message back if I am able to reproduce it and find out more.

                  Comment


                    #10
                    Hi Chelsea
                    unsure if this is the right place to place this request for help converting an indi from 7>8,
                    i've started to build the indi but need to add the onbarupdate code, i've looked and looked at the info sent by the support team, no idea where to start, here is the files and what i want it to look like and do, hope you can help as i'd really like to learn to modify and start learning how to do it myself,

                    here is what i was asked to do, by support:
                    You basically would need to copy the code from the NT7 OnBarUpdate() method and paste it into the NT8 OnBarUpdate(), however once pasted you would need to convert the NT7 code to the equivalent NT8 code. To do that, please use the NT8 code breaking section of the help guide that will show the NT7 method/property and what the NT8 method/property

                    sounds simple enough ~ once i opened the help topic page it lists 2 pages of method properties, none of which seemed to relate to "On Bar Update" from what i could see
                    it may as well be written in Chinese, useless to a non coder, so if i am going to get help, i need to know what section of the code needs to be copied and what part of the method properties section needs changing, or a link showing an example of, which i'm sure there are plenty
                    regards Angelo
                    Attached Files

                    Comment


                      #11
                      I added printing out the CurrentBar to my print statements which revealed that no redundant calls to OnBarUpdate were being called. It appears that Update() is working as expected.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by cre8able, Today, 03:20 PM
                      0 responses
                      2 views
                      0 likes
                      Last Post cre8able  
                      Started by Fran888, 02-16-2024, 10:48 AM
                      3 responses
                      46 views
                      0 likes
                      Last Post Sam2515
                      by Sam2515
                       
                      Started by martin70, 03-24-2023, 04:58 AM
                      15 responses
                      114 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Started by The_Sec, Today, 02:29 PM
                      1 response
                      7 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Started by jeronymite, 04-12-2024, 04:26 PM
                      2 responses
                      31 views
                      0 likes
                      Last Post NinjaTrader_BrandonH  
                      Working...
                      X