Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Daily data on 5-minute chart

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

    Daily data on 5-minute chart

    Hi, I'm trying to add different data series to a 5-minute chart, but I keep getting this error: Error on calling 'OnBarUpdate' method on bar 0: Index was outside the bounds of the array.

    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Minute, 60); // [1]
    AddDataSeries(Data.BarsPeriodType.Minute, 120); // [2]
    AddDataSeries(Data.BarsPeriodType.Minute, 240); // [3]
    AddDataSeries(Data.BarsPeriodType.Day, 1); // [4]
    }

    else if (State == State.DataLoaded)
    {


    SMA_5_50 = SMA(Close, 50);
    SMA_60_50 = SMA(Closes[1], 50);
    SMA_120_50 = SMA(Closes[2], 50);
    SMA_240_50 = SMA(Closes[3], 50);
    SMA_Day_50 = SMA(Closes[4], 50);
    SMA_Day_100 = SMA(Closes[4], 100);
    SMA_Day_200 = SMA(Closes[4], 200);
    }​


    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 1
    || CurrentBars[4] < 1)
    return;​

    #2
    Hello xtremel,

    From the given code I cant see what may be the problem, do you know specifically which line in OnBarUpdate is having an error?

    Comment


      #3
      Hi Jesse,

      I only have this for now:

      protected override void OnBarUpdate()
      {
      if (BarsInProgress != 0)
      return;

      if (CurrentBars[0] < 1
      || CurrentBars[4] < 1)
      return;

      Print(SMA_5_50[0]);
      Print(SMA_Day_200[0]);
      }

      Error: Indicator 'MySMAs2': Error on calling 'OnBarUpdate' method on bar 1: Index was outside the bounds of the array.​

      Comment


        #4
        Hello xtremel,

        Do you have enough bars to load for the primary to allow for 200 daily bar to be used? You would also need to change the || CurrentBars[4] < 1) to || CurrentBars[4] < 200) to match the required data.

        You may want to use the AddDataSeries with a BarsToLoad so you can specify 200 daily bars.

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


        Comment


          #5
          In my 5-minute chart, I only have loaded data for the last 30 days. Do I need to load data for 200 days? I would rather not load 200 days of data in a 5-minute chart.

          Comment


            #6
            Hello xtremel,

            As you are trying to use a daily SMA with a period of 200 that would require at least 200 bars to calculate the value.

            Comment


              #7
              Is it possible to push the value of the daily SMA 200 from a daily chart (365 days of data loaded) to a 5-minute chart (20 days of data loaded)?

              Comment


                #8
                Hello xtremel,

                In NinjaScript the script only sees the data that you add in code so you would need to add a daily series and have enough bars to load to account for the period of data you need. You can create a 5 minute chart that has that many days to load or use the AddDataSeries statement that lets you specify a number of bars to load, that was shown in post 4.

                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