Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Data series error when adding Tick series

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

    Data series error when adding Tick series

    Hello,

    I am trying to add both the Pivots and the "Order Flow VWAP" indicators to my NinjaScript custom strategy. The strategy is set to run on Calculate = Calculate.OnEachTick;

    In order to get the Pivots to work, I had to add 2 data series (1 min and 1 day);
    For the VWAP, I was able to get the "standard" resolution to work, but not the VWAPResolution.Tick. When I try to add the data series for the Tick I get an error:

    Let me know how I can get the VWAP to calculate on VWAPResolution.Tick​, and how I should ad the Data Series for Tick without the runtime errors, I would appreciate it!

    (....I am on a 1-min NQ chart, with a "Calculate on Tick" strategy.....)


    Code:
    else if (State == State.Configure)
    {
    // adding the Data Series for Tick throws an error
    //AddDataSeries(Data.BarsPeriodType.Tick, 1); // ERROR
    
    AddDataSeries(BarsPeriodType.Minute, 1); // this is for Pivots
    AddDataSeries(BarsPeriodType.Day, 1); // this is for pivots
    }
    
    else if (State == State.DataLoaded)
    {
    // PIVOTS initialize
    
    mPivots_DailyBars = Pivots(BarsArray[1], PivotRange.Daily, HLCCalculationMode.DailyBars, 0, 0, 0, 20);
    mPivots_IntraDayData = Pivots(BarsArray[1], PivotRange.Daily, HLCCalculationMode.CalcFromIntradayData, 0, 0, 0, 20);
    
    // VWAP initialize
    mOrderFlowVWAP = OrderFlowVWAP(VWAPResolution.Standard, Bars.TradingHours, VWAPStandardDeviations.None, 1, 2, 3);
    
    // When WVAPResolution is Tick it throws an run time error
    // mOrderFlowVWAP = OrderFlowVWAP(VWAPResolution.Tick, Bars.TradingHours, VWAPStandardDeviations.None, 1, 2, 3); // ERROR
    }


    ​Thanks
    Last edited by ldanenberg; 05-02-2025, 07:47 AM.

    #2
    Hello ldanenberg,

    To use the VWAP your code should look exactly like the sample shown in the following page including the two condition in OnBarUpdate. That is how the 1 tick series is used for that indicator.

    Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.


    After making your script look exactly like that you could add additional series after the tick series for your other indicator. In your other indicators you would also need to change BarsArray[1] to the index of the correct series, 1 is the first added data series so it would be 2 or 3 depending on the order you use AddDataSeries.

    Comment


      #3
      Hi... It doesn't work... I tried it step by step, and it still gives an error.

      Just now I commented out the VWAP indicator (and also commented out the PIVOTS).... and just ONLY added the Tick data series. and this is the error it gives (see attached)

      Code:
      else if (State == State.Configure)
      
      {
      
      AddDataSeries(BarsPeriodType.Minute, 1); // don't know if I need this
      
      AddDataSeries(BarsPeriodType.Day, 1); // bars array for pivots
      
      AddDataSeries(BarsPeriodType.Tick, 1);
      
      }
      ​
      
      ////// THE VWAP IS COMMENTED OUT
      //if (BarsInProgress == 0)
      
      //{
      
      // mOrderFlowVWAP = OrderFlowVWAP(VWAPResolution.Standard, Bars.TradingHours, VWAPStandardDeviations.None, 1, 2, 3);
      
      // mOrderFlowVWAP = OrderFlowVWAP(VWAPResolution.Tick, TradingHours.String2TradingHours("CME US Index Futures ETH"), VWAPStandardDeviations.None, 1, 2, 3);
      
      //}
      Attached Files
      Last edited by ldanenberg; 05-02-2025, 08:18 AM.

      Comment


        #4
        I tried changing the order of the Data series, and it still gives the same error (neither indicator is being instantiated)...

        Should I be posting this in the NinjaScript topic instead of the Strategy topic?

        Code:
        else if (State == State.Configure)
        
        {
        
        //AddDataSeries(Data.BarsPeriodType.Tick, 1);
        
        AddDataSeries(BarsPeriodType.Tick, 1);
        
        AddDataSeries(BarsPeriodType.Minute, 1); // don't know if I need this
        
        AddDataSeries(BarsPeriodType.Day, 1); // bars array for pivots
        ​}
        Attached Files
        Last edited by ldanenberg; 05-02-2025, 08:26 AM.

        Comment


          #5
          Hello ldanenberg,

          That may be due to some other code being used in the strategy. Have you tried making a completely new strategy and only adding the code from the sample I linked to? If not I would suggest trying that before doing anything else to make sure you have that first indicator set up correctly. Your script would just have the single 1 tick series added and the two conditions in OnBarUpdate.

          Comment


            #6
            I commented out the indicators...
            and now I commented out the 1 min and 1 day data series...

            I am running a 1-min chart, and calculating on tick....

            This is all I have for data series.....

            else if (State == State.Configure)
            {
            AddDataSeries(BarsPeriodType.Tick, 1);
            ​}

            and I still get the attached error when it tries to run.......

            Can you take a look at the error please and let me know what is causing this?

            I did a search on "BarsArray" and found this... could it be causing the problem?

            I commented out the bars array part, but am still getting the error

            Code:
            else if (State == State.Historical)
            {
            //if (BarsArray[0].BarsPeriod.BarsPeriodType == BarsPeriodType.Range)
            //    gRangeBarTicks = BarsArray[0].BarsPeriod.Value;
            //else
                gRangeBarTicks = 1;
            }
            ​
            Thanks!
            Attached Files
            Last edited by ldanenberg; 05-02-2025, 08:57 AM.

            Comment


              #7
              It says it is failing on line 3831.... which is where the first variable with "barsAgo" = 0 is being assigned.... So, when the tick data series is added, it can't assign the bars ago.....

              3831 gWCCI_TurboEnter = mWCCI.Turbo[pWCCI_Turbo_Enter_BarsAgo]; // ERROR index out of range......

              Comment


                #8
                Hello ldanenberg,

                I am not aware what would cause that error, based on the line number you mentioned it sounds like that is a larger script. All that I can suggest is to start from a known working point which would be to create a new script and the use the sample from the API guide. Once you see that working you could start adding your other code to see if it gets the same error, if so then you will know what specific code is causing that.

                Comment


                  #9
                  I'm asking if there is some check to do before assigning the "barsAgo" to variables with that data series... do I need the "bars In progress check or data loaded on assigning variables? You should know why that data series is effecting the "tick" assignment of the variables

                  Comment


                    #10
                    Hello ldanenberg,

                    That is a custom variable in your script, I am not aware how that is being used by that small of a sample and without any debug output.

                    BarsAgo refers to the bars from right now in processing for that specific series.

                    You may be able to debug that by printing the BarsInProgress, CurrentBar, your bars ago variable to see which series was processing your logic, what the values of each of the variables are. To use a bars ago you need to make sure the series you are using that bars ago with has processed at least that many bars, if you are calling the series from another bars in progress you may need to add error handling to avoid trying to access a bars ago before that series has processed that many bars.

                    Comment


                      #11
                      the bars ago = 0 .... Why would a tick data series cause this to error??????

                      Do I need to put asynch logic around the data series?

                      I can't believe you have no idea why this is happening

                      Comment


                        #12
                        what about this???

                        Summary follows :

                        Code: /// <summary>
                        /// Allows us to cheat IndicatorName's access restrictions
                        /// </summary>
                        private class IndicatorNameWrapper : IndicatorName
                        {
                        public IndicatorNameWrapper(IndicatorName source)
                        {
                        // Decide what to shallow copy here
                        }

                        public void AddDataSeriesWorkaround(BarsPeriodType periodType, int tickSize)
                        {
                        AddDataSeries(periodType, tickSize);
                        }
                        }


                        Code:
                        IndicatorNameWrapper instanceName = new IndicatorNameWrapper(IndicatorName(args));
                        instanceName.AddDataSeriesWorkaround(BarsPeriodTyp e.Tick, tickSize);


                        https://forum.ninjatrader.com/forum/...from-indicator

                        Comment


                          #13
                          Hello ldanenberg,

                          From the error I can't tell what the error may be, you are using custom code so I don't know what part of your existing code was affected based on the error. You would have to debug the script. Try commenting out your custom code so you have essentially a new script structure that does nothiing. make sure that compiles and runs. After doing that uncomment only the code required for the vwap and make sure that runs. Then uncomment small parts of the remaining code until you get the error. That will give you a better idea what to debug.

                          Comment


                            #14
                            can you explain to me what this "workaround" is for? Its from the Ninja Forum... I appreciate it, this is very frustrating that the data series is crashing the program! Thanks for your help!!

                            public void AddDataSeriesWorkaround(BarsPeriodType periodType, int tickSize)
                            {
                            AddDataSeries(periodType, tickSize);
                            }
                            }

                            Code:
                            IndicatorNameWrapper instanceName = new IndicatorNameWrapper(IndicatorName(args));
                            instanceName.AddDataSeriesWorkaround(BarsPeriodTyp e.Tick, tickSize);​

                            Comment


                              #15
                              Hello ldanenberg,

                              The link you provided is from the NT7 forum so it would not be relevant. In NT8 AddDataSsries is not inteded to be used like that with variables.

                              If a script uses secondary data the host script needs to add the same data, you will get a very specific message in the log telling you what your script needs to add if you are not adding the correct data.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by NullPointStrategies, Today, 05:17 AM
                              0 responses
                              41 views
                              0 likes
                              Last Post NullPointStrategies  
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              124 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              64 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              41 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              46 views
                              0 likes
                              Last Post TheRealMorford  
                              Working...
                              X