Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Monitor/capture/suppress plot value outside of valid range error

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

    Monitor/capture/suppress plot value outside of valid range error

    How can I monitor/capture/suppress a plot set value outside of valid range error in an indicator?

    Below is a code snippet which was an atttempt to try to avoid the issue, it has cut the errors down but not 100%. when the error occurs the indicator stops plotting. I don't care if a few plots dobn't show but not for it to quit totally plotting .

    The "try, catch" doesn't seem to do a thing as I never get anything in the output window. I put in all the validity checks I could think of but I can't seem to figure out the plot value that is causing the issue. The Diffference value is the result of a divide operation computed by using two values returned from a custom indicator with a custom data series. It works most of the time but I still get the error on occasion.

    I know the logic is crude but I didn't think it would this difficult to fix.

    Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "Diff"));

    try
    {
    if (Diffference != double.NaN &&
    Diffference != Double.PositiveInfinity &&
    Diffference != Double.NegativeInfinity &&
    Diffference != 9999999999999999999999999.0 &&
    Diffference != -9999999999999999999999999.0 &&
    Diffference != double.MinValue &&
    Diffference != double.MaxValue )
    {
    Diff.Set(Diffference);
    }
    }
    catch
    {
    Print("1.0x Diffference " + Diffference);
    }

    Anything you can think of I can use as a cure for my self inflicted ailment?
    Last edited by ct; 12-06-2013, 12:51 PM.

    #2
    I'd have to do some testing with this, but how are you calculating your plot value (Diffference) to end up with values this high? I can't remember off the top of my head but there might be a max plot range that is less than the max size of a double. (again I need to test, but I think this could be resolved by changing the way the value is being set)

    What error message are you getting?

    Look forward to assisting you further.
    LanceNinjaTrader Customer Service

    Comment


      #3
      Lance

      Exact wording in the log: "Error on setting indicator plot for indicator "MyIndicator". Value outside of valid range."

      Calculated as:
      double Diffference =-1 * (Indicator2( true).CalculatedPrice[0] / Math.Abs((Indicator2( false).CalculatedPrice[0] ));

      I hope that helps.

      Comment


        #4
        Originally posted by ct View Post
        How can I monitor/capture/suppress a plot set value outside of valid range error in an indicator?

        Below is a code snippet which was an atttempt to try to avoid the issue, it has cut the errors down but not 100%. when the error occurs the indicator stops plotting. I don't care if a few plots dobn't show but not for it to quit totally plotting .

        The "try, catch" doesn't seem to do a thing as I never get anything in the output window. I put in all the validity checks I could think of but I can't seem to figure out the plot value that is causing the issue. The Diffference value is the result of a divide operation computed by using two values returned from a custom indicator with a custom data series. It works most of the time but I still get the error on occasion.

        I know the logic is crude but I didn't think it would this difficult to fix.

        Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "Diff"));

        try
        {
        if (Diffference != double.NaN &&
        Diffference != Double.PositiveInfinity &&
        Diffference != Double.NegativeInfinity &&
        Diffference != 9999999999999999999999999.0 &&
        Diffference != -9999999999999999999999999.0 &&
        Diffference != double.MinValue &&
        Diffference != double.MaxValue )
        {
        Diff.Set(Diffference);
        }
        }
        catch
        {
        Print("1.0x Diffference " + Diffference);
        }

        Anything you can think of I can use as a cure for my self inflicted ailment?
        You should be curing it at the source. Check for division by zero, or the minimum other value that you may prefer, then calculate Difference only if the inputs to the calculation are valid.

        Comment


          #5
          Does the plot CalculatedPrice of Indicator2 work properly by itself when you put it on the chart?

          What sort of values do you get from calling
          Indicator2( true).CalculatedPrice[0]

          In other words I'm trying to confirm if the division here or the indicator values are causing the issue.
          LanceNinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_Lance View Post

            Does the plot CalculatedPrice of Indicator2 work properly by itself when you put it on the chart?

            Yes, I did a "-" as a test instead of a "/" and it worked fine.

            What sort of values do you get from calling
            Indicator2( true).CalculatedPrice[0]
            I can also get positive numbers.
            1.0 Diffference -220337.5
            1.0 Diffference -220437.5
            1.0 Diffference -218525
            1.0 Diffference -220012.5
            1.0 Diffference -219350
            1.0 Diffference -215687.5
            1.0 Diffference -218037.5
            1.0 Diffference -211237.5
            1.0 Diffference -210050
            1.0 Diffference -213612.5
            1.0 Diffference -213387.5
            1.0 Diffference -214450
            1.0 Diffference -208262.5
            1.0 Diffference -213962.5
            1.0 Diffference -212525
            1.0 Diffference -215187.5
            1.0 Diffference -215462.5
            1.0 Diffference -214862.5
            1.0 Diffference -215337.5
            1.0 Diffference -213925
            1.0 Diffference -216950
            1.0 Diffference -214537.5
            1.0 Diffference -218662.5
            1.0 Diffference -217525
            1.0 Diffference -215887.5
            1.0 Diffference -213200
            1.0 Diffference -209737.5
            1.0 Diffference -207525
            1.0 Diffference -205800
            1.0 Diffference -204787.5
            1.0 Diffference -205600
            1.0 Diffference -208800
            1.0 Diffference -208012.5
            1.0 Diffference -206375

            I will also show the computed Diffference value after the divide I actually plot. Normally a very small number but can have lots of decimals. I can round then up to just a few decimal places if you think it might help. Maybe it is the decimal precision and not the significant digits that are the cause.
            1.0 Diffference 0.164390945023356
            1.0 Diffference 0.106728142076503
            1.0 Diffference 0.109000684462697
            1.0 Diffference 0.0376240794108229
            1.0 Diffference 0.0169464930174172
            1.0 Diffference 0.0456598902871894
            1.0 Diffference 0.0595062939349354
            1.0 Diffference 0.0459974176888315
            1.0 Diffference 0.020308564231738
            1.0 Diffference -0.00353628536285363
            1.0 Diffference -0.0239457831325301
            1.0 Diffference -0.00322977545370655
            1.0 Diffference -0.0232102486812359
            1.0 Diffference -0.0209969788519637
            1.0 Diffference -0.0292091072498502
            1.0 Diffference -0.0199606835021927
            1.0 Diffference -0.0100809531082939
            1.0 Diffference -0.006591048436542
            1.0 Diffference -0.0473320593855652
            1.0 Diffference -0.0592248512120772
            1.0 Diffference -0.0797955416725827
            1.0 Diffference -0.0643857369712718
            1.0 Diffference -0.0742751035566348
            1.0 Diffference -0.0771749964402677
            1.0 Diffference 11.8116654954322
            1.0 Diffference 11.0819134993447
            1.0 Diffference 11.416384563304
            1.0 Diffference 10.4270833333333
            1.0 Diffference 9.40251228836701
            1.0 Diffference 9.62387892376682
            1.0 Diffference 9.45794392523364
            1.0 Diffference 9.5377358490566
            1.0 Diffference 8.79381965552178
            1.0 Diffference 9.05497382198953
            1.0 Diffference 8.57135826771654
            1.0 Diffference 8.13589981447124
            1.0 Diffference 8.67331670822943
            1.0 Diffference 8.52690802348337
            1.0 Diffference 8.8295165394402
            1.0 Diffference 12.1728395061728
            1.0 Diffference 14.1720890410959
            1.0 Diffference 13.5489396411093
            1.0 Diffference 14.071367884452
            1.0 Diffference 17.3322717622081
            1.0 Diffference 23.8603268945022
            1.0 Diffference 16.4004004004004
            1.0 Diffference 15.8360655737705
            1.0 Diffference 19.6033857315599
            1.0 Diffference 18.3059617547807
            1.0 Diffference 14.1495726495726


            In other words I'm trying to confirm if the division here or the indicator values are causing the issue.
            Understood
            Need more?

            Comment


              #7
              Just on spec I tried Math.Round(Diffference, 6); . It didn't help.

              Comment


                #8
                As a test try this:

                Run your script that sets your Plot called Diff.
                Right before you set the Plot do a print like this
                Print(Time[0]+ " "+ Difference);

                This way you can isolate the value that's being passed which causes the crash. (depending on your results and other code it may be helpful to add a few other prints as well, such as the indicator values and what they get stored to right after the division)

                Let me know what value you find.
                LanceNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by jaybedreamin, Today, 05:11 PM
                0 responses
                2 views
                0 likes
                Last Post jaybedreamin  
                Started by giogio1, 10-30-2024, 02:27 AM
                8 responses
                58 views
                0 likes
                Last Post giogio1
                by giogio1
                 
                Started by owen5819, Today, 04:51 PM
                0 responses
                4 views
                0 likes
                Last Post owen5819  
                Started by samish18, Today, 03:57 PM
                1 response
                6 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by owen5819, Today, 09:48 AM
                2 responses
                11 views
                0 likes
                Last Post owen5819  
                Working...
                X