Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator issue during playback connection

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

    #16
    Hello ZenYoda,

    It would just be guessing unless you can identify the specific line of code causing the error by adding debugging prints or commenting out code until the error stops and uncommenting code until the error returns.

    Note, that string.Format(), Draw method calls, Series, array, list, and other collection indexes can all cause this error.

    The fact this occurs only after bar 980 would likely suggest the line of code is within a conditional logic block.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #17
      Hi Chelsea,

      Thanks again for your patience. I managed to debug and narrow down the errors during playback, I've also changed / swapped some indicators. I'm using the NQ 5min candles series. The only error I'm getting now is related to onBarUpdate of an indicator used by strategy, causing later an error with OnBarUpdate of the strategy. The indicator is SuperTrend, I believe you are the author, which would simplify the discussion. Bottom line, the final error scenario is now as follows:
      1. Strategy is loaded and playback is initiated.
      2. After many bars, I get the following error: "Indicator 'Supertrend': Error on calling 'OnBarUpdate' method on bar 929: You are accessing an index..."
      3. The Indicator is then disabled following the error and not shown anymore on the chart.
      4. The strategy then calls the indicator (that is disabled) and causes an error in OnBarUpdate: " Strategy 'xxxx': Error on calling 'OnBarUpdate' method on bar 930: Object reference not set to an instance of an object.
      5. I've added prints to the Indicator to print the current bar, High[0], Low[0], Input[0], Default[0], then added separate prints (at the bottom, after checking CurrentBar >1) for Default[1] and Input[1]:
      Code:
      protected override void OnBarUpdate()
      {
      
      if (IsFirstTickOfBar)
      
      {
      barHighValue = double.MinValue;
      barLowValue = double.MaxValue;
      }
      
      // calculate the bar high and low when another indicator is input series
      
      barHighValue = (Input is PriceSeries) ? High[0] : Math.Max(barHighValue, Input[0]);
      barLowValue = (Input is PriceSeries) ? Low[0] : Math.Min(barLowValue, Input[0]);
      
      Print (CurrentBar + " - " + High[0] + " - " + Low[0] + " - " + Input[0] + " - " + Default[0]);
      
      // calculate the ATR, but allowing for another indicator as an input series
      if (CurrentBar == 0)
      atrSeries[0] = barHighValue - barLowValue;
      else
      {
      double close1 = Input is PriceSeries ? Close[1] : Input[1];
      double trueRange = Math.Max(Math.Abs(barLowValue - close1), Math.Max(barHighValue - barLowValue, Math.Abs(barHighValue - close1)));
      atrSeries[0] = ((Math.Min(CurrentBar + 1, ATRPeriod) - 1 ) * atrSeries[1] + trueRange) / Math.Min(CurrentBar + 1, ATRPeriod);
      }
      
      // dis:= a2 * ATR(a1);
      // bTop:= MP() + dis;
      // bBot:= MP() - dis;
      topValue = ((barHighValue + barLowValue) / 2) + (ATRMultiplier * atrSeries[0]);
      bottomValue = ((barHighValue + barLowValue) / 2) - (ATRMultiplier * atrSeries[0]);
      if (CurrentBar < 2)
      return;
      
      Print (CurrentBar + " - " + Default[1]);
      Print (CurrentBar + " - " + Input[1]);​
      Below is an extract of the output I got from the prints, which shows that on each bar there are 3 lines of prints, except on bar 929 there are 2, the last one related to Input[1] did not print and caused the error as the error occurred after printing Default[1].

      How can Input[1] not exist on bar 929 while it existed on previous bars?

      Why always Default[0] is 0 and Default[1] has a value? (maybe not relevant to the error but I'm curious).

      925 - 17900.25 - 17881.5 - 17889 - 0
      925 - 17874.9159739789
      925 - 17895
      926 - 17895.25 - 17873 - 17876.5 - 0
      926 - 17874.9159739789
      926 - 17889
      927 - 17887.5 - 17872 - 17877 - 0
      927 - 17874.9159739789
      927 - 17876.5
      928 - 17879.5 - 17866 - 17867.5 - 0
      928 - 17874.9159739789
      928 - 17877
      929 - 17885.25 - 17846.25 - 17881.75 - 0
      929 - 17908.3254052523
      Indicator 'Supertrend': Error on calling 'OnBarUpdate' method on bar 929: 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.
      Strategy 'xxxx': Error on calling 'OnBarUpdate' method on bar 930: Object reference not set to an instance of an object.
      Disabling NinjaScript strategy 'xxxx'
      Last edited by ZenYoda; 07-04-2024, 01:37 PM.

      Comment


        #18
        Hello ZenYoda,

        Input is the input series if another indicator is used as the Input series or the Close if another indicator is not used as the input series.
        Default is the indicators plot.

        Input[1] being an invalid index would be unexpected, and this would be coming from the source input series.

        I wasn't able to reproduce. Attached is a test script.
        SuperTrendTest_NT8.zip
        Below is a link to a video.


        Are you able to reproduce with the provided test script?

        Is the indicator being called on every bar?
        Are you adding the indicator to the chart with AddChartIndicator()?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #19
          Hello Chelsea;

          I ran the test script and there were no issues. I ran both scripts (yours and mine) together in same chart window on playback. Mine had the same issue at bar 926 but this time from the SMA indicator which got disabled for the same reason, while your script kept running smoothly ( I renamed my Supertrend Indicator in order not to have conflict).

          As for your questions:
          • The indicator is called on every bar from OnBArUpdate. Series is NQ 5min.
          • The indicator is added using AddChartIndicator().
          The strategy uses calculate.OnBarClose. However there is some code for trail stop logic running under onMarketData, but this doesn't use or call the super trend. The Supertrend and the other indicators (like the SMA) are only used as entry filters, calculated using onBarUpdate.

          So the behavior of my script is basically having an error on the indicator which disables it, and then triggers the strategy to have an error calling the indicator.

          Here is the output of both scripts running in parallel. The errors are from my script.

          4/16/2024 7:30:00 AM | 17833.1263622508
          4/16/2024 7:35:00 AM | 17836.1387260258
          4/16/2024 7:40:00 AM | 17847.2123534232
          4/16/2024 7:45:00 AM | 17847.2123534232
          4/16/2024 7:50:00 AM | 17848.5957562728
          4/16/2024 7:55:00 AM | 17861.5861806455
          4/16/2024 8:00:00 AM | 17863.715062581
          4/16/2024 8:05:00 AM | 17863.715062581
          4/16/2024 8:10:00 AM | 17863.715062581
          4/16/2024 8:15:00 AM | 17863.715062581
          4/16/2024 8:20:00 AM | 17863.715062581
          4/16/2024 8:25:00 AM | 17863.715062581
          4/16/2024 8:30:00 AM | 17863.715062581
          4/16/2024 8:35:00 AM | 17863.715062581
          4/16/2024 8:40:00 AM | 17863.715062581
          4/16/2024 8:45:00 AM | 17863.715062581
          4/16/2024 8:50:00 AM | 17863.715062581
          4/16/2024 8:55:00 AM | 17863.715062581
          4/16/2024 9:00:00 AM | 17863.715062581
          4/16/2024 9:05:00 AM | 17863.715062581
          4/16/2024 9:10:00 AM | 17863.715062581
          4/16/2024 9:15:00 AM | 17863.715062581
          4/16/2024 9:20:00 AM | 17863.715062581
          4/16/2024 9:25:00 AM | 17863.715062581
          Indicator 'SMA': Error on calling 'OnBarUpdate' method on bar 927: 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.
          4/16/2024 9:30:00 AM | 17863.715062581
          4/16/2024 9:35:00 AM | 17863.715062581
          4/16/2024 9:40:00 AM | 17931.9847553514
          Strategy 'xxxx': Error on calling 'OnBarUpdate' method on bar 930: Object reference not set to an instance of an object.
          Disabling NinjaScript strategy 'xxxx'
          4/16/2024 9:45:00 AM | 17931.9847553514
          4/16/2024 9:50:00 AM | 17922.5189018346
          4/16/2024 9:55:00 AM | 17922.5189018346
          4/16/2024 10:00:00 AM | 17922.5189018346
          4/16/2024 10:05:00 AM | 17922.5189018346
          4/16/2024 10:10:00 AM | 17922.5189018346
          4/16/2024 10:15:00 AM | 17922.5189018346
          4/16/2024 10:20:00 AM | 17922.5189018346
          4/16/2024 10:25:00 AM | 17922.5189018346
          4/16/2024 10:30:00 AM | 17922.5189018346
          4/16/2024 10:35:00 AM | 17922.5189018346

          Comment


            #20
            Hello ZenYoda,

            If the test script I've provided is not causing an error I would suspect something about the input series in your script might be where the issue is coming from.

            Are you using a custom series or another indicator as the input series?

            Try reducing the code to just the few lines necessary to reproduce. I recommend creating a copy of the script and reducing the copy.

            What is the specific code necessary to reproduce?
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            65 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            41 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            23 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            26 views
            0 likes
            Last Post TheRealMorford  
            Started by Mindset, 02-28-2026, 06:16 AM
            0 responses
            52 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Working...
            X