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 Hwop38, 05-04-2026, 07:02 PM
      0 responses
      152 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Started by CaptainJack, 04-24-2026, 11:07 PM
      0 responses
      305 views
      0 likes
      Last Post CaptainJack  
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      244 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      345 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      176 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Working...
      X