Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unable to load Range data into 1 minute Heiken Ashi

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

    Unable to load Range data into 1 minute Heiken Ashi

    Dear Support

    I have an indicator making calculation in 1 min Heiken Ashi, however, i want to add Range (4) data
    When i do this i get error

    Indicator '': Error on calling 'OnBarUpdate' method on bar 0: 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.

    I have done different things, i added

    protected override void OnBarUpdate()
    {

    if (CurrentBar < BarsRequiredToTrade || CurrentBar < BarsRequiredToPlot || CurrentBars[0] < 1 || CurrentBars[1] < 1 || CurrentBars[2] < 1)
    return;

    OnBarUpdate() will be called on incoming tick events on all Bars objects added to the strategy
    We only want to process events on our primary Bars object (index = 0) which is set when adding
    the strategy to a chart
    if (BarsInProgress != 0)
    return;

    .
    .
    .
    . rest of code

    how do i prevent this error? can you help?

    Thanks

    #2
    Hello jimmy_NT,

    To confirm, you have called AddDataSeries() twice, for the CurrentBars[2], is this correct?

    What specific code is causing the error?

    Can you print CurrentBars[2] by itself without an error?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea

      this is the code

      else if (State == State.Configure)
      {AddDataSeries("MES 06-22", Data.BarsPeriodType.Range, 4, Data.MarketDataType.Last);}

      else if (State == State.DataLoaded)
      {
      Stochastics1 = Stochastics(Close, 4, 28, 7); //4,26,26
      rsi = RSI(Inputs[0], Period, 3);
      EMA200 = EMA(200);
      EMA100 = EMA(100);
      EMA50 = EMA(50);
      EMA20 = EMA(20);
      MACD1 = MACD(MACDFast,MACDSlow,MACDSmooth);

      //Range 4 EMAs
      EMA20_Range = EMA(BarsArray[1], 20);
      EMA50_Range = EMA(BarsArray[1], 50);
      EMA100_Range = EMA(BarsArray[1], 100);
      EMA200_Range = EMA(BarsArray[1], 200);
      }

      AND i did

      if (CurrentBar < BarsRequiredToTrade || CurrentBar < BarsRequiredToPlot || CurrentBars[0] < 1 || CurrentBars[1] < 1 || CurrentBars[2] < 1)
      return;

      // OnBarUpdate() will be called on incoming tick events on all Bars objects added to the strategy
      // We only want to process events on our primary Bars object (index = 0) which is set when adding
      // the strategy to a chart
      if (BarsInProgress != 0)
      return;

      Thanks

      Comment


        #4
        Hello jimmy_NT,

        This code would cause an error.

        CurrentBars[2] doesn't exist. AddDataSeries has only been called once. Were you intending to add another data series?
        Last edited by NinjaTrader_ChelseaB; 06-07-2022, 07:35 AM.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thanks i removed it and is working now,

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by CarlTrading, 03-31-2026, 09:41 PM
          1 response
          45 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 04-01-2026, 02:41 AM
          0 responses
          21 views
          0 likes
          Last Post CarlTrading  
          Started by CaptainJack, 03-31-2026, 11:44 PM
          0 responses
          31 views
          1 like
          Last Post CaptainJack  
          Started by CarlTrading, 03-30-2026, 11:51 AM
          0 responses
          50 views
          0 likes
          Last Post CarlTrading  
          Started by CarlTrading, 03-30-2026, 11:48 AM
          0 responses
          42 views
          0 likes
          Last Post CarlTrading  
          Working...
          X