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 NullPointStrategies, Today, 05:17 AM
          0 responses
          52 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          130 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          70 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          44 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          48 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X