• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

PercentComplete behavior

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

    PercentComplete behavior

    Hello Support Tem!

    After PercentComplete is set to 1.0 I can still see an update of the current bar. The following code can demonstrate the behavior:

    Code:
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public class Test : Indicator
        {
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                                    = @"Indicator is used for testing purpose";
                    Name                                            = "Test";
                    Calculate                                       = Calculate.OnEachTick;
                    IsOverlay                                       = true;
                    DisplayInDataBox                          = true;
                    DrawOnPricePanel                        = true;
                    DrawHorizontalGridLines               = true;
                    DrawVerticalGridLines                   = true;
                    PaintPriceMarkers                         = true;
                    ScaleJustification                           = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                    IsSuspendedWhileInactive            = true;
                }
            }
    
            protected override void OnBarUpdate()
            {
             if (BarsInProgress != 0)
                 {
                 return;
                }
              if (CurrentBar < Bars.Count - 1)
                 {
                 return;
                }            
             if (Bars.PercentComplete >= 1)
                 {
                 Print ("Current time = " + DateTime.Now + " PercentComplete = " + this.Bars.PercentComplete + " BarID = " + CurrentBar + " Bar Time = " + this.Bars.GetTime (CurrentBar) + " Last Chart Bar = " + Time[0].ToString ());
                }
            }
        }
    }



    Printout:

    Current time = 11-12-2018 15:18:00 PercentComplete = 1 BarID = 500 Bar Time = 11-12-2018 15:18:00 Last Chart Bar = 11-12-2018 15:18:00
    Current time = 11-12-2018 15:18:00 PercentComplete = 1 BarID = 500 Bar Time = 11-12-2018 15:18:00 Last Chart Bar = 11-12-2018 15:18:00
    Current time = 11-12-2018 15:18:01 PercentComplete = 1 BarID = 500 Bar Time = 11-12-2018 15:18:00 Last Chart Bar = 11-12-2018 15:18:00
    Current time = 11-12-2018 15:18:01 PercentComplete = 1 BarID = 500 Bar Time = 11-12-2018 15:18:00 Last Chart Bar = 11-12-2018 15:18:00
    Current time = 11-12-2018 15:18:02 PercentComplete = 1 BarID = 500 Bar Time = 11-12-2018 15:18:00 Last Chart Bar = 11-12-2018 15:18:00
    Current time = 11-12-2018 15:18:02 PercentComplete = 1 BarID = 500 Bar Time = 11-12-2018 15:18:00 Last Chart Bar = 11-12-2018 15:18:00
    Current time = 11-12-2018 15:18:02 PercentComplete = 1 BarID = 500 Bar Time = 11-12-2018 15:18:00 Last Chart Bar = 11-12-2018 15:18:00
    Current time = 11-12-2018 15:18:03 PercentComplete = 1 BarID = 500 Bar Time = 11-12-2018 15:18:00 Last Chart Bar = 11-12-2018 15:18:00
    Current time = 11-12-2018 15:19:00 PercentComplete = 1 BarID = 501 Bar Time = 11-12-2018 15:19:00 Last Chart Bar = 11-12-2018 15:19:00
    Current time = 11-12-2018 15:19:00 PercentComplete = 1 BarID = 501 Bar Time = 11-12-2018 15:19:00 Last Chart Bar = 11-12-2018 15:19:00
    Current time = 11-12-2018 15:19:01 PercentComplete = 1 BarID = 501 Bar Time = 11-12-2018 15:19:00 Last Chart Bar = 11-12-2018 15:19:00
    Current time = 11-12-2018 15:19:01 PercentComplete = 1 BarID = 501 Bar Time = 11-12-2018 15:19:00 Last Chart Bar = 11-12-2018 15:19:00
    Current time = 11-12-2018 15:19:02 PercentComplete = 1 BarID = 501 Bar Time = 11-12-2018 15:19:00 Last Chart Bar = 11-12-2018 15:19:00
    Current time = 11-12-2018 15:19:02 PercentComplete = 1 BarID = 501 Bar Time = 11-12-2018 15:19:00 Last Chart Bar = 11-12-2018 15:19:00
    Current time = 11-12-2018 15:19:02 PercentComplete = 1 BarID = 501 Bar Time = 11-12-2018 15:19:00 Last Chart Bar = 11-12-2018 15:19:00
    Current time = 11-12-2018 15:19:03 PercentComplete = 1 BarID = 501 Bar Time = 11-12-2018 15:19:00 Last Chart Bar = 11-12-2018 15:19:00

    The printout shows 2 things:
    1. After PercentComplete is set to 1.0, an update of the bar has been performed several times (see BarID)
    2. Update of the bar is taking place during the time of the next bar (see Current time in comparision to the ongoing bar time)

    Could you please clarify if such behavior is correct.

    Thank you very much in advance
    GmA

    #2
    Hello GmA,

    Likely this code is not the exact code you have tested.
    Bars.PercentComplete will never be greater than 1. A 1 means that the bar is complete.

    However, with that condition removed, I am not able to reproduce.
    Here is a sample of the output I am seeing:
    Current time = 12/11/2018 9:41:58 AM PercentComplete = 0.970832733333333 BarID = 5156 Bar Time = 12/11/2018 9:42:00 AM Last Chart Bar = 12/11/2018 9:42:00 AM
    Current time = 12/11/2018 9:41:58 AM PercentComplete = 0.970832733333333 BarID = 5156 Bar Time = 12/11/2018 9:42:00 AM Last Chart Bar = 12/11/2018 9:42:00 AM
    Current time = 12/11/2018 9:41:58 AM PercentComplete = 0.970832733333333 BarID = 5156 Bar Time = 12/11/2018 9:42:00 AM Last Chart Bar = 12/11/2018 9:42:00 AM
    Current time = 12/11/2018 9:42:00 AM PercentComplete = 0.00231634666666669 BarID = 5157 Bar Time = 12/11/2018 9:43:00 AM Last Chart Bar = 12/11/2018 9:43:00 AM
    Current time = 12/11/2018 9:42:00 AM PercentComplete = 0.00231634666666669 BarID = 5157 Bar Time = 12/11/2018 9:43:00 AM Last Chart Bar = 12/11/2018 9:43:00 AM
    Current time = 12/11/2018 9:42:00 AM PercentComplete = 0.00233312333333335 BarID = 5157 Bar Time = 12/11/2018 9:43:00 AM Last Chart Bar = 12/11/2018 9:43:00 AM
    In the output you have provided, the prints are showing that the script is still processing the 15:19:00 bar a few seconds after the bar has closed.
    It may be that with the large amount of prints is causing a performance hit and the script is catching up.

    From the help guide:
    "Warning: High frequency of Print() method calls can represent a performance hit on your PC. Please see the NinjaScript section of the Performance Tips article for more information."
    https://ninjatrader.com/support/help...n-us/print.htm

    If you only print the first tick of the bar and not for every tick, are you finding the delay is still present?


    Also, is your PC Clock in sync with internet time to the second?

    Compare your PC Clock with https://www.time.gov/

    If you are not in sync:
    • Shutdown NinjaTrader
    • Right-click the clock in the lower right corner of your desktop -> Select Adjust date/time
    • If you are using Windows 10, click 'Additional date, time, & regional settings' -> then click 'Set the time and date'
    • Click on Internet Time tab
    • In the Server: drop-down select time.nist.gov
    • Click Update
    • If the message that appears says successful your PC clock should now be updated
      If not, select a different server from the Server: drop-down and try again (repeat until one of the servers is successful)
    • Restart NinjaTrader
    • Connect to a data feed, then right-click the chart and select Reload All Historical Data
    http://mintywhite.com/windows-7/7mai...t-time-how-to/
    http://www.windows10update.com/2015/...t-time-server/

    After syncing the PC clock and reducing the amount of ticks, please let me know if this has not resolved the issue.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea

      Thank you very much for the fast reply.
      1. Attached code is the one what was running for the provided printout. It does not check the condition Bars.PercentComplete < 1 (what I am not interested in) but it checks two conditions: when Bars.PercentComplete == 1 or when Bars.PercentComplete > 1. Even it will never be bigger than 1, it will still print out the values when Bars.PercentComplete == 1.
      2. Provided code is not printed until all bars on the chart are loaded and last Bars.PercentComple is set to 1 after that, so fastest way to get the printout is to load indicator on 1 minute chart (sorry, my mistake did not mention it in the first post)
      3. My time is synchronized with time.windows.com

      GmA

      Comment


        #4
        Hello GmA,

        I was not able to confirm, if you only print the first tick of the bar and not for every tick, are you finding the delay is still present?

        You can print in real-time only by including
        if (State != State.Realtime)
        return;

        To the top of OnBarUpdate().
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hello Chelsea

          I am not printing first tick of the bar. I am trying to find the last tick of the bar. On my understanding, when Bars.PercentComplete is set to 1, it means that bar is finished, but the behavior listed in the printouts shows different picture: after Bars.PercentComplete is set to 1 in some situations (not always) few more updates of that bar are taking place.
          I just would like to understand if such behavior is expected or not.

          Thank you very much in advance
          GmA

          Comment


            #6
            Hello GmA,

            I am not able to reproduce this behavior. My suspicion is that you are printing too much and this is causing a performance hit which is causing a delay.

            If you were to test printing less and no longer able to reproduce, this may give us a clearer picture of what the issue is.

            To confirm, if you reduce the prints to once per bar, are you able to reproduce the behavior?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hello Chelsea

              It is exactly the question. Code prints only once per tick and only after Bars.PercentComplete is set to 1 what should not be the case! On my understanding it should print only once or not to print at all (if the condition Bars.PercentComplete == 1 is not caught). As you can see from the printout, it is still printing.
              Let me ask my question in another way:
              If Bars.PercentComplete is set to 1 can ticks still be received by the that bar?

              Thank you very much in advance
              GmA

              Comment


                #8
                Hello GmA,

                I am not able to reproduce this behavior. When testing with that condition I am not getting any prints.

                Below is a link to a video of the test.
                https://drive.google.com/file/d/1icX...w?usp=drivesdk

                The PercentComplete never gets to 1. The highest I saw was .988.

                The code commented out is how I was testing all ticks but only printing once per bar by accumulating this to a string variable on each tick and then printing the accumulated value when IsFirstTickOfBar is true.

                This may indicate that on your end, the PC clock is not in sync or that the CPU core is under heavy resource use due to the large amount of prints.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hello Chelsea!

                  Printout is not taking place all the time. Could you please keep test program running for a hour?
                  Meanwhile, I've played with synchronization. After synchronization reset and following opening of NT8, printout occurs in approximately 5 minutes after indicator loading. With time, the number of printouts is increasing. Looks you are right and it really relates to the synchronization. Similar behavior I can see on all my computers with the difference in time (first printout occurs between 3 and 10 minutes). Therefore the next question:
                  Does it mean that to use Bars.PercentComplete I need to have high-precision clocks in the computer (I think to set automatic synchronization for very 4-5 minutes is not a good idea)?!

                  Thank you in advance
                  GmA

                  Comment


                    #10
                    Hello GmA,

                    May I confirm you followed my original instructions and compared your PC clock with time.gov?

                    If so, and these were in sync to the second, this wouldn't be the issue..
                    This was asked so that we know what to focus on..

                    May I have a screenshot or short video showing that your local PC clock is in sync with time.gov to the second, shows NInjaTrader being started after this, shows all data being reloaded, and shows that the behavior can still be reproduced?


                    May I also confirm you have started printing once per bar and the behavior is still being reproduced? (This be like the code commented out in my video that would print all ticks once per bar)
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Hello Chelsea!

                      Sorry for the delay with response. I was travelling.

                      Please find below the link to the video showing synchronization process followed by loading NT8 with Test indicator.

                      https://drive.google.com/open?id=1Pn...nE97oJv8mEPJTO

                      Please also find the code where I've added indicator startup time for the reference.
                      Code:
                      namespace NinjaTrader.NinjaScript.Indicators
                      {
                          public class Test : Indicator
                          {
                              protected override void OnStateChange()
                              {
                                  if (State == State.SetDefaults)
                                  {
                                      Description                                    = @"Indicator is used for testing purpose";
                                      Name                                        = "Test";
                                      Calculate                                    = Calculate.OnEachTick;
                                      IsOverlay                                    = true;
                                      DisplayInDataBox                            = true;
                                      DrawOnPricePanel                            = true;
                                      DrawHorizontalGridLines                        = true;
                                      DrawVerticalGridLines                        = true;
                                      PaintPriceMarkers                            = true;
                                      ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                                      IsSuspendedWhileInactive                    = true;
                                  }
                               else
                                  {
                                   if (State == State.Configure)
                                      {
                                       Print ("Current time = " + DateTime.Now + " Indicator Test is strting up");
                                      }
                                  }
                              }
                      
                              protected override void OnBarUpdate()
                              {
                                  //Add your custom indicator logic here.
                               if (BarsInProgress != 0)
                                   {
                                   return;
                                  }
                                if (CurrentBar < Bars.Count - 1)
                                   {
                                   return;
                                  }            
                               if (Bars.PercentComplete >= 1)
                                   {
                                   Print ("Current time = " + DateTime.Now + " PercentComplete = " + this.Bars.PercentComplete + " BarID = " + CurrentBar + " Bar Time = " + this.Bars.GetTime (CurrentBar) + " Last Chart Bar = " + Time[0].ToString ());
                                  }
                              }
                          }
                      }
                      If my understanding is correct, the code have to print only once when bar is completed (PercentComplete is set to 1) and the new one is going to be open. In fact it prints several times after PercentComplete is set to 1. For example, on bar 4999 it prints 4 times: first time when PercentComplete has just been set to 1 (what is normal case) and, then followed by 3 other print outs. On the video you can also see that after first PercentComplete was printed, updating of the bar continues.

                      Thank you in advance
                      GmA

                      Comment


                        #12
                        Hello GmA,

                        While the video shows you doing a time synchronization, this video does not compare the time with time.gov to show these are in sync.

                        I have seen synchronizations with windows not work in the past. Immediately after syncing the time was slow by a few seconds. Only manually changing it would make it catch up and then it would fall behind again..

                        I'm not saying this is what is happening with you, I'm saying that I was to verify that the clock is actually in sync and nothing OS or hardware related might be causing time to slip on the computer..

                        So unfortunately, you have not provided what I have requested.


                        Testing on my end, I am not able to reproduce these results. This leads me to think that something is different with our computers. The behavior I am seeing on my end is the behavior I am expecting. If a time based bar is at 100 percent completion, that bar should be closed and we should be on a new bar. If the time is off by a second (or even less), it may explain why there are a few tick updates after the bar should be closed.


                        I would like to schedule a call with you so that I may compare your clock on your behalf. Please send an email to platformsupport [at] ninjatrader [dot] com. In the email please include a link to this forum thread.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Hello Chelsea and thank you for all replies.

                          Merry Christmas
                          GmA

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Rollile, Today, 03:48 AM
                          0 responses
                          3 views
                          0 likes
                          Last Post Rollile
                          by Rollile
                           
                          Started by Timothy951, Today, 03:01 AM
                          0 responses
                          3 views
                          0 likes
                          Last Post Timothy951  
                          Started by U0000999, Today, 02:50 AM
                          0 responses
                          1 view
                          0 likes
                          Last Post U0000999  
                          Started by Hiromichi, Today, 02:33 AM
                          0 responses
                          2 views
                          0 likes
                          Last Post Hiromichi  
                          Started by johnnybegoode, Yesterday, 07:15 PM
                          0 responses
                          4 views
                          0 likes
                          Last Post johnnybegoode  
                          Working...
                          X