Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bug?: Optimization of Multi-timeframe strategies fails with an error

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

    Bug?: Optimization of Multi-timeframe strategies fails with an error

    Hi NT folks!

    I'm trying to run Optimization (using Default and Genetic optimizer) of a simple multi timeframe strategy that I got by converting SampleMultiTimeFrame strategy to optimizable by adding parameters for slow/fast period (attached) and it fails with an error.

    Running backtest on this strategy works fine.

    Steps to reproduce (NT 8.0.1.0 64-bit):
    1. Strategy Analyzer
    2. Backtest Type - Optimization
    3. Optimizer - Default or Genetic
    4. Select MyMultiTimeFrame (attached)
    5. set Fast to 2-5, Slow to 5-50
    6. configure some instrument and date range
    7. hit Run button

    Current behavior:
    1. Error message in print window:
    Code:
    Strategy 'MyMultiTimeFrame': Error on calling 'OnBarUpdate' method on bar 20: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
    2. Investigating exception details shows:
    Code:
    ================ EXCEPTION ==================
    'barsAgo' needed to be between 0 and -1 but was 0
    Parameter name: barsAgo
       at NinjaTrader.NinjaScript.Series`1.get_Item(Int32 barsAgo)
       at NinjaTrader.NinjaScript.NinjaScriptBase.get_Item(Int32 barsAgo)
       at NinjaTrader.NinjaScript.Strategies.MyMultiTimeFrame.OnBarUpdate() in c:\Users\luk\Documents\NinjaTrader 8\bin\Custom\Strategies\MyMultiTimeFrame.cs:line 86
    =============================================
    3. Strategy analyzer obviously shows no results and terminates immediately after start

    Thanks for investigating this, it's very important for me!
    Lukas
    Attached Files
    Last edited by lukas.h; 11-15-2016, 10:21 PM.

    #2
    Hello lukas.h, and thank you for your question.

    In addition to making sure you have enough bars for BarsRequiredToTrade, if you are passing a BarsArray member to an indicator, you also have to check its BarsRequiredToPlot. I have annotated a copy of your source and attached it to this reply with some changes from this page of the help guide documentation inside your code.

    http://ninjatrader.com/support/helpG...nstruments.htm

    Please let us know if there are any other ways we can help.
    Attached Files
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Hi Jessica!

      I tried your modified version and it shows the same error. I also tried to tweak it a bit and modified the indicators to EMA (they don't have any requirement for required bars). And it's still failing even when I set BarsRequiredToPlot to some ridiculously high number as 100.

      The error says:
      'barsAgo' needed to be between 0 and -1 but was 0
      Which sounds weird and looks like the bars were not even loaded.

      Also I want to emphasize that:
      Backtest of this strategy runs fine.
      Which means there's probably no problem with the strategy itself.

      btw: is it possible to download the RC version somewhere? Because I think although I've done some changes in my code, this started to appear after I installed the 8.0.1 final release.

      Thanks!
      Lukas
      Last edited by lukas.h; 11-16-2016, 08:16 AM.

      Comment


        #4
        Thank you for mentioning backtesting works correctly, I had overlooked something when I put that strategy together. Adding this line made the attached strategy work outside of backtesting on my end.

        Code:
        BarsRequiredToPlot = Math.Max(BarsRequiredToPlot, Math.Max(smaSlowB0.BarsRequiredToPlot, smaFastB0.BarsRequiredToPlot));
        Originally posted by lukas.h View Post
        btw: is it possible to download the RC version somewhere? Because I think although I've done some changes in my code, this started to appear after I installed the 8.0.1 final release.

        Thanks!
        Lukas
        Previous versions of NinjaTrader are no longer available for download through the help guide.
        Attached Files
        Jessica P.NinjaTrader Customer Service

        Comment


          #5
          This might be helpful

          If been having the exact same behaviour. No errors when backtesting, only when optimizing. I'm also working with a multitimeframe strategy and working with an indicator (SMA) that uses the secondary dataserie.

          After a couple of hours of debugging, I found that the solution was to initialize the indicators in the State.DataLoaded block like:

          else if (State == State.DataLoaded)
          {
          SMA_SLEEPKABEL = SMA(BarsArray[1], SMA_sleepkabel);
          SMA_KORT = SMA(BarsArray[1], SMA_kort);
          SMA_LANG = SMA(BarsArray[1], SMA_lang);
          }

          Initializing the indicator anywhere else would result in an error when optimizing like:
          Strategy 'USMarketsNEW': Error on calling 'OnBarUpdate' method on bar 5998: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by yeikson89, Today, 02:53 PM
          2 responses
          8 views
          0 likes
          Last Post yeikson89  
          Started by sdauteuil, Today, 01:06 PM
          1 response
          11 views
          0 likes
          Last Post NinjaTrader_Jim  
          Started by trumpy, 03-09-2017, 02:11 PM
          30 responses
          3,224 views
          0 likes
          Last Post foxthorn  
          Started by shani77, Today, 09:58 AM
          1 response
          22 views
          0 likes
          Last Post NinjaTrader_Eleanore  
          Started by cjanau, Yesterday, 11:07 AM
          1 response
          31 views
          0 likes
          Last Post NinjaTrader_ThomasC  
          Working...
          X