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

Adding Daily DataSeries Disables Backtest Triggering

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

    Adding Daily DataSeries Disables Backtest Triggering

    I noticed my simple strategy wouldn't trigger any backtesting trades unless I commented out the two Daily dataseries which were added to my strategy. My backtesting strategy is on a 5m bar chart.

    I have a multi-timeframe/multi-instrument strategy which I still need to debug, but for now the trade logic is a just a simple 10 and 25 period moving average crossover of the primary dataseries (5m QQQ). No logic is called from the secondary data series or longer timeframes.

    I noticed after I increased the primary dataseries "days to load" to 150 days, the backtesting trades then trigger and get marked on the chart.

    Why do I need 150 days of 5 minute data loaded just because I added the daily timeseries? How does NT know how much dataseries to load for the other added timeframes/instruments or can I set the loads for these too? What do I need to know?

    Here's what my adds look like...

    Code:
     // Add Multi-Timeframes/Multi-Instruments
     // QQQ
    Add("QQQ",PeriodType.Minute,5); // BarsArray(1) = QQQ, 5m bars
    Add("QQQ",PeriodType.Minute,10); // BarsArray(2) = QQQ, 10m bars
    Add("QQQ",PeriodType.Minute,30); // BarsArray(3) = QQQ, 30m bars
    Add("QQQ",PeriodType.Minute,60); // BarsArray(4) = QQQ, 60m bars
    Add("QQQ",PeriodType.Day,1);     // BarsArray(5) = QQQ, Daily bars
    // COMP
    Add("^COMP",PeriodType.Minute,5); // BarsArray(6) = COMP, 5m bars
    Add("^COMP",PeriodType.Minute,60);// BarsArray(7) = COMP, 60m bars
    Add("^COMP",PeriodType.Day,1);    // BarsArray(8) = COMP, Daily bars
    // VXN
    Add("^VXN",PeriodType.Minute,5);  // BarsArray(9) = VXN, 5m bars

    #2
    well you do have Daily charts as well, so I'm certain you're going some type of distance to see how far it is. It's either built into your strategy or as one of the parameters that you're able to change up.

    No clue, since no more of your code on here, but check for BarsRequiredToTrade and see what you have it set to.

    Also, is this on NT7? That doesn't look like Array language for C#, unless Ninja Trader just allows for method creations without establishing them as new - as in a built in work around... Those actually confuse me more, so either way glad NT8 is moving more towards an actual programming language type =)

    Comment


      #3
      Hello borland,

      Thanks for your post.

      If you are setting the BarsRequired in the strategy http://ninjatrader.com/support/helpG...srequired2.htm or you are setting it in the user interface panel when you apply the strategy (found in the "General" section as "Min bars required"). These two apply globally to all data series in the strategy.

      If you are not referencing or using the daily bars, why are you adding them? If indeed you are referencing/using them then you would want to ensure that you have an adequate number of bars loaded for each data series. Another way to approach is to use a CurrentBars[n] check where you ensure than enough bars are loaded for each added dataseries before processing, for example:

      if (CurrentBars[0] < 25 || CurrentBars[1] < 10 || CurrentBars[3] < 5.....CurrentBars[n] < 1) return; // do not process anything until all data series have minimum bars needed for each dataseries.
      Paul H.NinjaTrader Customer Service

      Comment


        #4
        Thanks for the help Paul,

        Are you saying I need to set the “Min Bars Required” for the longest timeframe (e.g., Daily) and indicator lookback period (e.g., 200 days) ? If I’m loading the strategy on a 5 minute chart and my trading logic uses a Daily 200 period EMA, then I need to count the number of 5 minute bars for 200 days, then set the “Min Bars Required” to that amount? Then with this setting, trading won’t trigger until the current bar has reached this count? Is that right?

        The reason I had added the daily BarsArray[] is that my trading logic will eventually use that. I’m porting my trading logic from another trading platform. The strategy trades off of a 5 minute chart, but adjusts for changing market condition determined by longer timeframes. The logic adapts based on intermediate and longer timeframes up to 200 daily EMA of the Nasdaq composite. First, I need to pre-test portions of the ported trade logic before trying to run it all at once.

        Why would I need to check for CurrentBars[] if there is a setting “Min Bars Required”?

        This seems a little awkward to me as I’m coming from a platform that loaded enough historical data for what was needed to calculate what the program logic calls for in order to calculate what the indicator settings are asking for in the script.

        Comment


          #5
          Hello borland,

          Thanks for your reply.

          Two points to keep in mind here, 1) Strategy will start on the first bar which is the the farthest datetime and processes the bars in that order (left to right time-wise if you will). 2) Using a 200 period moving average will require at a minimum, 200 days of data to calculate on to be correct (others would argue that even more are needed). If you access the 200 before 200 days have been processed the value will certainly be less correct than if you wait 200 days.

          The reason for CurrentBars or Min Bars Required is that in some MTF or MTS cases you might be using time bars which will have a known number verses non time based bars which will have a variable number of bars in a given time period.

          The best resource for understanding a multi time frame strategy is the helpguide section: http://ninjatrader.com/support/helpG...nstruments.htm
          Paul H.NinjaTrader Customer Service

          Comment


            #6
            Paul,

            You didn’t address my questions directly. So, are you saying that programmatic CurrentBars() function checks does the same thing as the property setting “Min Bars Required”?

            The reason for CurrentBars or Min Bars Required is that in some MTF or MTS cases you might be using time bars which will have a known number verses non time based bars which will have a variable number of bars in a given time period.

            I don’t really don’t understand this. Can you give a code example?

            I realize that NT needs historical data in all bars of the look back period in order to calculate the correct indicator values, but is not smart enough to know when that is not the case unless told so programmatically. I’m only using standard T/A indicators with time period bars for my multi-timeframe/multi-instrument strategy.

            Comment


              #7
              Hello borland,

              Thanks for your reply.

              From the helpguide on BarsRequired (strategy): http://ninjatrader.com/support/helpG...srequired2.htm

              Definition
              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.

              Tips
              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.


              I was incorrect in advising "These two apply globally to all data series in the strategy." as it only applies to the primary series.

              Regarding a code sample, that was previously provided in the post that shows if (CurentBars[0] < .....

              In addition you may want to review: http://ninjatrader.com/support/forum...ead.php?t=3170
              Paul H.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by mmenigma, Today, 02:22 PM
              0 responses
              1 view
              0 likes
              Last Post mmenigma  
              Started by frankthearm, Today, 09:08 AM
              9 responses
              35 views
              0 likes
              Last Post NinjaTrader_Clayton  
              Started by NRITV, Today, 01:15 PM
              2 responses
              9 views
              0 likes
              Last Post NRITV
              by NRITV
               
              Started by maybeimnotrader, Yesterday, 05:46 PM
              5 responses
              26 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by quantismo, Yesterday, 05:13 PM
              2 responses
              21 views
              0 likes
              Last Post quantismo  
              Working...
              X