Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Catching error

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

    Catching error

    Indicator "BlockVolume" required 1 Tick TimeFrame.
    How to catch an error in this case?
    The standard design doesn't work.
    Code:
    try{
    Print(BlockVolume(100,CountType.Volume)[0]);
    }
    catch{}

    #2
    Hello jshapen,

    Thanks for the post.

    The help guide page tells up we need to add a 1 tick series in State.Configure to calculate historical values for this indicator. e.g:

    Code:
    else if (State == State.Configure)
    {
      AddDataSeries(Data.BarsPeriodType.Tick, 1);
    }
    If NinjaTrader detects there is no 1 tick series to calculate with, then an error will be thrown.

    Please let me know if I can assist further.

    Comment


      #3
      Originally posted by NinjaTrader_ChrisL View Post

      If NinjaTrader detects there is no 1 tick series to calculate with, then an error will be thrown.
      My question is different. How to catch this error?

      Comment


        #4
        Hello jshapen,

        Thanks for the reply.

        The exception that is thrown is an ArgumentOutOfRangeException type. e.g:

        Code:
        try
        {
            double value = BlockVolume(80, CountType.Volume)[0];
            Print("The current Block Volume value is " + value.ToString());
        }
        
        catch (ArgumentOutOfRangeException outOfRange)
        {
            Print("Error: " + outOfRange.Message);
        }
        The following page on the NinjaScript lifecycle goes into further detail on the setup process of NinjaScripts:

        https://ninjatrader.com/support/help...fecycle_of.htm

        Please let me know if I can assist further.

        Comment


          #5
          How to make that the indicator does not stop working when this error occurs?

          Comment


            #6
            Hello jshapen,

            Thanks for the reply.

            The additional 1 tick data series must be added at compile time. There are no means of adding a 1 tick series after the script has run through State.Configure. You could run through all of the bars objects in the script in State.DataLoaded and display an error message when a 1 tick series does not exist.

            Code:
            else if (State == State.Historical)
                        {
                            foreach (Bars mybars in BarsArray)
                            {
                                if(mybars.BarsType.Name == "1 Tick")
                                {
                                    IsTickAdded = true;
                                }
                            }
                        }
            I have also attached the full test script to this response.

            Please let me know if I can assist further.

            Attached Files

            Comment


              #7
              Originally posted by NinjaTrader_ChrisL View Post
              The additional 1 tick data series must be added at compile time. There are no means of adding a 1 tick series after the script has run through State.Configure. You could run through all of the bars objects in the script in State.DataLoaded and display an error message when a 1 tick series does not exist.
              How to make that the indicator continued to work without adding 1 tick data series?
              I just want the indicator to skip the error and continue working
              Code:
              try
              {    
              double value = BlockVolume(80, CountType.Volume)[0];
              Print("The current Block Volume value is " + value.ToString());
              }
              catch (ArgumentOutOfRangeException outOfRange)
              {     Print("Error: " + outOfRange.Message); }
              
              //this line will never be reached
              int k=0;

              Comment


                #8
                Hello jshapen,

                Thanks for the reply.

                This help guide page on multi time frame scripts explains why the 1 tick series must be added:



                Note: To maximize data loading performance, any NinjaScript object (indicator or strategy as host) which references a multi-series indicator which calls AddDataSeries must include it's own calls to AddDataSeries(). For example, if the code above was included in an indicator, and that indicator was referenced in a NinjaScript strategy, then the hosting strategy will need to include the same calls to AddDataSeries(). When the strategy adds the additional Bars objects, the calls to AddDataSeries() within the indicator will be ignored. If the Bars objects are not added by the strategy in such cases, and error will be thrown in the Log tab of the Control Center that would read - "A hosted indicator tried to load additional data. All data must first be loaded by the hosting NinjaScript in its configure state."
                The BlockVolume indicator adds a 1 tick series itself, so the indicator/strategy that uses BlockVolume must also have a 1 tick series added with AddDataSeries.

                Please let me know if I can assist further.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                579 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                334 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                101 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                554 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                551 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X