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

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:



                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 Christopher_R, Today, 12:29 AM
                0 responses
                6 views
                0 likes
                Last Post Christopher_R  
                Started by sidlercom80, 10-28-2023, 08:49 AM
                166 responses
                2,234 views
                0 likes
                Last Post sidlercom80  
                Started by thread, Yesterday, 11:58 PM
                0 responses
                3 views
                0 likes
                Last Post thread
                by thread
                 
                Started by jclose, Yesterday, 09:37 PM
                0 responses
                7 views
                0 likes
                Last Post jclose
                by jclose
                 
                Started by WeyldFalcon, 08-07-2020, 06:13 AM
                10 responses
                1,414 views
                0 likes
                Last Post Traderontheroad  
                Working...
                X