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

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 hazylizard, Today, 08:38 AM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_Erick  
            Started by geddyisodin, Today, 05:20 AM
            2 responses
            16 views
            0 likes
            Last Post geddyisodin  
            Started by Max238, Today, 01:28 AM
            5 responses
            43 views
            0 likes
            Last Post Max238
            by Max238
             
            Started by giulyko00, Yesterday, 12:03 PM
            3 responses
            13 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by habeebft, Today, 07:27 AM
            1 response
            16 views
            0 likes
            Last Post NinjaTrader_ChristopherS  
            Working...
            X