Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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?
    JesseNinjaTrader Customer Service

    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)


        JesseNinjaTrader Customer Service

        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.
            JesseNinjaTrader Customer Service

            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.
                JesseNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by AaronKoRn, Yesterday, 09:49 PM
                0 responses
                11 views
                0 likes
                Last Post AaronKoRn  
                Started by carnitron, Yesterday, 08:42 PM
                0 responses
                10 views
                0 likes
                Last Post carnitron  
                Started by strategist007, Yesterday, 07:51 PM
                0 responses
                11 views
                0 likes
                Last Post strategist007  
                Started by StockTrader88, 03-06-2021, 08:58 AM
                44 responses
                3,980 views
                3 likes
                Last Post jhudas88  
                Started by rbeckmann05, Yesterday, 06:48 PM
                0 responses
                9 views
                0 likes
                Last Post rbeckmann05  
                Working...
                X