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

Help Please - Backtest Failing

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

    Help Please - Backtest Failing

    I'm running a pairs trading strategy which gets its signals from a custom multi-series indicator (two stocks).

    In charts, I set stock A as the primary and then Add() stock B in the indicator. In charts, this works fine as the indicator is plotted as expected. I also get my Print() messages in Output.

    In the strategy, I again Add() stock B. However, in the Strategy Analyzer when stock A is selected as the target of the backtest, I get this error:

    Error on calling 'OnBarUpdate' method for indicator 'PairsIndicator' on bar 0: Object reference not set to an instance of an object.

    After the failed backtest, on the chart of stock A in strategy analyzer, trying to plot the Indicator doesn't work at all - the panel is created but nothing is plotted. This puzzles me as to why the Indicator would work in regular charting and not in backtesting. The MinBarsRequired setting is 0 in both cases.

    Any ideas to why this is the case problem would be much appreciated.

    I googled that declaring data series and in variables which are not initiated may cause this problem. This isn't the case here.

    Thanks in advance!

    ---

    Update: Also getting this error sometimes:

    Error on calling 'OnBarUpdate' method for indicator 'PairsIndicator' on bar 0: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

    I've looked through the code and still can't find anything. Surely if this was the problem, it would cause the same thing in regular charting?
    Last edited by wuilengh; 08-19-2012, 04:20 PM.

    #2
    wuilengh,

    I am happy to assist you.

    I would suggest using a Try/Catch to print to your Output Window the error that occurred. It will even tell you which line this error is coming from in many cases.

    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Thanks, I've run the catch and try block and the problem seems to be within this bit of code I have in the indicator.

      if (Bars.FirstBarOfSession)
      {
      openpricea = Opens[InstrumentB][0];
      openpriceb = Opens[InstrumentA][0];

      The error message output is this:

      8/13/2012 5:02:00 PM System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
      Parameter name: index
      at System.Collections.ArrayList.get_Item(Int32 index)
      at NinjaTrader.Data.MemBars.GetOpen(Int32 index)
      at NinjaTrader.Data.Bars.GetOpen(Int32 index)
      at NinjaTrader.Indicator.DataSeriesHelper.get_Item(In t32 barsAgo)
      at NinjaTrader.Indicator.VXXPremiumDiscount.OnBarUpda te()

      Note that I'm living 12 hours away from EST so 5:02 PM is actually 5:02 AM premarket. I'm thinking that premarket data is causing the problem. However, under the backtest settings I've set the session template to "US Equities RTH" (just as I usually do in charts) and even the chart displayed in Strategy Analyzer is from 9:30 AM - 4:00 PM (9:30 PM - 4:00 AM in my case).

      How is the indicator receiving data out of the session template when it's not even displayed and how can I remedy this?

      Thanks again.

      Comment


        #4
        Solved by going into Instrument Manager and switching the Session Templates for Stock B to US Equities RTH.

        For some reason Charting assumes this for Stock B given that Stock A is set to US Equities RTH. Backtesting doesn't for some reason.

        Thanks again!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by DustyContrer, Today, 04:02 AM
        0 responses
        3 views
        0 likes
        Last Post DustyContrer  
        Started by ETFVoyageur, Today, 02:15 AM
        0 responses
        11 views
        0 likes
        Last Post ETFVoyageur  
        Started by Board game geek, Today, 01:34 AM
        0 responses
        9 views
        0 likes
        Last Post Board game geek  
        Started by morrnel, 05-12-2024, 06:07 PM
        3 responses
        42 views
        0 likes
        Last Post wzgy0920  
        Started by FishTrade, Yesterday, 11:11 PM
        0 responses
        7 views
        0 likes
        Last Post FishTrade  
        Working...
        X