Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CaclOnBarClose=false, and Plot method CPU usage

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

    CaclOnBarClose=false, and Plot method CPU usage

    I have a very specific question that I think the developers may be able to answer.

    Imagine that you have 3 indicators on a particular chart, called A, B, and C. Indicators A and B are set to CalcOnBarClose=True, and Indicator C is set to CalcOnBarClose=False, which means it updates on every tick.

    When a new tick comes in, obviously the OnBarUpdate call will execute on Indicator C, which I would think would also trigger the Plot method of that same indicator, to be able to visually show the new value on the chart.

    The question is, does executing the Plot method of Indicator C also indirectly trigger the Plot methods of indicators A and B? If the whole window is repainting as a result of a change in C, I would think that A and B also need to be repainted. This scenario means that if there is CPU-intensive code in the Plot routines of A and B, it will still get triggered on every tick, even though CalcOnBarClose is set to True for those indicators.

    Is this the case, or am I missing something? Thanks!

    #2
    Trader,

    In this case, there would be no calling of the other indicators methods like OnBarUpdate except for whatever is internally done for the graphics code. Plot methods wouldn't be accessible to you in supported code, and typically they do not need to be changed.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_AdamP View Post
      Trader,

      In this case, there would be no calling of the other indicators methods like OnBarUpdate except for whatever is internally done for the graphics code. Plot methods wouldn't be accessible to you in supported code, and typically they do not need to be changed.
      Actually, you can override the Plot method like this:

      public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)

      There is an indicator in the support forum indicators section called dValueArea7 which does this, along with a number of others. So I know that the OnBarUpdate call of the other indicators is not triggered, but is the Plot method triggered? Sometimes there is quite a bit of code in there, which can be even more intensive than what is in the OnBarUpdate call...

      Comment


        #4
        Trader,

        Yes, the plot method can be overridden as its part of the inheritance of the Indicator class. Its just that we don't have a reference sample on doing this currently, nor do we cover it in the help guide. This basically means "unsupported" but not "impossible".

        I am actually not sure here when the plot method would be called in relation to OnBarUpdate(), I suspect it would be after but I am not positive in the scenario you mentioned. I'll check with some other members of our NS team on Monday to see if they have any idea and get back to you.
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_AdamP View Post
          Trader,

          Yes, the plot method can be overridden as its part of the inheritance of the Indicator class. Its just that we don't have a reference sample on doing this currently, nor do we cover it in the help guide. This basically means "unsupported" but not "impossible".

          I am actually not sure here when the plot method would be called in relation to OnBarUpdate(), I suspect it would be after but I am not positive in the scenario you mentioned. I'll check with some other members of our NS team on Monday to see if they have any idea and get back to you.
          Thanks, much appreciated... I would think that it would get triggered every time the window is refreshed, which probably needs to happen when a "CalcOnBarClose=false" is updated on the same chart... but I could be wrong. You can let me know what the other team members think... thanks!

          Comment


            #6
            Trader,

            After talking with my colleagues, it looks like Plot() is called after each OnBarUpdate() and is responsible for drawing that indicator on the chart. Unfortunately this is a "under the hood" method, and though it can be overridden, it is not recommended. We removed this after NT 6.5 due to some unexpected behavior when people override it, or used it improperly.

            Unfortunately I can't really comment much further on this, apologies for any inconvenience.
            Adam P.NinjaTrader Customer Service

            Comment


              #7
              Plot Override

              Just two remarks:

              There is a number of NinjaTrader system indicators which override the plot method. This includes the Pivots, RegressionChannel, VolumeProfile, VolumeZones, ZigZag. You can use them as a reference.

              The plot is not updated each time OnBarUpdate() has been called. In a fast market you will only get an update after the display update interval, which I have set to 0.5 seconds for my purposes. If you use a display update interval, which is too small, NinjaTrader may freeze in a fast market depending on what is done in the custom plots.

              Comment


                #8
                Originally posted by Harry View Post
                Just two remarks:

                There is a number of NinjaTrader system indicators which override the plot method. This includes the Pivots, RegressionChannel, VolumeProfile, VolumeZones, ZigZag. You can use them as a reference.

                The plot is not updated each time OnBarUpdate() has been called. In a fast market you will only get an update after the display update interval, which I have set to 0.5 seconds for my purposes. If you use a display update interval, which is too small, NinjaTrader may freeze in a fast market depending on what is done in the custom plots.
                Thanks Harry... so what you are saying is that the refresh rate of the chart will always call the Plot method of each indicator on that chart no matter what, correct? That seems to be the "clock" that drives the refresh rate of the entire chart, according to my understanding of your statement. So to go back to my original question then, it would stand to reason that if you have a CalcOnBarClose=false indicator on the chart, then it must by definition refresh the entire chart on every tick, not on every X refresh seconds, correct? Otherwise the indicator would not be seen updating on every tick. This must mean that all Plot methods are called on every tick. Is my understanding correct?

                Comment


                  #9
                  Originally posted by Trader_55 View Post
                  Thanks Harry... so what you are saying is that the refresh rate of the chart will always call the Plot method of each indicator on that chart no matter what, correct? That seems to be the "clock" that drives the refresh rate of the entire chart, according to my understanding of your statement. So to go back to my original question then, it would stand to reason that if you have a CalcOnBarClose=false indicator on the chart, then it must by definition refresh the entire chart on every tick, not on every X refresh seconds, correct? Otherwise the indicator would not be seen updating on every tick. This must mean that all Plot methods are called on every tick. Is my understanding correct?
                  I do not know the internals of NinjaTrader, so whatever I am responding here, would need to be confirmed by somebody who knows it. I am more or less relying on deduction.

                  When the chart is refreshed all indicators are plotted, as far as I know this does not depend on whether CalculateOnBarClose has been set to true or false. The chart is refreshed earliest when the display update interval has elapsed and a new tick was registered during that interval or afterwards.

                  As far as I have understood this means that the code of the Plot Override() method may be executed every 0.5 seconds, if the display update interval for the chart is set to that value. This would apply to indicators with both CalculateOnBarClose set to true or false.

                  For the CPU load this would mean

                  -> CalculateOnBarClose = true -> OnBarUpdate() is triggered once at the bar close
                  -> CalculateOnBarClose = false -> OnBarUpdate() is triggered with every incoming tick
                  -> display update interval = 100 msec -> code contained within Plot Override() is executed up to 10 times per second for all indicators, depending on incoming ticks

                  But again, it would be better to have this explanation confirmed by somebody else.

                  Comment


                    #10
                    Originally posted by Harry View Post
                    I do not know the internals of NinjaTrader, so whatever I am responding here, would need to be confirmed by somebody who knows it. I am more or less relying on deduction.

                    When the chart is refreshed all indicators are plotted, as far as I know this does not depend on whether CalculateOnBarClose has been set to true or false. The chart is refreshed earliest when the display update interval has elapsed and a new tick was registered during that interval or afterwards.

                    As far as I have understood this means that the code of the Plot Override() method may be executed every 0.5 seconds, if the display update interval for the chart is set to that value. This would apply to indicators with both CalculateOnBarClose set to true or false.

                    For the CPU load this would mean

                    -> CalculateOnBarClose = true -> OnBarUpdate() is triggered once at the bar close
                    -> CalculateOnBarClose = false -> OnBarUpdate() is triggered with every incoming tick
                    -> display update interval = 100 msec -> code contained within Plot Override() is executed up to 10 times per second for all indicators, depending on incoming ticks

                    But again, it would be better to have this explanation confirmed by somebody else.
                    One way to test this would be to set the display update interval to something like 10 seconds, and then add an indicator on the chart that refreshes with every tick. If you see the indicator updating more than once every 10 seconds, that means that the indicator is overriding the refresh rate of the chart. Otherwise, the refresh rate of the chart must be the driving factor regardless of the indicator settings. In either case, all the Plot() calls must be happening whenever anything is changed on the chart... I don't think that you could refresh the chart without Plot() being called for everything that is on that particular window. If you disagree let me know... I may try testing this to see what happens - if I do I'll report the results.

                    Comment


                      #11
                      Thanks for your help here Harry.

                      There are internal mechanisms for plotting the currently forming price bar, outside of any script that is applied. OnBarUpdate() drives chart plotting for indicators and frequency of calls are raised according to CalculateOnBarClose setting defined for the indicator. It's either every tick (false) or on bar close(true).

                      While OnBarUpdate() will drive plot charting, the chart display is updated only as often as the refresh setting you define in properties. This doesn't affect calculations. It's the smallest time in-between chart display updates. Unless you are overriding plot you still need ticks (OBU calls) as the main driver for indicator plotting. If you override plot, then you could manually control when your chart is drawn, through custom events like timers.
                      Ryan M.NinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by kujista, Today, 05:44 AM
                      0 responses
                      5 views
                      0 likes
                      Last Post kujista
                      by kujista
                       
                      Started by ZenCortexCLICK, Today, 04:58 AM
                      0 responses
                      5 views
                      0 likes
                      Last Post ZenCortexCLICK  
                      Started by sidlercom80, 10-28-2023, 08:49 AM
                      172 responses
                      2,281 views
                      0 likes
                      Last Post sidlercom80  
                      Started by Irukandji, Yesterday, 02:53 AM
                      2 responses
                      18 views
                      0 likes
                      Last Post Irukandji  
                      Started by adeelshahzad, Today, 03:54 AM
                      0 responses
                      8 views
                      0 likes
                      Last Post adeelshahzad  
                      Working...
                      X