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

MultiInstruments in Indicator

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

    MultiInstruments in Indicator

    I am trying to create a calculation based on the current instrument and an ETF. I add the series for the etf like this:

    else if (State == State.Configure)
    {
    AddDataSeries("QQQ", Data.BarsPeriodType.Day, 500);
    }
    Since I have been getting errors I decided to just print out both closing prices like this:

    protected override void OnBarUpdate()
    {
    if (CurrentBar < 252)
    return;

    Print("QQQ: " + Closes[1][0] + " " + "AAPL: " + Closes[0][0]);
    }

    I get the following error:

    Indicator 'x': Error on calling 'OnBarUpdate' method on bar 252: 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 have plenty of data for the etf AND the current instrument. Both dataseries are set to 500 bars.

    Dana

    #2
    Hello,

    Thank you for the question.

    Depending on the granularity of the series you use, this can come up. It would be suggested to use a current bar check for both series like the following:

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

    Could you try adding this instead of the CurrentBar check you have now and see if this resolves the error?

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Here is what I changed:

      Print("QQQ: " +CurrentBars[1] + " " + "AAPL: " + CurrentBars[0]);

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

      Print("QQQ: " + Closes[1][0] + " " + "AAPL: " + Closes[0][0]);

      This is the result:

      QQQ: -1 AAPL: 0
      QQQ: -1 AAPL: 1
      QQQ: -1 AAPL: 2
      QQQ: -1 AAPL: 3
      QQQ: -1 AAPL: 4
      QQQ: -1 AAPL: 5
      QQQ: -1 AAPL: 6
      QQQ: -1 AAPL: 7
      QQQ: -1 AAPL: 8
      etc

      Dana

      Comment


        #4
        Hello,

        I wanted to check, have you added the syntax I provided in at the top of OnBarUpdate and confirmed that has solved the problem?

        Code:
        if (CurrentBars[0] < 1 || CurrentBars[1] < 1) return;
        I see the prints are printing, is the logic following this check being stopped so the error is no longer present?

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          The error is gone. It seems that AddDataSeries did not work as expected.

          Comment


            #6
            It turns out there are two issues - I understood that AddDataSeries("QQQ", Data.BarsPeriodType.Day, 500); meant to load 500 bars of QQQ. Instead, the 500 was the period. I changed it to 1 and now I get data. However, in OnBarUpdate, the CurrentBars get out of sync after about bar 250. If this is the correct behavior, then I will have to keep my own bar array for each instrument. Any suggestions?

            QQQ 244 AAPL 244
            QQQ 244 AAPL 244
            QQQ 245 AAPL 245
            QQQ 245 AAPL 245
            QQQ 246 AAPL 246
            QQQ 246 AAPL 246
            QQQ 247 AAPL 247
            QQQ 247 AAPL 247
            QQQ 248 AAPL 248
            QQQ 248 AAPL 248
            QQQ 249 AAPL 249
            QQQ 249 AAPL 249
            QQQ 250 AAPL 250
            QQQ 250 AAPL 250
            QQQ 251 AAPL 251
            QQQ 251 AAPL 251
            QQQ 252 AAPL 251
            QQQ 253 AAPL 251
            QQQ 254 AAPL 251
            QQQ 255 AAPL 252
            QQQ 255 AAPL 252
            QQQ 256 AAPL 253
            QQQ 256 AAPL 253

            Comment


              #7
              Hello,

              Thank you for the reply.

              Can you try to open a chart for both the QQQ and AAPL, Reload the historical data for each, and then re-run the script? If that still has the same problem, please try the following print:

              Code:
              Print("QQQ: " + CurrentBars[0] + " Time: " + Times[0][0] + "AAPL: " + CurrentBars[1] + " Time: " + Times[1][0]);
              If you also print the Times for these bars and then view a chart, is there data for the time that is missing or out of sync displayed on the chart? I could expect differences between two different instruments in regard to the data available but because these are daily bars and both instruments have the same session I would expect them to match closely.

              I look forward to being of further assistance.
              JesseNinjaTrader Customer Service

              Comment


                #8
                You are right. AAPL is missing the days of 12/29/2015 - 12/31/2015, 3/3/2017 and 3/10/2017. The data feed is wrong. I have verified these days exist in another charting package. I used Kinetick EOD for the data.
                Last edited by chartish; 09-22-2017, 03:46 PM.

                Comment


                  #9
                  Hello,

                  Thank you for the reply.

                  I tried this morning for the dates you mentioned but I see them populating for me. I attached an image of the historical data manager data.

                  Could you try the following to see if this is relating to caching?
                  • Exit NinjaTrader
                  • Open the folder: Documents\NinjaTrader 8\db
                  • Delete the folder "cache" and only the cache folder.
                  • Start NinjaTrader
                  • In a chart for QQQ, right click and choose Reload historical data. Ensure the timeframe is included in the Days to load.
                  • In a second chart for AAPL, right click and choose Reload historical data. Ensure the timeframe is included in the Days to load.


                  After doing this, could you use the historical data manager to verify that the days are present like the image from above?

                  I look forward to being of further assistance.
                  Attached Files
                  JesseNinjaTrader Customer Service

                  Comment


                    #10
                    I actually deleted the whole year of historical data and downloaded it again and it works now. Don't know how the data got corrupted.

                    Dana

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by BarzTrading, Today, 07:25 AM
                    2 responses
                    13 views
                    1 like
                    Last Post BarzTrading  
                    Started by devatechnologies, 04-14-2024, 02:58 PM
                    3 responses
                    19 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Started by tkaboris, Today, 08:01 AM
                    0 responses
                    3 views
                    0 likes
                    Last Post tkaboris  
                    Started by EB Worx, 04-04-2023, 02:34 AM
                    7 responses
                    162 views
                    0 likes
                    Last Post VFI26
                    by VFI26
                     
                    Started by Mizzouman1, Today, 07:35 AM
                    1 response
                    9 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Working...
                    X