Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Attempting to load data?

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

    Attempting to load data?

    I have this set of code which compiles but is throwing an error in the output
    "Strategy 'MovingAveragesTest': Error on calling 'OnBarUpdate' method on bar -1: 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've tracked down that it has to do with this code below. For whatever reason it can't seem to access information from 1 bar go?

    Code:
    bool bearS = Highs[3][0] > Opens[3][0] && Highs[2][0] > Opens[2][0] && Highs[1][0] > Opens[1][0] && Close[0] < Opens[1][0];
    bool bullS = Lows[3][0] < Opens[3][0] && Lows[2][0] < Opens[2][0] && Lows[1][0] < Opens[1][0] && Close[0] > Opens[1][0];
    It's this or I get the error: "Strategy 'TMAOverlay': Error on calling 'OnBarUpdate' method on bar 0: Index was outside the bounds of the array"

    I'm wondering if I don't have my State == State.Configure or State == State.DataLoaded set up properly.
    Right now I have:
    Code:
    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Minutes, 1);
    }
    But that could be wrong...

    #2
    Hello alphatango,

    Thank you for your inquiry.

    If you only have one added data series, you only have 2 bars series. The index of the primary series is 0, and the index of the added secondary series is 1.

    You may have the syntax mixed up. Your barSeriesIndex can only be 0 or 1.


    Highs[int barSeriesIndex][int barsAgo]
    https://ninjatrader.com/support/help.../nt8/highs.htm

    Lows[int barSeriesIndex][int barsAgo]


    Opens[int barSeriesIndex][int barsAgo]
    https://ninjatrader.com/support/help.../nt8/opens.htm

    Closes[int barSeriesIndex][int barsAgo]
    https://ninjatrader.com/support/help...nt8/closes.htm


    Please let me know if you have any other questions.

    Comment


      #3
      That's what I thought. I got parts of it to work by tweaking numbers, but simply couldn't get the right information. Okay.

      I'm trying to have it gather information from the current data set (chart settings) but up to 3 bars back. That would be "Highs[0][3]", correct?

      Comment


        #4
        Hello,

        Yes, the high of the primary series 3 bars ago is Highs[0][3].

        Please let us know if you have any other questions.

        Comment


          #5
          If I'm not trying to reference a different dataset, using simply "high" would be adequate, am I understanding that correctly?

          Comment


            #6
            Hello,

            You can use High[0] instead of Highs[0][0] if you specify the BarsInProgress index and access the price within the condition.

            Code:
            if (BarsInProgress == 0)
            //access the High[0] price here and do something with that value
            Otherwise, just use Highs[] to make sure you are specifying which bar series you want to access.

            Please see this Help Guide page on accessing price data in a multi bars script:



            If you have any other questions, please let me know.

            Comment


              #7
              Part of me feels like I'm deep in the weeds on this.

              if I can simplify I can extrapolate. Answer me this:
              What is the syntax for this.
              given: 1 minute bar on the 1 minute chart (no special data sets)

              Is the bar 3 minutes ago a positive (green) or negative (red) bar. make bool BullishBar = True.
              I feel like this should be
              BullishBar = Close[3] > Open [3].

              What am I missing?

              Comment


                #8
                Hello,

                If you have no added data series, yes you can do a check for a red or green bar this way (with no BarsInProgress check).

                Please let us know if you have any other questions.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Yesterday, 05:17 AM
                0 responses
                56 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                132 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                73 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                45 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                49 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X