Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Counter intuitive time stamps

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

    #31
    Hi Josh,

    just to make sure that I understood everything, I have modified the default pivot indicator of NinjaTrader. Modifications are lines 120, 140, 331 and 337 (comments added).

    Could you confirm that the code works correctly?
    Attached Files

    Comment


      #32
      Harry,

      Quick glance over looks like you used it correctly. I cannot guarantee you the code changes definitively work because I have not extensively tested it, but I do not suspect issues.
      Josh P.NinjaTrader Customer Service

      Comment


        #33
        Thanks for your answer, tested here, seems to work.

        Originally posted by NinjaTrader_Josh View Post
        Harry,

        Quick glance over looks like you used it correctly. I cannot guarantee you the code changes definitively work because I have not extensively tested it, but I do not suspect issues.

        Comment


          #34
          Problem with CurrentBar in PlotOverride

          Hi Josh,

          used the code snippets as you suggested, and at first glance it seemed to work, but then I ran into problems, see logs attached. Problem is that the integer diff came out negative, and the indicator plotted nothing,

          Code:
          int index = CurrentBar - Math.Min(Bars.Count - 1, this.LastBarIndexPainted);
          Bars.Session.GetNextBeginEnd(Bars, index, out lastBarSessionBegin, out lastBarSessionEnd);            
          Print(""+ index +", " + CurrentBar + ", " + this.LastBarIndexPainted );
          Print(""+ index +", " + CurrentBar + ", " + (Bars.Count-1) );
          which showed:

          CurrentBar = 1
          LastBarIndexPainted = 9460
          Index = CurrentBar - LastBarIndexPainted = -9459;

          Bars.Session.GetNextBeginEnd() did not accept a negative value for barsAgo. which created the error message. So the real problem here is that CurrentBar should have returned a value of 9461, but returned a value of 1 within PlotOverride.

          Excerpt from output file (repeated adding of indicator via F5

          1, 9461, 9460 correct for (index, CurrentBar, this.LastBarIndexPainted)
          1, 9461, 12534 correct for (index, CurrentBar, Bars.Count-1) // this is required for non-equidistant spacing
          -9459, 1, 9460 false for (index, CurrentBar, this.LastBarIndexPainted)
          -9459, 1, 12534 false for (index, CurrentBar, Bars.Count-1)
          1, 9461, 9460
          1, 9461, 12534
          Attached Files
          Last edited by Harry; 05-23-2011, 06:31 PM.

          Comment


            #35
            Harry,

            Where is your chart scrolled to? I am not following your comment about Bars.Count required for non-equidistant charts. I will need information on how exactly you have your chart setup and when exactly you get which prints. Multi-series charts? Thank you.
            Josh P.NinjaTrader Customer Service

            Comment


              #36
              Originally posted by NinjaTrader_Josh View Post
              Harry,

              Where is your chart scrolled to? I am not following your comment about Bars.Count required for non-equidistant charts. I will need information on how exactly you have your chart setup and when exactly you get which prints. Multi-series charts? Thank you.
              Hi Josh,

              I have observed the exceptions with both multi-series charts and single series charts. The exceptions are not related to Non-Equidistant Spacing, but simply to CurrentBar returning negative values in PlotOverride().

              To observe the problem, you only need to put the two attached indicators (anaPivotsDailyV32 and anaPivotsDailyV32b) on a chart, best use a multi-series chart and add them to the upper and lower panel. Then toggle between instruments until an exception is thrown.

              The exception is caused

              -> by lines 1341+1342 (anaPivotsDailyV32)
              -> by lines 1342-1345 (anaPivotsDailyV32b)

              anaPivotsDailyV33 does not throw any exceptions, as I used the old signature of GetNextBeginEnd() in Plot() Override. So the immediate problem is solved for me now, when I use the new signature in OnBarUpdate() and the old signature in Plot().

              I could only demonstrate with inserting Print() instructions that the problem is caused by CurrentBar taking negative values, so it could be another serious NinjaTrader bug.
              Attached Files

              Comment


                #37
                Harry,

                Let's try this. Can you run this script and see if you ever run into CurrentBar = 1 besides when you are on the very beginning of the chart? I have not been able to achieve that with this 100% basic setup. If we are able to establish this base scenario than I would suspect there to be something up with something in the Plot() logic you used on top of this basic setup causing the issue. That would be where we would need to look next.
                Attached Files
                Josh P.NinjaTrader Customer Service

                Comment


                  #38
                  i ran into similar problem. Let me cut long problem in short , i am seeking correct use of

                  Code:
                  this.LastBarIndexPainted
                  when i have more than one data series.


                  say , in my indicator i Add a data series like

                  Code:
                  protected override void Initialize()
                          {
                              Overlay				= true;
                  	    Add(PeriodType.Minute,15);
                          }
                  This indi is applied on 5 minute single series chart. Now following code works fine for primary data series ( that is 5 minute )

                  Code:
                  if(BarsInProgress == 0)
                  			{
                  			rmb_index0 = CurrentBars[0] - this.LastBarIndexPainted;
                  			Print(rmb_index0);
                  			}
                  now how can i get correct values for added series ( 15 minute ) ? following code returns wrong and negative values as this.LastBarIndexPainted references primary data series.

                  Code:
                  if(BarsInProgress == 1)
                  			{
                  			rmb_index1 = CurrentBars[1] - this.LastBarIndexPainted;
                  			Print(rmb_index1);
                  			}
                  Devdas
                  NinjaTrader Ecosystem Vendor - Devdas

                  Comment


                    #39
                    Hello devdas,
                    Yes, LastBarIndexPainted will refer to the primary instrument only.

                    You may refer to the unsupported ChartControl.LastBarTimePainted (which returns a DateTime) and then further custom code it to get the correct bar number using the GetBar method.
                    JoydeepNinjaTrader Customer Service

                    Comment


                      #40
                      Hi Joydeep,

                      i think this is deprecated now.

                      code

                      Code:
                      Print(this.ChartControl.LastBarTimePainted.ToString());

                      is returning "1/1/1800 12:00:00 AM" for every bar.

                      Hope im not doing anything wrong.
                      Can you check at your end or suggest correct snippets for this.
                      Devdas
                      NinjaTrader Ecosystem Vendor - Devdas

                      Comment


                        #41
                        Hello devdas,
                        If you try using the below code to get the datetime of the last bar painted and then calculate the bar number of the secondary data series using the GetBar method.

                        Code:
                        DateTime time = Time[Math.Min(CurrentBar, this.LastVisibleBar)];
                        JoydeepNinjaTrader Customer Service

                        Comment


                          #42
                          It worked only on single series....but with secondary added series its just printing CurrentBars[1] value of last bar on ecah bar.

                          Code:
                           if(BarsInProgress == 1)
                          			{
                          			DateTime time = Time[Math.Min(CurrentBar, this.LastVisibleBar)];
                          			Print(BarsArray[1].GetBar(time));
                          			}
                          Please confirm its not possible for more than 1 series , so i should tweak my indicator for single series.
                          Devdas
                          NinjaTrader Ecosystem Vendor - Devdas

                          Comment


                            #43
                            Hello devdas,
                            If you try the below code and then scroll back on history then what prints are you getting.

                            Code:
                            if (this.BarsInProgress != 0) return;
                            DateTime time = Time[Math.Min(CurrentBar, this.LastBarIndexPainted + 1)];
                            int i = BarsArray[1].GetBar(time);
                            Print("CurrentBars 1 = " + CurrentBars[1].ToString() + " Corrosponding secondary bar " + (CurrentBars[1] - i).ToString());
                            JoydeepNinjaTrader Customer Service

                            Comment


                              #44
                              Hi Joydeep,

                              thanx very much for your time and appreciate your help.
                              though i hv taken alternate approach with single series , but your code worked and from initial test i think i can give a try latter. I have yet to test deeply as its not very easy or may be something different behavior may result if primary data series period > secondary data series period.
                              But thanx again.
                              Devdas
                              NinjaTrader Ecosystem Vendor - Devdas

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by algospoke, 04-17-2024, 06:40 PM
                              6 responses
                              49 views
                              0 likes
                              Last Post algospoke  
                              Started by arvidvanstaey, Today, 02:19 PM
                              4 responses
                              11 views
                              0 likes
                              Last Post arvidvanstaey  
                              Started by samish18, 04-17-2024, 08:57 AM
                              16 responses
                              61 views
                              0 likes
                              Last Post samish18  
                              Started by jordanq2, Today, 03:10 PM
                              2 responses
                              10 views
                              0 likes
                              Last Post jordanq2  
                              Started by traderqz, Today, 12:06 AM
                              10 responses
                              21 views
                              0 likes
                              Last Post traderqz  
                              Working...
                              X