• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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?
    https://ninjatrader.com/support/help...-us/update.htm

    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 seagraph, Today, 03:27 PM
                      0 responses
                      9 views
                      0 likes
                      Last Post seagraph  
                      Started by dedouglas, Today, 02:54 PM
                      1 response
                      10 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Started by elkhatabi, 08-01-2019, 06:36 PM
                      5 responses
                      50 views
                      0 likes
                      Last Post NinjaTrader_RyanL  
                      Started by mr_trade, Today, 01:01 PM
                      4 responses
                      17 views
                      0 likes
                      Last Post mr_trade  
                      Started by Renorail, Today, 12:31 PM
                      1 response
                      12 views
                      0 likes
                      Last Post NinjaTrader_PaulH  
                      Working...
                      X