Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

data series issue when translating from NT7 to NT8

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

    data series issue when translating from NT7 to NT8


    I have the following issue in an indicator translated from NT7 to NT8

    Variables:
    double methodRef1;
    private Series<double> methodRef1DS
    method1 definition


    on State.DataLoaded:
    methodRef1DS = new Series<double>(this);
    methodRef1 = method1;
    methodRef1DS[0] = methodRef1;

    The last statement compiles but not producing any data

    in NT7 this is - methodRef1DS.Set(methodRef1); which works fine.

    Please advise, Thanks.

    #2
    Hello Semion.AI.,

    Thanks for your post.

    You may use the assignment operator (=) to assign values to a Series<double>, but assignment to a Series<double> should only be done in OnBarUpdate, when we are processing that bar. (Series/DataSeries values are a set of values synchronized to the bars in the chart so we can have a custom value for each bar.)

    As a tip, reference the Code Breaking pages page of the Help Guide and looking up the item in the "Filter" section can help point out the specific items that have changed.

    Code Breaking Changes - https://ninjatrader.com/support/help...ng_changes.htm

    Documentation on using Series<double> - https://ninjatrader.com/support/help...ml?seriest.htm

    Example on using Series<double> - https://ninjatrader.com/support/help...taseries_o.htm

    If you need further direction for creating NinjaTrader 8 indicators in general - https://ninjatrader.com/support/help...indicators.htm

    We look forward to assisting.

    Comment


      #3
      Thanks Jim for your prompt response,

      However, I have already tested your suggestion to have the assignments in OBU, which wasn't successful.
      Since I work with Multi-Time Frame, should there be any other definitions for the time series ?

      best, Semion.

      Comment


        #4
        Hello Semion,

        If you need the Series synchronized to a specific data series in a Multi Time Frame script, you can provide the BarsArray[0], BarsArray[1], etc. in the Series' constructor.

        Code:
        else if (State == State.DataLoaded)
        {
            mySeries = new Series<double>(BarsArray[1]);
        }
        then in OnBarUpdate, since this Series<double> is synchronized to the secondary series:

        Code:
        if (BarsInProgress == 1)
        {
            mySeries[0] = Closes[1][0]; // Can also use Close[0] since we are on BIP 1
        }
        It may be helpful to test setting up the Series in a separate test script like the example, and then to implement your own Series in a test Multi Time Frame script.

        Prints could be used to make sure the values you are assigning the Series are the values you expect, and this can help reveal if the code is reaching the assignment to the Series.

        Debugging tips - https://ninjatrader.com/support/help...script_cod.htm

        Comment


          #5
          Hello Jim,
          The above issues have been solved.
          Thanks a lot for your help.

          Now I'm trying to follow you on the time series syncing.

          I have the following in State.Configure:

          AddDataSeries(Data.BarsPeriodType.Range, 1);
          AddDataSeries(Data.BarsPeriodType.Range, 2);
          AddDataSeries(Data.BarsPeriodType.Range, 3);


          You suggest to have in State.DataLoaded:

          ts1 = new Series<double>(BarsArray[1]);
          ts2 = new Series<double>(BarsArray[2]);
          ts3 = new Series<double>(BarsArray[3]);



          and then in OBU

          if (BarsInProgress == 1)
          {
          ts1[0] = Closes[0][0];
          ts2[0] = Closes[0][0];
          ts3[0] = Closes[0][0];

          }

          How would you test for such syncing ?

          Best, Semion.
          Last edited by Semion.AI.; 04-20-2022, 06:41 AM.

          Comment


            #6
            Hello Semion,

            Each Series will be synchronized to the Bars object given to it.

            In your case:
            • ts1 will be synchronized to the 1 Range data series
            • ts2 will be synchronized to the 2 Range data series
            • ​​​​ts3 will be synchronized to the 3 Range data series
            this means that:
            • tsi1 should be updated on BarsInProgress (BIP) 1
            • tsi2 should be updated on BarsInProgress (BIP) 2
            • tsi3 should be updated on BarsInProgress (BIP) 3

            I.E.

            Code:
            if (BarsInProgress == 0)
            {
                // This is the primary data series.
            }
            else if (BarsInProgress == 1)
            {
                ts1[0] = Closes[1][0];
            }
            else if (BarsInProgress == 2)
            {
                ts2[0] = Closes[2][0];
            }
            else if (BarsInProgress == 3)
            {
                ts3[0] = Closes[3][0];
            ​​​​​​​}
            This information is further detailed in the Multi Time Frame and Instruments documentation. I suggest reviewing the following sections specifically:
            • Creating Series<T> Objects
            • True Event Driven OnBarUpdate() Method
            • Accessing the Price Data in a Multi-Bars NinjaScript​​​​​​​
            Multi time Frame and Instruments (Important Read!) - https://ninjatrader.com/support/help...nstruments.htm

            Comment


              #7
              Hi again Jim.

              The above worked for the various range bars.

              However, when I tried to sync a unirenko bartype, declared as
              AddDataSeries(new BarsPeriod { BarsPeriodType = (BarsPeriodType) 2018, BaseBarsPeriodValue = 1, Value = 2, Value2 = 2 });
              an error appeared saying "Error on calling 'OnBarUpdate' method on bar 252: Object reference not set to an instance of an object."

              any suggestion ?

              Thanks much.

              Comment


                #8
                Hello Semion,

                The error is mentioned to be received from OnBarUpdate and the error mentions an object you are referencing is null.

                I would suggest using prints to identify the specific line that throws the error.

                Once you find the line of code that throws the error, check each item on the line and check to see which is null.
                • Is it ok for the object to be null here? aka -should a null check be added?
                • Is this object needed at this point in the code and should not be null? - should check how that object is instantiated.
                An example for checking for null references can be found below. This shows an example for Order objects but the same error is seen when any object that is null is referenced.

                The solution is to add a null check or correct the code so the object is created and available when other code needs it.

                Comment


                  #9
                  Hello Jim,

                  Thanks for your help - all works now.

                  I have another question:
                  in NT7 I was able to use negative BarsInProgress (e.g Closes[0][-2]) to streamWrite signals from delayed indicators. in NT8, however, it doesn't work.
                  Is there any way to allow this ?

                  Thanks much. Semion.

                  Comment


                    #10
                    Hello Semion,

                    No, there would not be a way to use negative BarsAgo references on Series objects.

                    If we are processing realtime data, these bars would not have yet exist, so the value would not be meaningful in that kind of context.

                    Comment


                      #11
                      what about historical data - that's what I'm looking for ?

                      Comment


                        #12
                        Hello Semion,

                        You could use GetValueAt to fetch a value at an absolute index instead of a BarsAgo reference.

                        As an example, the following will print the absolute index, (aka CurrentBar index) and the associated Close value for all bars that are loaded. (This would look ahead while processing historical data.)

                        Code:
                        for (int i = 0; i < Bars.Count-1; i++)
                        {
                            Print(i + " " + Close.GetValueAt(i));
                        }

                        Comment


                          #13
                          Hello Jim,
                          I have managed to get correct values using the following script. However, it only works for the primary bar series and not for higher bars frames (I use MTF).
                          Please advise...

                          Print(" Closes[0][0]: " + Closes[0][0].ToString()
                          + " GetValueAt(0): " + Closes[0].GetValueAt(CurrentBar)
                          + " GetValueAt(-1): " + Closes[0].GetValueAt(CurrentBar-1)
                          + " GetValueAt(-2): " + Closes[0].GetValueAt(CurrentBar-2)
                          + " GetValueAt(-3): " + Closes[0].GetValueAt(CurrentBar-3)
                          + " GetValueAt(-4): " + Closes[0].GetValueAt(CurrentBar-4)
                          );

                          Thanks...









                          Last edited by Semion.AI.; 05-16-2022, 04:52 AM.

                          Comment


                            #14
                            Hello Semion.AI,

                            In your code, you are only using Closes[0]

                            Closes[0] is the primary data series, Closes[1] is the first added data series, etc.

                            Closes - https://ninjatrader.com/support/help...tml?closes.htm

                            PriceSeries - https://ninjatrader.com/support/help...riceseries.htm

                            Comment


                              #15
                              Thanks for your reply, Jim,

                              As I said - it works only for the primary series, although I did try higher bars frames Closes[2] & Closes[3]. For those, however, the values were wrong...?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              31 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              24 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              14 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              13 views
                              0 likes
                              Last Post TheRealMorford  
                              Started by Mindset, 02-28-2026, 06:16 AM
                              0 responses
                              45 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Working...
                              X