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

BarsRequired in a multi-series strategy

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

    BarsRequired in a multi-series strategy

    Hello,


    I'm backtesting a multi-series strategy with hundreds of stocks. The stocks have varying lengths of historical data. I found that OnBarUpdate() is not called until data is available for all stocks. For example, if one stock has only 3 months of data, but all other stocks have 10 years of data. The backtest would start from 3 months ago. This is the case even when I set BarsRequired to 0 or -1. This behavior is undesirable, and surprisingly, is inconsistent with the NinjarTrader documentation. The documentation below says: "In a multi-series strategy this restriction applies only for the primary Bars object." Can you please look into this inconsistency? Thank you for your help!


    --------------------------------------

    Definition of BarsRequired:

    The number of historical bars required before the strategy starts processing calls to the OnBarUpdate() method. This property is generally set via the UI when starting a strategy.

    The OnBarUpdate() method is not triggered until CurrentBar >= BarsRequired. In a multi-series strategy this restriction applies only for the primary Bars object. Should your strategy logic intertwine calculations across different Bars objects please ensure all Bars objects have met the BarsRequired requirement before proceeding. This can be done via checks on the CurrentBars array.

    Property Value
    An int value representing the number of historical bars.

    Tip:
    1. When working with a multi-series strategy, real-time bar update events for a particular Bars object are only received when that Bars object has satisfied the BarsRequired requirement. To ensure this requirement is met, please use the CurrentBars array.

    #2
    Tony, we will look into it and get back to you.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Tony, we will update the docs, what you're seeing is expected though - you will not see an OBU call until all bars objects have fullfilled their BarsRequired.
      BertrandNinjaTrader Customer Service

      Comment


        #4
        Hi Bertrand,

        Thank you very much for your reply. I was hoping the documentation was right but I did some thing wrong in my code, because what's described in the documentation is the desirable behavior of BarsRequired. The current implemetation, on the other hand, is too restrictive, and makes it impossible to backtest or live-trade most multi-series strategies.

        For example, in an equity long-short strategy, not all stocks have the same length of history. If a stock does not have the required length of history, one should be able to exclude the stock from trading by checking CurrentBars for the stock. It doesn't make sense to prevent all stocks from trading just because some stocks don't have enough data.

        I strongly urge Ninjatrader to change the implementation of BarsRequired to conform to the documentation, not the other way around. The multi-series capability is a powerful and very desirable feature of ninjatrader, but the restrictive implementation of BarsRequired renders it useless in most cases. In fact, a search on the forum found the same request submitted by another member 3 years ago, and Brett from Ninjatrader support team replied that the new feature would be added in a future version.

        Thank you for your kind consideration of enabling a powerful feature of Ninjatrader!

        Comment


          #5
          Thanks for voicing your feedback here Tony and I can follow the reasoning. I've added a vote to id #2257 tracking this request in our product management lists. I cannot give you an ETA or commitment unfortunately, but we appreciate the input as we're working hard on our next major platform update.
          BertrandNinjaTrader Customer Service

          Comment


            #6
            Hi Bertrand,

            Please add my vote to this improvement!

            It is very easy for a user to manually check that all of the instruments in a strategy satisfy the BarsRequired requirement. However, on the other side, it is a huge pain to go through instruments one by one to find the one that is causing issues. Also, as tonyz outlined below, it makes backtesting a very frustrating process when you have to track down the one instrument out of a great many that might be causing issues.

            Here is my code (I'm sure that there are more efficient ways to go about it, but this is what I came up with at least... very simple).

            Code:
            int minBars = int.MaxValue;	
            int currentInstrumentBars;
            				
            for (int instrumentIndex = 0; instrumentIndex <= numInstruments-1; instrumentIndex++)
            {
            	currentInstrumentBars = CurrentBars[instrumentIndex];
            	minBars = Math.Min(minBars,currentInstrumentBars);	// Compares the CurrentBar of each instrument to the previous MIN bars
            }
            
            if (currentInstrumentBars < MinimumBarsRequired)
            	return;
            It is incredibly frustrating to try and work with a multiple instrument strategy on stocks as things stand right now. For example, I'm running a strategy on S&P 500 stocks. Even for such a large cap index like that, there are typically 10-15 new stocks every year. When building a new strategy, I can't even describe how annoying it is to have to sort through 500-1000-2000+ stocks, just to track down the single stock that might be causing issues.

            If it helps push this through, I really think that you can put an economic impact on this. For example, I am currently using NinjaTrader to backtest my strategies, and on the whole I'm quite happy with the performance. However, in my case, it seems like it would be incredibly cumbersome to use it for live trading, due to the headaches surrounding this kind of instrument management. There are other programs and websites out there that do this sort of thing in a much simpler fashion than NinjaTrader, so right now I am backtesting in NT and just porting my finished system over to those other options. I don't think that this is ideal, either for me or for NinjaTrader, since it's a headache for me to transfer and you're losing out on the broker license.

            3 Things that would convince me to "go live" with NinjaTrader:
            1) Adding instruments needs to be far simpler.
            - Adding the list of stocks is a good function, but being able to add them in .csv format would solve a lot of headaches
            - Having to go through each stock, updating the stock description & tickers (if necessary) is pretty cumbersome

            2) Adding a list of stocks is convenient, but having to manually "clean up" their split & dividend data is needlessly complicated
            > As I've requested in another thread, having to click "Update Splits & Dividends" for each stock individually seems ridiculous, when an "Update All" button would take all of 15 mins to code

            3) Adding a new instrument to a strategy (ie, a stock with a shorter history than those already in there) shouldn't cause the strategy to stop working for the other 1,999 instruments
            - I think that most people would much prefer a Ninja Error, saying "Not enough bars for barsInProgressIndex 'X' " (that could be fixed with the above code) than to have this sort of restriction

            If you could solve these issues, you would easily win a broker license from me (And I'm sure that there must be other people out there in a similar boat, as evidenced by the threads on this forum)

            Just my $0.02...

            Comment


              #7
              kbeary33, thanks much for this comprehensive post and detailing your enhancement ideas - the points you've raised are already on our list of product feedback collected and I've made sure to add votes on your behalf in as well.

              We also appreciate the sharing of your code solution snippet for our community.
              BertrandNinjaTrader Customer Service

              Comment


                #8
                Thanks kbeary33 !

                amazing
                when i have used :
                if (CurrentBars[0] < BarsRequired || CurrentBars[1] < BarsRequired) return;
                Poor results..

                thats why i was used to do this
                if (CurrentBar < 200 ) or even more than 200, but becomes complicated when put more days to the chart.
                but with this !
                awesome

                Comment


                  #9
                  I am wondering if the problems reported in this thread are in any way related to an observation I just made:

                  When I use Add() to add indicators to a strategy, the BarsRequired setting in those indicators are ignored -- sort of. The indicators seem to be processing, but not displaying until the number of bars reaches BarsRequired in the strategy. Shouldn't the indicators be displayed with respect to BarsRequired in each indicator?

                  -A
                  Last edited by anachronist; 10-24-2014, 11:12 PM. Reason: corrected description

                  Comment


                    #10
                    Hello anachronist,

                    Thank you for your post.

                    The indicators added will use the BarsRequired of the strategy, unfortunately there is no method around this.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by pechtri, 06-22-2023, 02:31 AM
                    10 responses
                    124 views
                    0 likes
                    Last Post Leeroy_Jenkins  
                    Started by judysamnt7, 03-13-2023, 09:11 AM
                    4 responses
                    59 views
                    0 likes
                    Last Post DynamicTest  
                    Started by ScottWalsh, Yesterday, 06:52 PM
                    4 responses
                    36 views
                    0 likes
                    Last Post ScottWalsh  
                    Started by olisav57, Yesterday, 07:39 PM
                    0 responses
                    7 views
                    0 likes
                    Last Post olisav57  
                    Started by trilliantrader, Yesterday, 03:01 PM
                    2 responses
                    22 views
                    0 likes
                    Last Post helpwanted  
                    Working...
                    X