Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CurrentBars[1] is always -1

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

    CurrentBars[1] is always -1

    I have an indicator that displays the current chart's ATR as text. I wanted to add the VIX to that as well. Here's the code:

    Code:
    AddDataSeries("VIX", BarsPeriodType.Minute, 5);
    Code:
    protected override void OnBarUpdate()
    {
        //if (BarsInProgress != 0) return;
        if(CurrentBars[0] < 20 && CurrentBars[1] < 5) return;
    
        Print("Made it here");
        //Add your custom indicator logic here.
        double atr = Math.Round(ATR(14)[0], 2);
    
        double vix = 0;
        Print(CurrentBars[1]);
        if (CurrentBars[1] > 5)
            vix = Closes[1][0];
    
        Print("Made it here 2");
        Draw.TextFixed(this, "ATR+VIX", "ATR: " + atr.ToString() + "\tVIX: " + vix.ToString(),
            TextPosition.BottomLeft,
            ChartControl.Properties.ChartText,
            ChartControl.Properties.LabelFont,
            Brushes.Transparent, Brushes.Transparent, 0);
        }
    }
    The log is showing the following:

    Code:
    Made it here
    -1
    Made it here 2
    CurrentBars[1][0] is always -1

    Not sure what I'm doing wrong.​​

    #2
    Hello, thanks for writing in. All indexes in NinjaTrader start with a carrot symbol '^' Try this for your AddDataSeries call:

    AddDataSeries("^VIX", BarsPeriodType.Minute, 5);

    Comment


      #3
      That did the trick, thanks.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      571 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
      548 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      549 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X