Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NT is changing the Input Series and allowing a -1 index thru

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

    NT is changing the Input Series and allowing a -1 index thru

    I have recently noticed a change in NT regarding an indicator I have. The change may have happened in NT 8r25. I'm not sure exactly when this issue started, but I know for years the indicator never had an issue.

    The issues are:
    #1. NT is changing the Input Series to Close. When first adding it to the chart the Input Series is correct, set to the chart Data Series like any moving average indicator. There is no code referencing Input, so the code is not changing it. See attached video.
    How can I prevent NT from changing the Input Series?

    #2. I'm guess #1 has something to do when the errors that are now happening, that didn't happen before. Also, see video for error.
    The code has checks for CurrentBar less than 0, so it appears NT is forcing a -1 currentbar through to OnBarUpdate().
    How can I prevent OnBarUpdate() from executing a -1 Currentbar?

    Code:
    protected override void OnBarUpdate()
    {
    
    if(BarsInProgress == 0 || [B]CurrentBar < 0[/B]) return;
    
    Print("BiP = "+BarsInProgress+" \t CurrentBar = "+CurrentBar.ToString().PadLeft(5));
    
    if(CurrentBars[1] > 0 && [B]CurrentBar > 0[/B])
    {
    Values[0][0] = mtfMAData[0];
    }
    The site will not allow a mp4 file to be uploaded, so I attached an image.
    thanks.
    Attached Files
    Last edited by zacharydw00; 08-31-2022, 04:43 PM.

    #2
    Hello zacharydw00,

    Thank you for your post.

    So I may better assist you, please answer the following questions:
    • What version of NinjaTrader are you using? This may be found by going to Control Center > Help > About
    • Are you able to consistently reproduce the behavior with the input series changing in the UI? What are the steps you are taking? Are you able to reproduce these steps on a different indicator, such as the EMA that comes with NinjaTrader by default?
    • What are the errors you are getting?
    If you would prefer to answer these questions as well as send the video via email, please write to scriptingsupport[AT]ninjatrader[DOT]com and reference "case # 03197419 ATTN Emily" in the subject line as well as include a link to this forum thread in the body of the email.

    I look forward to your reply.

    Comment


      #3
      Originally posted by NinjaTrader_Emily View Post
      What version of NinjaTrader are you using?.
      8.0.26.1 64-bit

      Are you able to consistently reproduce the behavior with the input series changing in the UI?
      Yes.

      What are the steps you are taking?
      1. Add the indicator to the chart.
      2. Reopen the Indicator window again, and the Input series is changed.

      Are you able to reproduce these steps on a different indicator, such as the EMA that comes with NinjaTrader by default?
      No, not that I have seen.

      [*]What are the errors you are getting?
      Indicator 'MTF Moving Average': Error on calling 'OnBarUpdate' method on bar -1: 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.

      Thanks.

      Comment


        #4
        Hello zacharydw00,

        I appreciate the information.

        After reviewing your screenshot and the code snippet you provided, I created a quick test script on my end. One thing that stood out is your screenshot shows an EMA with a period of 10. For a moving average period, there is a minimum number of bars required on the chart to calculate properly. You have the following checks in your code that will likely need to be adjusted to meet the needs of the moving average period used:

        if(BarsInProgress == 0 || CurrentBar < 0) return;
        if(CurrentBars[1] > 0 && CurrentBar > 0)

        As an example, if your EMA has a period of 10, you would need to check that the CurrentBar > 10

        Rather than checking against 0, you will need to make sure there are enough bars in the data series you are accessing. You could utilize BarsRequiredToPlot in your checks if you'd like; the default value is 20 although that may be adjusted in State.SetDefaults as needed. Here is more information about BarsRequiredToPlot:



        I suspect that after adjusting the check for CurrentBar, the error from question #2 should be resolved. I am curious to know if the issue from #1 will also be resolved along with it or if the behavior will persist.

        I look forward to hearing the results.

        Comment


          #5
          Thanks for trying to help. I did figure out issue #1.

          During State.DataLoaded
          I had something like this.
          Code:
          Series<double> [B]mtfCloses [/B]= Closes[1];  // This isn't proper code, I know.  I'm summarizing for others to learn from my mistake.
          
          switch (MAType)
          {
          case MTFMovingAverage_MAType.DEMA:
          mtfMAData = DEMA([B]mtfCloses[/B], MAPeriod);
          break;
          case MTFMovingAverage_MAType.EMA:
          mtfMAData = EMA([B]mtfCloses[/B], MAPeriod);
          break;
          ...
          It's weird that with the code above NT would change the Input Series.

          I changed the code to this, which is more correct, and both problems solved.
          Code:
          barsACount = BarsArray.Count()-1;
          
          switch (MAType)
          {
          case MTFMovingAverage_MAType.DEMA:
          mtfMAData = DEMA([B]BarsArray[barsACount][/B], MAPeriod);
          break;
          case MTFMovingAverage_MAType.EMA:
          mtfMAData = EMA([B]BarsArray[barsACount][/B], MAPeriod);
          break;
          ...

          As an example, if your EMA has a period of 10, you would need to check that the CurrentBar > 10
          I disagree because all of NT's moving averages always output a valid price value starting on bar zero. NT's code is written correctly so a minimum bar count check is not needed. I totally agree when accessing a custom MA indicator that may output invalid values until the period number of bars has calculated.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          566 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          330 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          547 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          548 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X