Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator OnBarUpdate on each new tick

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

    Indicator OnBarUpdate on each new tick

    I was wondering whether someone could help me with a question regarding NT indicators when used on a chart and "Calculate on bar close" equals FALSE.

    If the Indicator OnBarUpdate is called on each new tick the series will grow to hold 1 indicator value for each tick, in addition the indicator won't have the correct values. An SMA on 20 1 minute bars calculated each new ticks will be an SMA on 20 ticks. (At least that's how the code looks like).

    Does NT drop the last value in the series until the bar is fully calculated ?

    What happens to local variables in the script, do you use reflection to rollback their values to before the previous tick update ?

    #2
    Welcome to our forums - only the last bar would be affected here, so the your SMA would be working over the last 19 (closed bars) and then updating calcs based on the last tick seen. It would still be a 20 bar SMA at all times, no matter how many live tick updates your OnBarUpdate() would have been called for. Once the currently developing bar is completely build the process would shift one bar forward of course.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thanks for the reply! I'm still missing one piece here, what happens to the local script variables that the indicator is using ?

      Many indicators use variables for various calculations if those are updated tick by tick by the OnBarUpdate function then the indicator value won't come out right since they should be holding the values set by the last full bar and not the previous tick.

      So the question is are those variables rolled back on each tick to the value that existed at the previous bar end ?

      For example: The Aroon indicator has these local variables in it:
      " private double runningMax;
      private int runningMaxBar;
      private double runningMin;
      private int runningMinBar;"

      Those are updated on each tick but this would result in an incorrect calculation if they are not rolled back to their previous values after each tick.

      Comment


        #4
        Sorry I don't follow you - the same applies to the variables as well, your full OnBarUpdate() is rerun for each tick and thus the updated results are used. If we get a bar closure on the first tick of new bar > they will update as well using closing tick for the bar.

        You can access that state running COBC = false and save anything to a custom tracking variable if desired that you would have access to intrabar as the bar updates.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          So NT assumes that the designer of the Indicator uses local variables in such a way that is compatible with both ticks updates and bar updates ?

          Local variables that are used with the assumptions of bar updates might do various calculations which might not be valid if the indicator is updated tick by tick.

          My question was basically whether NT magically (using reflection or new objects) restores these local variables to their values at the last full bar. Thus allowing the designer of the indicator to ignore the possibility that the indicator might be updated on each new tick.

          Comment


            #6
            You're correct in understand Alon, the developer would need to be aware and handle if code is sensitive to that. The variable would hold whatever value you last set it to via code, there would be no 'under the hood' handling by NT.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Thank you! I'm not sure that all of your indicators are aware to that. Looking at the code some might result in a different values processing tick updates and bar updates - but I could be wrong. Thanks, you answered my questions.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by selu72, Today, 02:01 PM
              1 response
              3 views
              0 likes
              Last Post NinjaTrader_Zachary  
              Started by WHICKED, Today, 02:02 PM
              2 responses
              8 views
              0 likes
              Last Post WHICKED
              by WHICKED
               
              Started by f.saeidi, Today, 12:14 PM
              8 responses
              21 views
              0 likes
              Last Post f.saeidi  
              Started by Mikey_, 03-23-2024, 05:59 PM
              3 responses
              50 views
              0 likes
              Last Post Sam2515
              by Sam2515
               
              Started by Russ Moreland, Today, 12:54 PM
              1 response
              7 views
              0 likes
              Last Post NinjaTrader_Erick  
              Working...
              X