Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Refresh problem

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

    Refresh problem

    Hello there,

    I'm building and testing a new indicator, it's a swing indicator. What I observed is that before and after refreshing the chart (where for refreshing I mean applying again that indicator w/o deleting) Indicator plots change.

    I coded it various times,, debugged several times, code seems to be working finebut the output is the same, when condition is verified I have a dbl plot on two consecutive bars.

    Attached images about that. Calcolate on bar close is set to true.

    Maybe I'm loosing something or some tricks about refreshing indicators (nt6).

    Thanks in advance,

    best regards

    Marcello
    Attached Files

    #2
    imported post

    Second image after indicato refresh
    Attached Files

    Comment


      #3
      imported post

      This happens each time? If yes, please send me the indicator code to ray at ninjatrader dot com and reference this post.

      Thanks
      RayNinjaTrader Customer Service

      Comment


        #4
        imported post

        The problem is that for indicators, OnBarUpdate() currently isnot guaranteed to be only called once per bar when CalculateOnBarClose = true. Do not code your indicator script assuming that you will only see one call per bar.

        What you can do is addsome code like the following:
        private int lastBarSeen = -1;

        protected override void OnBarUpdate()
        {
        if (CurrentBar <= lastBarSeen)
        return;
        lastBarSeen = CurrentBar;

        // Do something here
        }
        Ray
        RayNinjaTrader Customer Service

        Comment


          #5
          imported post

          Ray,
          It seems that CalculateOnBarClose is misnamed. If one can't trust it to calculate only on bar close should indicator code be wrapped like this?

          protected override void OnBarUpdate()
          {
          if(Bars.PercentComplete ==1)
          {
          // Do something here
          }
          }
          What is the difference in this, and your code below?

          Comment


            #6
            imported post

            We will address this issue later this year, its not critical and only is shows up on low value tick based intervals. The only impact this has is if you are managing internal counters and incrementing them on each call to OnBarUpdate(), otherwise, the logic within OnBarUpdate() is irrelevant no matter how many times this method is called. That being said, we do realize that its better if its guaranteed to be called once for each bar or tick.

            The code you provided is not the same as what I provided. My code checks on the actual bar index that is calling OnBarUpdate() where yours just checks if the bar is completed. The problem with yours is that the bar can be complete on a specified index and OnBarUpdate() is called more than once on that index.

            Ray
            RayNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by op1031, Today, 05:16 PM
            0 responses
            1 view
            0 likes
            Last Post op1031
            by op1031
             
            Started by fscabrera03, Today, 01:18 PM
            1 response
            11 views
            0 likes
            Last Post fscabrera03  
            Started by BottomShark77, Today, 12:20 PM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_ShawnB  
            Started by bowling, Today, 06:16 AM
            3 responses
            29 views
            0 likes
            Last Post NinjaTrader_ShawnB  
            Started by systemtrader4, Today, 01:54 AM
            2 responses
            88 views
            0 likes
            Last Post systemtrader4  
            Working...
            X