• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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.
    Chris L.NinjaTrader Customer Service

    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.
        Chris L.NinjaTrader Customer Service

        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
            Chris L.NinjaTrader Customer Service

            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:

                https://ninjatrader.com/support/help...tToninjascript

                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.
                Chris L.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Johnny Santiago, Today, 12:20 PM
                0 responses
                2 views
                0 likes
                Last Post Johnny Santiago  
                Started by NinjaTrader_Brandon, Today, 10:24 AM
                0 responses
                24 views
                0 likes
                Last Post NinjaTrader_Brandon  
                Started by ptertich, Today, 07:56 AM
                1 response
                12 views
                0 likes
                Last Post NinjaTrader_ChrisL  
                Started by aslane, Today, 08:24 AM
                1 response
                14 views
                0 likes
                Last Post NinjaTrader_ChrisL  
                Started by Capablanca, Yesterday, 05:51 PM
                1 response
                13 views
                0 likes
                Last Post NinjaTrader_PaulH  
                Working...
                X