Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error fetching SMA numbers

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

    Error fetching SMA numbers

    Good morning

    I have an indicator with 60min primary data series and Daily as secondary data series. I have CurrentBars[1] <= BarsRequiredToPlot and BarsRequiredToPlot = 201

    I have added SMA100 = SMA(BarsArray[1], 100); for the daily 100 sma

    When I Print("100sma " + SMA100[80]); I get an Error on calling 'OnBarUpdate' method on bar 4904: 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.

    If I am requiring 201 daily bars, and asking for the 100 period SMA price 80 daily bars ago shouldn't I have enough bars? This error seems to go away if I ask it to Print("100sma " + SMA100[60]);

    Any help will be appreciated.

    Thanks,
    Ryan

    #2
    Hi Ryan, thanks for posting. You will need more bars in the secondary series to process this. Try first printing out BarsArray[1].Count. A 100 day SMA needs 100 bars to create one data point, so you need more than 200 bars in the secondary series to complete this calculation.

    Comment


      #3
      Chris,

      Thanks for the response. With that print function it tells me how many bars I have but I am not sure why I would need more then 200 bars or how to find out if I need more. If the 100 SMA uses 100 previous bars for todays data point, and 100 days ago it uses the previous 100 bars for that data point, why would I need more then 200 bars to plot?

      Thanks,
      Ryan

      Comment


        #4
        Hi Ryan, there are not enough secondary bars loaded to support the 100 SMA for that series. You can load a specific amount of bars using this overload to resolve this:

        AddDataSeries(string instrumentName, BarsPeriod barsPeriod, int barsToLoad, string tradingHoursName, bool? isResetOnNewTradingDay)

        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