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 cmoran13, 04-16-2026, 01:02 PM
      0 responses
      51 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      31 views
      0 likes
      Last Post PaulMohn  
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      165 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      100 views
      1 like
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      160 views
      2 likes
      Last Post CaptainJack  
      Working...
      X