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 Mindset, 04-21-2026, 06:46 AM
        0 responses
        65 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        94 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        52 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        108 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        63 views
        0 likes
        Last Post PaulMohn  
        Working...
        X