Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bars processed out of order?

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

    Bars processed out of order?

    I am stepping thou some code to find an error using Visual Studio and im noticing some strange behaviour. It starts by processing bars from 11/2/14 and then jumps back and starts to process bars from the day before, 10/2/14?

    Also OnBarUpdate for Day bars would be called at the open and at the close of session? If they are called on open, would they be called before min bars?

    #2
    Hello GKonheiser,

    Thanks for your post.

    Is your code doing any kind of date processing? You said that it jumps from November 2, 2014 to October 2, 2014, or do you mean from February 11, 2014 back to February 10, 2014?

    Regarding the bar processing, it would depend on your CalculateOnBarClose setting. If set to True, then each bar is only updated at the end of the bar. If set to false, you would get a tick on the Day bar at the start of the session.

    I look forward to your reply.

    Comment


      #3
      Its jumping form Feb 11 to Feb 10th. The code is behaving very strangely since today. Its been working fine and now since I started working with it on a new machine its all gone to hell.

      Could this be down to some corruption in the data? Im going to move my code back to the old PC and see if it has the same issues.

      Comment


        #4
        Hello GKonheiser,

        Thanks for your reply.

        Yes, see if you can reproduce the error and advise.

        Are you sure there isn't an issue with date processing based on the date format you are using?

        Comment


          #5
          I pretty sure its not the date format, today I introduced a bool to switch off graphics to improve performance, which shouldn't have had any other impact on the code. But where it was definitely processing the Day bars before the min bars at the start of session before, it isn't now?? So the code I had at the start of day, which is crucial to the calculations, isn't running at the correct time.

          COBC has always been set to true.

          Comment


            #6
            I just added a print statement to OnBarUpdate for Min Bars and Day Bars and the output doesnt look right,

            Min Bars2/11/2014 8:49:00 AM
            Day Bars2/10/2014 10:00:00 PM
            Min Bars2/11/2014 10:07:00 AM
            Min Bars2/11/2014 10:45:00 AM
            Min Bars2/11/2014 11:26:00 AM
            Min Bars2/11/2014 1:18:00 PM
            Min Bars2/11/2014 2:31:00 PM
            Min Bars2/11/2014 2:32:00 PM
            Min Bars2/11/2014 2:56:00 PM
            Min Bars2/11/2014 3:28:00 PM
            Min Bars2/11/2014 3:47:00 PM
            Min Bars2/11/2014 4:54:00 PM
            Min Bars2/11/2014 5:04:00 PM
            Min Bars2/11/2014 5:27:00 PM
            Min Bars2/11/2014 5:29:00 PM
            Min Bars2/11/2014 5:30:00 PM
            Min Bars2/12/2014 8:23:00 AM
            Day Bars2/11/2014 10:00:00 PM
            Min Bars2/12/2014 8:28:00 AM
            Min Bars2/12/2014 8:52:00 AM
            Min Bars2/12/2014 8:56:00 AM
            Min Bars2/12/2014 9:57:00 AM
            Min Bars2/12/2014 11:56:00 AM
            Min Bars2/12/2014 1:03:00 PM
            Min Bars2/12/2014 1:13:00 PM

            Does it?

            Comment


              #7
              Hello GKonheiser,

              Thanks for your updates.

              I understand you are running with COBC = true. This would cause the behavior you are seeing in a Multi-Time Frame situation. When set to true, the code will reference that last closed bar which was the day before in the case of the Day bars. Please see this reference in the help guide: http://www.ninjatrader.com/support/h...nstruments.htm and in particular review the section how bar data is referenced, it has a great visual between COBC=true and COBC = false.

              You may want to verify that your session template is set up correctly as your day bar is ending at 10 PM.

              Please let me know if you have any further questions.

              Comment


                #8
                Well its a mystery cos the code has been working for the last few months with COBC = True. I remember adding a print statement to OnBarUpdate for day bars and it would process at the close and first thing.

                With regards to the Printout I posted earlier, is it normal not to see a printout for every min bar if I have a print statement in OnBarUpdate for Min bars?

                Comment


                  #9
                  Hello GKonheiser,

                  Thanks for your reply.

                  With minute bars yes I would expect to see a Print statement once a minute.

                  Are you using BarsInProgress to process when the print statement is issued or is there other logic that may preclude it?

                  I look forward to your reply.
                  Last edited by NinjaTrader_PaulH; 07-07-2014, 10:57 AM.

                  Comment


                    #10
                    Originally posted by NinjaTrader_Paul View Post
                    Hello GKonheiser,

                    Thanks for your reply.

                    With minute bars yes I would expect to see a Print statement once a minute.

                    Are you using BarsInProgress to process when the print statement is issued or is there other logic that may preclude it?

                    I look forward to your reply.
                    yes, first statement after BarsInProgress for Min bars is,

                    Print("Min Bars"+ Time[0]);

                    Comment


                      #11
                      Hello GKonheiser,

                      I understand you have Day bars and minute bars, what is the base chart minute bars? Do you have any other timeFrames added?

                      Can you advise which BarsInProgress aligns with which timeFrame?

                      What is the instrument?

                      I look forward to your reply.

                      Comment


                        #12
                        Hi Paul,

                        The Instrument Im looking at it FGBL 06-14. Here is the code that sets up the time franmes,

                        protected override void Initialize()
                        {
                        Add(PeriodType.Day, 1);//Add Day Bars with index location 1
                        Add(PeriodType.Minute, 1);//Add 1 min Bars with index location 2

                        this.indPivAverage = PivotAverage(false, iPivotAverage); //
                        // this.indPivAverage.Plots[0].Pen.Width = 1;

                        // Add(this.indPivAverage); //display the pivotaverage


                        CalculateOnBarClose = true;
                        // TraceOrders = true;
                        }

                        /// <summary>
                        /// Called on each bar update event (incoming tick)
                        /// </summary>
                        protected override void OnBarUpdate()
                        {

                        if(BarsPeriod.Id == PeriodType.Minute && BarsPeriod.Value == 1)
                        {
                        mBIP = 0;
                        dBIP = 1;
                        }
                        else if(BarsPeriod.Id == PeriodType.Day && BarsPeriod.Value == 1)
                        {
                        mBIP = 2;
                        dBIP = 0;
                        }


                        else
                        {
                        mBIP = 2;
                        dBIP = 1;
                        }

                        Comment


                          #13
                          Hi Paul,

                          I figured out why the print statement isnt printing after every min. Its because the contract was not front and was very thin. But what is still bothering me is the order the Day bars are being processed(see below),

                          Min Bars2/11/2014 8:49:00 AM
                          Day Bars2/10/2014 10:00:00 PM
                          Min Bars2/11/2014 10:07:00 AM
                          Min Bars2/11/2014 10:45:00 AM
                          Min Bars2/11/2014 11:26:00 AM
                          Min Bars2/11/2014 1:18:00 PM
                          Min Bars2/11/2014 2:31:00 PM
                          Min Bars2/11/2014 2:32:00 PM
                          Min Bars2/11/2014 2:56:00 PM
                          Min Bars2/11/2014 3:28:00 PM
                          Min Bars2/11/2014 3:47:00 PM
                          Min Bars2/11/2014 4:54:00 PM
                          Min Bars2/11/2014 5:04:00 PM
                          Min Bars2/11/2014 5:27:00 PM
                          Min Bars2/11/2014 5:29:00 PM
                          Min Bars2/11/2014 5:30:00 PM
                          Min Bars2/12/2014 8:23:00 AM
                          Day Bars2/11/2014 10:00:00 PM
                          Min Bars2/12/2014 8:28:00 AM
                          Min Bars2/12/2014 8:52:00 AM
                          Min Bars2/12/2014 8:56:00 AM
                          Min Bars2/12/2014 9:57:00 AM
                          Min Bars2/12/2014 11:56:00 AM
                          Min Bars2/12/2014 1:03:00 PM

                          Comment


                            #14
                            Hello GKonheiser,

                            Thanks for your reply and code snippet.

                            It looks like you have 3 time frames. The base chart (not identified in your code), adding a 1 day time frame and adding a 1 minute time frame. What this means is that you have 3 BarsArrays in this strategy. To ensure you are addressing them correctly you need to use BarsInProgress. Each time frame will have a different BarsInProgress value.

                            BarsInProgress == 0, Base Chart time Frame (not identified)

                            BarsInProgress == 1, Day time frame

                            BarsInProgress == 2, minute time frame

                            Here is a link to using BarsInProgress http://www.ninjatrader.com/support/h...inprogress.htm

                            In your logic, you will want to refer to these different BarsInProgress when you want your logic to be executed according to which time Frame has just issued the OnBarUpdate. In other words, a Tic in any time frame can issue the OnBarUpdate. If you have logic that only operates when the 1 minute bar updates then you would use BarsInProgress == 2 so that when OnBarUpdate occurs, your logic would verify that the tic came from the 1 minute bar.

                            Code:
                            if (BarsInProgress == 2)  // if the 3rd time frame
                            
                            {
                            
                            // Execute 1 minute stuff here
                            
                            Print ("1 minute Bar time = ", Times[2][0])  // Print the current bar of the 3rd time frame (1 minute)
                            
                            }
                            Here is a link to using Times http://www.ninjatrader.com/support/h...html?times.htm

                            Please let me know if you have any further questions.

                            Comment


                              #15
                              Paul I am aware of this and am addressing the BarsInProgress correctly, if you look at the code I attached earlier you can see I have logic that assigns the BarsInProgress to mBIP or dBIP depending on what the primary bars are. But this doesn't explain what Day Bars are being processed after sometime after open, as you can see from the print statement?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              646 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              367 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              107 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              569 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              573 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X