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

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.
    Gaby V.NinjaTrader Customer Service

    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.
        Gaby V.NinjaTrader Customer Service

        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.
            Gaby V.NinjaTrader Customer Service

            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.
                Gaby V.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by rhyminkevin, Today, 04:58 PM
                4 responses
                52 views
                0 likes
                Last Post dp8282
                by dp8282
                 
                Started by iceman2018, Today, 05:07 PM
                0 responses
                5 views
                0 likes
                Last Post iceman2018  
                Started by lightsun47, Today, 03:51 PM
                0 responses
                7 views
                0 likes
                Last Post lightsun47  
                Started by 00nevest, Today, 02:27 PM
                1 response
                14 views
                0 likes
                Last Post 00nevest  
                Started by futtrader, 04-21-2024, 01:50 AM
                4 responses
                50 views
                0 likes
                Last Post futtrader  
                Working...
                X