Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CurrentBars[] Numbers High w/Multiple Timeframes Added

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

    CurrentBars[] Numbers High w/Multiple Timeframes Added

    I wrote a Strategy script that when OnBarUpdate() is called, Prints to the Output Window, displaying the BarsInProgress number called with CurrentBars[] numbers.

    What I am seeing is high CurrentBars numbers when adding additional timeframes. This makes it difficult to set a Check within OnBarUpdate for sufficient Bars needed to calculate required indicator lookback periods used by the trade logic.

    Here's a sample of what is displayed..
    Code:
    BarsInProgress: 0,  CurrentBars[0]:  2,  CurrentBars[1]:  12991
    BarsInProgress: 1,  CurrentBars[0]:  2,  CurrentBars[1]:  12991
    BarsInProgress: 1,  CurrentBars[0]:  2,  CurrentBars[1]:  12992
    BarsInProgress: 1,  CurrentBars[0]:  2,  CurrentBars[1]:  12993
    BarsInProgress: 1,  CurrentBars[0]:  2,  CurrentBars[1]:  12994
    BarsInProgress: 1,  CurrentBars[0]:  2,  CurrentBars[1]:  12995
    BarsInProgress: 1,  CurrentBars[0]:  2,  CurrentBars[1]:  12996
    BarsInProgress: 1,  CurrentBars[0]:  2,  CurrentBars[1]:  12997
    BarsInProgress: 1,  CurrentBars[0]:  2,  CurrentBars[1]:  12998
    BarsInProgress: 1,  CurrentBars[0]:  2,  CurrentBars[1]:  12999
    BarsInProgress: 1,  CurrentBars[0]:  2,  CurrentBars[1]:  13000
    BarsInProgress: 1,  CurrentBars[0]:  2,  CurrentBars[1]:  13001
    I've attached the Strategy script and Output Window text file.

    Is there any way to ensure the CurrentBars numbers are synchronized the with other timeframes?
    Attached Files

    #2
    Hello borland,

    Thank you for writing in.

    I am not entirely sure what you mean by syncing the CurrentBars numbers together.

    It would be expected for higher time frames (such as daily bars) to have a lower CurrentBars count than lower time frames (such as minute bars) for the same period of time.

    Can you please clarify what you would like?
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      Sorry I wasn't clear.

      I should have mentioned, I was running the above strategy from a Chart with panel 1 on 5 minute bars. When I run the same strategy from the Control Center's Strategies Tab, I get more expected results, where I was expecting lower CurrentBars numbers. Here's Output Window prints when run from the Strategies Tab....

      Code:
      BarsInProgress: 0,  CurrentBars[0]:  233,  CurrentBars[1]:  233,  CurrentBars[2]:  116,  CurrentBars[3]:  38,  CurrentBars[4]:  20,  CurrentBars[5]:  2
      BarsInProgress: 1,  CurrentBars[0]:  233,  CurrentBars[1]:  233,  CurrentBars[2]:  116,  CurrentBars[3]:  38,  CurrentBars[4]:  20,  CurrentBars[5]:  2
      BarsInProgress: 2,  CurrentBars[0]:  233,  CurrentBars[1]:  233,  CurrentBars[2]:  116,  CurrentBars[3]:  38,  CurrentBars[4]:  20,  CurrentBars[5]:  2
      BarsInProgress: 3,  CurrentBars[0]:  233,  CurrentBars[1]:  233,  CurrentBars[2]:  116,  CurrentBars[3]:  38,  CurrentBars[4]:  20,  CurrentBars[5]:  2
      BarsInProgress: 4,  CurrentBars[0]:  233,  CurrentBars[1]:  233,  CurrentBars[2]:  116,  CurrentBars[3]:  38,  CurrentBars[4]:  20,  CurrentBars[5]:  2
      BarsInProgress: 0,  CurrentBars[0]:  234,  CurrentBars[1]:  234,  CurrentBars[2]:  116,  CurrentBars[3]:  38,  CurrentBars[4]:  20,  CurrentBars[5]:  2
      BarsInProgress: 1,  CurrentBars[0]:  234,  CurrentBars[1]:  234,  CurrentBars[2]:  116,  CurrentBars[3]:  38,  CurrentBars[4]:  20,  CurrentBars[5]:  2
      BarsInProgress: 0,  CurrentBars[0]:  235,  CurrentBars[1]:  235,  CurrentBars[2]:  117,  CurrentBars[3]:  38,  CurrentBars[4]:  20,  CurrentBars[5]:  2
      CurrentBars[0] is the same period as CurrentBars[1]. Notice how CurrentBars[1] number is now consistent with CurrentBars[0]. So they look to be in sync when run from the Strategies Tab.
      Attached Files
      Last edited by borland; 07-20-2016, 09:36 AM.

      Comment


        #4
        Hello borland,

        Thank you for the clarification.

        When running this strategy on a 5 minute ES 09-16 chart, I do see CurrentBars[1] match CurrentBars[0] as expected. CurrentBars[6], and CurrentBars[9] also match as expected, since they are all 5 minute timeframes.

        Please shut down NinjaTrader and follow the steps below to test this strategy on a new workspace to see if you are still seeing the same unexpected behavior on a chart.

        As a test, please take the following steps to force NinjaTrader to start without your saved workspace. You will have the option to reopen these after our tests.
        • Shut down NinjaTrader
        • Navigate to (My) Documents\NinjaTrader 7\workspaces
        • Delete the file named "_Workspaces.XML". DO NOT delete the 'workspaces' folder - only delete the '_Workspaces.XML' file within the 'workspaces' folder
        • After deleting this file, restart NinjaTrader which should startup without any workspaces.
        • Once NinjaTrader has started on just the control center, please open a new chart with no custom bar types/indicators/templates and test for issues.
        • *Please note this will not delete your workspace however the new blank workspace will be named Untitled1. If you have a workspace already named Untitled1 however you will not want to save the workspace when exiting NinjaTrader, otherwise it will overwrite it.
        • If there are no issues on this new workspace, please try opening the previous workspace by going to File--> Workspaces--> Open workspace.
        Zachary G.NinjaTrader Customer Service

        Comment


          #5
          ZacharyG,

          Following your instructions, I get consistent results on a new chart with one 5 minute Data Series. However, deleting the _Workspace XML file really didn't fix my problem or understanding.

          If on the chart, I add a second Data Series (1 Day, Days to Load - 250 days) to the primary (5 minute, Days to Load - 5 days), the high CurrentBars[] numbers return.

          The high numbers by themselves really doesn't seem to be a problem if they are really in sync with the other Data Series. That doesn't seem to be the case in my example, since additional Added time series of the same period (5 minute periods) does not have the same CurrentBars[] numbers. So, to me this looks like a bug.

          Maybe I need to Print out some Bar timestamps to see what's going on with those high counts?

          Another problem...Since the strategy I am working on will have an indicator with look back period of 200 days, I will need to set that added data Series to have a check of CurrentBars[5] > 200. It looks like from the Output Window, NT doesn't load enough daily bars to satisfy that, so the strategy will never trigger an entry.
          Last edited by borland; 07-20-2016, 11:54 AM.

          Comment


            #6
            Hello borland,

            I am not entirely clear.

            A script has no regards to other data series that you have added to a chart window. When adding data series within the script's Initialize() method, all added series is just going to follow the parameters you have set for the chart panel that you have added your script to.

            For instance, let's say that you add your script to a 5 minute chart with a days to load setting set to 5. All other series added in your script are going to be constrained to these parameters you have specified.

            As an example, I'll test your script on an ES 09-16 5 minute chart. I specify "Load data based on" CustomRange with a Start date of July 18, 2016 and an End date of July 20, 2016.

            Let's take a look at the output:

            Code:
            BarsInProgress: 0,  CurrentBars[0]:  786,  CurrentBars[1]:  786,  CurrentBars[2]:  394,  CurrentBars[3]:  132,  CurrentBars[4]:  66,  CurrentBars[5]:  2,  CurrentBars[6]:  786,  CurrentBars[7]:  66,  CurrentBars[8]:  2,  CurrentBars[9]:  786
            BarsInProgress: 1,  CurrentBars[0]:  786,  CurrentBars[1]:  786,  CurrentBars[2]:  394,  CurrentBars[3]:  132,  CurrentBars[4]:  66,  CurrentBars[5]:  2,  CurrentBars[6]:  786,  CurrentBars[7]:  66,  CurrentBars[8]:  2,  CurrentBars[9]:  786
            BarsInProgress: 2,  CurrentBars[0]:  786,  CurrentBars[1]:  786,  CurrentBars[2]:  394,  CurrentBars[3]:  132,  CurrentBars[4]:  66,  CurrentBars[5]:  2,  CurrentBars[6]:  786,  CurrentBars[7]:  66,  CurrentBars[8]:  2,  CurrentBars[9]:  786
            BarsInProgress: 3,  CurrentBars[0]:  786,  CurrentBars[1]:  786,  CurrentBars[2]:  394,  CurrentBars[3]:  132,  CurrentBars[4]:  66,  CurrentBars[5]:  2,  CurrentBars[6]:  786,  CurrentBars[7]:  66,  CurrentBars[8]:  2,  CurrentBars[9]:  786
            BarsInProgress: 4,  CurrentBars[0]:  786,  CurrentBars[1]:  786,  CurrentBars[2]:  394,  CurrentBars[3]:  132,  CurrentBars[4]:  66,  CurrentBars[5]:  2,  CurrentBars[6]:  786,  CurrentBars[7]:  66,  CurrentBars[8]:  2,  CurrentBars[9]:  786
            BarsInProgress: 5,  CurrentBars[0]:  786,  CurrentBars[1]:  786,  CurrentBars[2]:  394,  CurrentBars[3]:  132,  CurrentBars[4]:  66,  CurrentBars[5]:  2,  CurrentBars[6]:  786,  CurrentBars[7]:  66,  CurrentBars[8]:  2,  CurrentBars[9]:  786
            BarsInProgress: 6,  CurrentBars[0]:  786,  CurrentBars[1]:  786,  CurrentBars[2]:  394,  CurrentBars[3]:  132,  CurrentBars[4]:  66,  CurrentBars[5]:  2,  CurrentBars[6]:  786,  CurrentBars[7]:  66,  CurrentBars[8]:  2,  CurrentBars[9]:  786
            BarsInProgress: 7,  CurrentBars[0]:  786,  CurrentBars[1]:  786,  CurrentBars[2]:  394,  CurrentBars[3]:  132,  CurrentBars[4]:  66,  CurrentBars[5]:  2,  CurrentBars[6]:  786,  CurrentBars[7]:  66,  CurrentBars[8]:  2,  CurrentBars[9]:  786
            BarsInProgress: 8,  CurrentBars[0]:  786,  CurrentBars[1]:  786,  CurrentBars[2]:  394,  CurrentBars[3]:  132,  CurrentBars[4]:  66,  CurrentBars[5]:  2,  CurrentBars[6]:  786,  CurrentBars[7]:  66,  CurrentBars[8]:  2,  CurrentBars[9]:  786
            BarsInProgress: 9,  CurrentBars[0]:  786,  CurrentBars[1]:  786,  CurrentBars[2]:  394,  CurrentBars[3]:  132,  CurrentBars[4]:  66,  CurrentBars[5]:  2,  CurrentBars[6]:  786,  CurrentBars[7]:  66,  CurrentBars[8]:  2,  CurrentBars[9]:  786
            What do these numbers mean?

            Let's take a look at the help guide for CurrentBar: https://ninjatrader.com/support/help...currentbar.htm

            CurrentBar is a number represents the bar index that the strategy is currently evaluating over.

            You will see that higher time-frames have lower numbers and lower time-frames have higher numbers. Why is this the case? This is because more (or less) bars are required to fill that same time period.

            As we expect here, CurrentBars[0], CurrentBars[1], CurrentBars[6], and CurrentBars[9] all match because they are the same period (5 minutes). CurrentBars[2] is a smaller number because less 10 minute bars fill that same amount of time that's loaded. So on and so forth.

            Your chart will need a look back period that would contain more than 201 daily bars (as the first daily bar starts at 0).
            Zachary G.NinjaTrader Customer Service

            Comment


              #7
              Thank you ZacharyG. That may seem obvious to many, but I didn't think that was necessary.

              In my mind, I had questioned why there were no settings for how much data should be loaded with adding additional timeframes with the Add() function. Having to load that much 5 minute data seems unnecessary when it is not needed. I didn't see that as being needed in any of the reference materials dealing with multi-timeframes. Must have missed it.

              My longer term (daily) indicators are used for adjusting shorter term indicator parameters so that the strategy adapts to rally and corrections in both bull and bear markets.

              Comment


                #8
                Hello borland,

                I do want to note that NinjaTrader 8 will provide users the ability to limit the amount of data loaded by each series added in a script.



                You can see that there is an overload for AddDataSeries() that allows one to specify the amount of bars to load for that series.

                Please, let us know if we may be of further assistance.
                Zachary G.NinjaTrader Customer Service

                Comment


                  #9
                  Good to know about NT8.

                  I would like to request a related feature similar to the existing system variable BarsRequired.

                  Please consider for NT7 a system variable "DaysToLoad" so that that the parameter can be programmatically set in the Strategy script. This would help in avoiding mistakes with strategy configuration from the Strategies dialog box (Grid).
                  Last edited by borland; 07-20-2016, 01:57 PM.

                  Comment


                    #10
                    I added bar timestamps to the script and found that when I added new symbols to the Add() function, an out-of-sync condition happens with the last added symbol (BarsArray[9]). Only the last VXN data series gets out of sync, the other eight added data series stay in sync.

                    Attached is the revised ninjascript file. Output Window limits amount of data printed when chart's DaysToLoad is 200, so I comment out some prints.

                    It starts off in sync, but deviates at times, later getting back in sync, then again loosing sync. Very puzzling behavior.

                    Below is a partial list of the Output Window.


                    Code:
                    BarsInProgress: 9,  CurBars[0]:  10761, (h.m): 12:50,  CurBars[9]:  11173, (h.m): 12:50
                    BarsInProgress: 0,  CurBars[0]:  10762, (h.m): 12:55,  CurBars[9]:  11174, (h.m): 12:55
                    BarsInProgress: 1,  CurBars[0]:  10762, (h.m): 12:55,  CurBars[9]:  11174, (h.m): 12:55
                    BarsInProgress: 6,  CurBars[0]:  10762, (h.m): 12:55,  CurBars[9]:  11174, (h.m): 12:55
                    BarsInProgress: 9,  CurBars[0]:  10762, (h.m): 12:55,  CurBars[9]:  11174, (h.m): 12:55
                    BarsInProgress: 0,  CurBars[0]:  10763, (h.m): 13:0,  CurBars[9]:  11175, (h.m): 13:0
                    BarsInProgress: 1,  CurBars[0]:  10763, (h.m): 13:0,  CurBars[9]:  11175, (h.m): 13:0
                    BarsInProgress: 2,  CurBars[0]:  10763, (h.m): 13:0,  CurBars[9]:  11175, (h.m): 13:0
                    BarsInProgress: 3,  CurBars[0]:  10763, (h.m): 13:0,  CurBars[9]:  11175, (h.m): 13:0
                    BarsInProgress: 4,  CurBars[0]:  10763, (h.m): 13:0,  CurBars[9]:  11175, (h.m): 13:0
                    BarsInProgress: 5,  CurBars[0]:  10763, (h.m): 13:0,  CurBars[9]:  11175, (h.m): 13:0
                    BarsInProgress: 6,  CurBars[0]:  10763, (h.m): 13:0,  CurBars[9]:  11175, (h.m): 13:0
                    BarsInProgress: 7,  CurBars[0]:  10763, (h.m): 13:0,  CurBars[9]:  11175, (h.m): 13:0
                    BarsInProgress: 8,  CurBars[0]:  10763, (h.m): 13:0,  CurBars[9]:  11175, (h.m): 13:0
                    BarsInProgress: 9,  CurBars[0]:  10763, (h.m): 13:0,  CurBars[9]:  11175, (h.m): 13:0
                    BarsInProgress: 9,  CurBars[0]:  10763, (h.m): 13:0,  CurBars[9]:  11176, (h.m): 13:5
                    BarsInProgress: 9,  CurBars[0]:  10763, (h.m): 13:0,  CurBars[9]:  11177, (h.m): 13:10
                    BarsInProgress: 9,  CurBars[0]:  10763, (h.m): 13:0,  CurBars[9]:  11178, (h.m): 13:15
                    Attached Files

                    Comment


                      #11
                      Hello borland,

                      I would not expect the CurrentBar count over two different instruments to be the exact same even with the same time-frame.

                      It is always possible that there are less or more bars that exist over that time period for different instruments. Also, session templates that are used by each instrument can also affect the amount of bars that you would have loaded.

                      I would expect the count to match if both instruments are the same and are on the same timeframe, however.
                      Zachary G.NinjaTrader Customer Service

                      Comment


                        #12
                        I'm more concerned with the bar closing times than count to ensure that all bars are in sync. I didn't see any missing bars in the data, but I might have overlooked that.

                        It is possible that there are missing bars due to no ticks during the interval, but these are 5 minute periods. That's a long time for no activity or ticks.

                        I don't know what session templates has to do with this? Yesterday, from your comments I understood that DaysToLoad setting was for primary and all additional data series added. I'm not familiar with session templates, so I'll have to look into that.

                        Comment


                          #13
                          Hello borland,

                          Session templates affect the data that would be available to your script as well as what is displayed on the chart. Any data outside of the ranges defined by your session template would be ignored.

                          Please take a look at this help guide link for more information about the Session Manager as well as Session Templates: https://ninjatrader.com/support/help...on_manager.htm

                          If a multi-series script adds an additional Bars object that already exists on the chart, the script will use the pre-existing series instead of creating a new one to conserve memory. This includes that series' session template as applied from the chart. If the Bars object does not exist on the chart, the session template of the added Bars object will be the session template of the primary Bars object. If the primary Bars object is using the "<Use instrument settings>" session template then the additional Bars objects will use the default session templates as defined for their particular instruments in the Instrument Manager.
                          Zachary G.NinjaTrader Customer Service

                          Comment


                            #14
                            Thanks,

                            I noticed from looking at the Instrument Manager, that I have no instrument listed as "QQQ". But for index "^COMP", the session template is set to "US Equities RTH" , while for index "^VXN", the session template is set to "Default 24/7".

                            I also noticed from the Session Manager, that the session template is set to "Default 24/7", but my charts seem to be displaying "US Equities RTH".

                            So, this must be similar to DaysToLoad, in that the primary data series is the controlling which session bars are available to the trading logic. Think so?
                            Last edited by borland; 07-21-2016, 09:50 AM.

                            Comment


                              #15
                              Hello borland,

                              If a multi-series script adds an additional Bars object that already exists on the chart, the script will use the pre-existing series instead of creating a new one to conserve memory. This includes that series' session template as applied from the chart.

                              If the Bars object does not exist on the chart, the session template of the added Bars object will be the session template of the primary Bars object. However, if the primary Bars object is using the "<Use instrument settings>" session template then the additional Bars objects will use the default session templates as defined for their particular instruments in the Instrument Manager.
                              Zachary G.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by gentlebenthebear, Today, 01:30 AM
                              2 responses
                              13 views
                              0 likes
                              Last Post gentlebenthebear  
                              Started by Kaledus, Today, 01:29 PM
                              2 responses
                              8 views
                              0 likes
                              Last Post Kaledus
                              by Kaledus
                               
                              Started by frankthearm, Yesterday, 09:08 AM
                              13 responses
                              45 views
                              0 likes
                              Last Post frankthearm  
                              Started by PaulMohn, Today, 12:36 PM
                              2 responses
                              16 views
                              0 likes
                              Last Post PaulMohn  
                              Started by Conceptzx, 10-11-2022, 06:38 AM
                              2 responses
                              56 views
                              0 likes
                              Last Post PhillT
                              by PhillT
                               
                              Working...
                              X