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

CalculateOnBarClose not working?

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

    CalculateOnBarClose not working?

    In the help it says CalculateOnBarClose needs to be false to operate on tick data and needs to be the last statement in Initialize(). When I do that I still only get a call on bar close.

    To verify this I print the current bar # in the start of my OnBarUpdate(). I would expect this to print the same bar # for however many ticks occur in this bar. Not so, only printed twice (why twice?) when there are MANY ticks coming in here (1000 tick graph).

    What am I doing wrong? I could swear it WAS working at one point (i have sounds hooked up and they were repeating per tick) but it does not now.

    Thanks for any help.

    My code:

    Code:
    protected override void Initialize()
            {
                signals = new DataSeries(this);
            
                Overlay                = true;
                PriceTypeSupported    = false; 
                
                CalculateOnBarClose    = false;
            }
    
            protected override void OnBarUpdate()
            {    
                Print("Current bar = " + CurrentBar);
    ...
            }
    Output:
    Current bar = 548
    Current bar = 548
    Current bar = 549
    Current bar = 549
    Current bar = 550
    Current bar = 550
    Current bar = 551
    Current bar = 551

    #2
    You will get a print for each tick in real-time only, not on any historical bars.
    RayNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Ray View Post
      You will get a print for each tick in real-time only, not on any historical bars.
      Aye, saw that in the help. I'm testing this with live RT data (NQ/ES futures).

      Comment


        #4
        Assuming -

        - When the indicator is added to your chart and the property in the indicator dialoge "Calculate on bar close" is set to false
        - Real-time bars only

        You will get a call to OnBarUpdate() for each incoming tick. I just ran a quick test and get many Print(CurrentBar) values to the Output window on a 150 tick bar connected to Zen-Fire.
        RayNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Ray View Post
          Assuming -

          - When the indicator is added to your chart and the property in the indicator dialoge "Calculate on bar close" is set to false
          - Real-time bars only

          You will get a call to OnBarUpdate() for each incoming tick. I just ran a quick test and get many Print(CurrentBar) values to the Output window on a 150 tick bar connected to Zen-Fire.
          Interesting. I was defaulting it to "false" in the code but it appears to come in as "true". Didn't even think to look at the indicator properties in the actual chart. Why does it not respect the default value?

          Comment


            #6
            - Either you have not compiled
            - You are loading a different indicator than the one you think you are
            - You changed the implementation but did not "Reload NinjaScript" (right click in chart) to reload the changed implementation after compiling the change

            Setting CalculateOnBarClose = false in Initialize(), the order in which it is set has no relevance.
            RayNinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Ray View Post
              - Either you have not compiled
              - You are loading a different indicator than the one you think you are
              - You changed the implementation but did not "Reload NinjaScript" (right click in chart) to reload the changed implementation after compiling the change

              Setting CalculateOnBarClose = false in Initialize(), the order in which it is set has no relevance.
              I agree it shouldn't have any effect (the order), just listening to the documentation:

              Definition
              If true, OnBarUpdate() is called on the close of each bar otherwise it is called on each incoming tick. This property should ONLY be set in an Initialize() method and be the last statement within that method.


              I am compiling, am loading the right one (its the only custom indicator), and am reloading it in the chart (I'm making other changes as well and they are being reflected). The false is not being respected. I'm not too concerned as I save chart templates anyways, just an interesting note



              cheers and thanks for the heads up on looking in the properties on the chart.

              Comment


                #8
                I've seen this too.

                Parameter settings such as CalculateOnBarClose that are specified in the Initialize method will have their values cached by NinjaTrader, so after changing the value in the source code and re-compiling, you should remove the indicator and reload the new copy so the new value from the Initialize method is used instead of the saved parameter value.

                Thus, using the "Reload NinjaScript" (or F5) is not sufficient, you must use the "Remove" and then "New" functions to load a fresh copy in this case.

                Comment


                  #9
                  Originally posted by KBJ View Post
                  I've seen this too.

                  Parameter settings such as CalculateOnBarClose that are specified in the Initialize method will have their values cached by NinjaTrader, so after changing the value in the source code and re-compiling, you should remove the indicator and reload the new copy so the new value from the Initialize method is used instead of the saved parameter value.

                  Thus, using the "Reload NinjaScript" (or F5) is not sufficient, you must use the "Remove" and then "New" functions to load a fresh copy in this case.
                  Ah, great tip. Thanks!

                  Comment


                    #10
                    The help file says...

                    CalculateOnBarClose

                    Definition
                    If true, OnBarUpdate() is called on the close of each bar otherwise it is called on each incoming tick. This property should ONLY be set in an Initialize() method and be the last statement within that method.
                    ...but there are a number of NinjaTrader supplied indicators which do not follow this rule about being "the last statement" of the Initialize() method, including CandleStickPattern, ConstantLines, DMIndex, ParabolicSAR, Swing, TEMA, and ZigZag.

                    So does this mean that sometimes it matters, and sometimes not?

                    Comment


                      #11
                      Don't recall the logic behind the statement in the Help Guide. It likely does not matter for the indicators you pointed out so I would just stay in sync with what the Help Guide states at this time.
                      RayNinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by bortz, 11-06-2023, 08:04 AM
                      47 responses
                      1,603 views
                      0 likes
                      Last Post aligator  
                      Started by jaybedreamin, Today, 05:56 PM
                      0 responses
                      8 views
                      0 likes
                      Last Post jaybedreamin  
                      Started by DJ888, 04-16-2024, 06:09 PM
                      6 responses
                      18 views
                      0 likes
                      Last Post DJ888
                      by DJ888
                       
                      Started by Jon17, Today, 04:33 PM
                      0 responses
                      4 views
                      0 likes
                      Last Post Jon17
                      by Jon17
                       
                      Started by Javierw.ok, Today, 04:12 PM
                      0 responses
                      12 views
                      0 likes
                      Last Post Javierw.ok  
                      Working...
                      X