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

NT has an assertion failure

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

    NT has an assertion failure

    I pull up the Indicators dialog and double-click on my toy indicator. I get a popup for an NT assertion failure. Cannot copy/paste from the dialog, but the first clauses are:

    at
    NinjaTrader.Gui.Tools.ObjectModelViewModel`1.OnAdd Item(Object selected)
    at
    NinjaTrader.Gui.Tools.ObjectModelViewModel`1.OnAva ilableDoubleClick()
    at
    ​...

    This is reproducible. I exited NinjaTrader, restarted it, and tried again to add my toy indicator to my chart. I got the same assertion popup.

    #2
    I continued and got another dialog -- it looks like an NT dialog to me but I am not certain. It says
    Unhandled exception: Non-static method requires a target.

    Comment


      #3
      Hello ETFVoyageur,

      If this is happening when adding your custom indicator it likely relates to that indicator in some way. Do you see this happen with any other indicators? If this happens for all indicators you can try to do a re install first to refresh the platforms files, if that does not resolve the error you can use the steps below to create a clean user folder which will exclude your custom data so you can confirm the problem is resolved. If this only relates to your custom indicator you would have to debug that script to see what the problem is.

      To do a clean user folder test:
      • Exit NinjaTrader
      • Open the Documents folder
      • Rename the NinjaTrader 8 folder to NinjaTrader 8 Old
      • Download the installer from https://account.ninjatrader.com/download
      • Install the platform, this will create a new user folder.
      • Open the platform and import any of the items that you need
      JesseNinjaTrader Customer Service

      Comment


        #4
        This is not happening for my other indicators. It is related to this one specific indicator that I have been working on. My next step is to back out my recent changes to isolate what is causing the problem.

        I reported it only because it seems to me that it should not be happening and NT folks might want to see what it is that they are not handling correctly. Note that the assertion is in NT code, not in my code. That indicates that the NT code found something unexpected. Once I isolate what change in my indicator is causing NT to choke I'll let you know.

        Comment


          #5
          Hello ETFVoyageur,

          Yes anytime you see a problem with something you are creating you would need to debug it to see what may be happening. Without knowing what code is involved it would be impossible to say why you are getting that exception.

          You can cause problems using code which could cause problems in various areas of the platform and may display in different ways. Depending on the complexity of what you tried to do the platform may be able to handle the error or it may not. It is helpful to remind yourself when developing that NinjaTrader can handle certain expected errors which you will encounter, common items that most users encounter, for other items it may not be able to directly handle that situation and may produce error dialogs or errors in the log.


          JesseNinjaTrader Customer Service

          Comment


            #6
            Nothing I do should cause NT to assert.

            In any case, I have narrowed it down. I used the wizard to create as simple a new indicator as I could. The only option I gave was setting the indicator name. I just clicked through the rest. Then I added the following lines of code:
            Code:
                   [Display(Order = 9, Name = "Plot property", GroupName = "Parameters", Description = "Plot input parameter")]
                    public Plot MyPlot
                    { get; set; } = new Plot();
            
            ​
            Trying to load that indicator onto my chart provokes the assertion. If I do not initialize the property (i.e. remove the "= Plot();") it loads fine.

            This sounds like an NT bug to me.

            FYI: to prevent any misunderstanding, here is the entire indicator (minus the generated code at the bottom)
            Code:
            #region Using declarations
            using System;
            using System.Collections.Generic;
            using System.ComponentModel;
            using System.ComponentModel.DataAnnotations;
            using System.Linq;
            using System.Text;
            using System.Threading.Tasks;
            using System.Windows;
            using System.Windows.Input;
            using System.Windows.Media;
            using System.Xml.Serialization;
            using NinjaTrader.Cbi;
            using NinjaTrader.Gui;
            using NinjaTrader.Gui.Chart;
            using NinjaTrader.Gui.SuperDom;
            using NinjaTrader.Gui.Tools;
            using NinjaTrader.Data;
            using NinjaTrader.NinjaScript;
            using NinjaTrader.Core.FloatingPoint;
            using NinjaTrader.NinjaScript.DrawingTools;
            #endregion
            
            //This namespace holds Indicators in this folder and is required. Do not change it.
            namespace NinjaTrader.NinjaScript.Indicators
            {
                public class VsaShowBug : Indicator
                {
                    protected override void OnStateChange()
                    {
                        if (State == State.SetDefaults)
                        {
                            Description                                    = @"This causes an NT assertion failure when loading this indicator";
                            Name                                        = "VsaShowBug";
                            Calculate                                    = Calculate.OnBarClose;
                            IsOverlay                                    = false;
                            DisplayInDataBox                            = true;
                            DrawOnPricePanel                            = true;
                            DrawHorizontalGridLines                        = true;
                            DrawVerticalGridLines                        = true;
                            PaintPriceMarkers                            = true;
                            ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                            //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                            //See Help Guide for additional information.
                            IsSuspendedWhileInactive                    = true;
                        }
                        else if (State == State.Configure)
                        {
                        }
                    }
            
                    protected override void OnBarUpdate()
                    {
                        //Add your custom indicator logic here.
                    }
                    
                    // Remove the initialization and the assertion goes away
                    [Display(Order = 9, Name = "Plot property", GroupName = "Parameters", Description = "Plot input parameter")]
                    public Plot MyPlot
                    { get; set; } = new Plot();
            
                }
            }
            
            ​

            Comment


              #7
              Hello ETFVoyageur,

              In that case that is invalid code, you need to use AddPlot to create plots not new Plot().

              I would suggest taking a look at the Bollinger indicator, that shows how to correctly add plots and also make public properties that reference those plots. That is the only correct way to make public properties for plots you create.

              Alternatively you can use the new indicator wizard too generate plot code.
              JesseNinjaTrader Customer Service

              Comment


                #8
                It is helpful to remind yourself when developing that NinjaTrader can handle certain expected errors which you will encounter, common items that most users encounter, for other items it may not be able to directly handle that situation and may produce error dialogs or errors in the log.
                We are not talking about logged errors or NT error dialogs. Those are fine. They are what NT should be doing. We are talking about NT having an uncaught assertion -- that should not be happening.

                Comment


                  #9
                  Hello ETFVoyageur,

                  NinjaTrader is not going to handle this situation because you are using code which would not be expected to be used, you are not following the correct steps to add the plot.

                  If you use a NinjaTrader method like AddPlot and then place that in the incorrect location the platform can handle that because it knows where that code needs to go and where it was used incorrectly. There was expected code supplied, in the wrong location, a log message can be generated.

                  What you are doing is not following the design of how NinjaScript works so the platform presents an error message in the form of a window because it was unexpected and caused an error.

                  Going forward please use AddPlot or the indicator wizard to generate new plots so the correct design pattern is being used.
                  JesseNinjaTrader Customer Service

                  Comment


                    #10
                    In that case that is invalid code, you need to use AddPlot to create plots not new Plot().
                    I do not understand.your point. The code is not invalid. It is not trying to add a plot, so AddPlot(...) is not appropriate. The code is trying to add a Plot type to the configuration dialog.

                    That may be unconventional, but it should work. In fact, I did so recently in another case until I decided that adding a Stroke was better from a usability standpoint.

                    Furthermore, my point remains: this should not cause NT to get an uncaught exception.

                    Comment


                      #11
                      Hello ETFVoyageur,

                      To add a Plot to the UI properties grid you need to use AddPlot, that generates the UI properties internally.

                      The only valid way to create a Plot is to use AddPlot. The public property in your code is not necessary, that is just a convenience for your code so you don't have to use Value[0] to set the plot, you can call your property name instead. That has to be programmed in a very specific way.

                      The code you have in post 1 should not work and should not be used, that is not the correct way. As a learning exercise please do the following:
                      1. Open the NinjaScript editor
                      2. Right click indicators
                      3. Click New
                      4. Go to Plots
                      5. Add a Plot
                      6. Click Generate.

                      This is the valid code and the plot will show up in the UI to be configured.

                      See the SetDefaults section and the Properties section for the generated code.
                      Code:
                      protected override void OnStateChange()
                      {
                         if (State == State.SetDefaults)
                         {
                             AddPlot(Brushes.Orange, "Test");
                         }
                      }​
                      
                      [Browsable(false)]
                      [XmlIgnore]
                      public Series<double> Test
                      {
                         get { return Values[0]; }
                      }​
                      In regard to the assertation, I can't do anything there because the code you used is not valid, if you see a problem using valid code we can look into that.
                      JesseNinjaTrader Customer Service

                      Comment


                        #12
                        That is not correct.

                        The code is not trying to create a Plot. It is trying to gather information and will use AddPlot() later, in State=Configure. As I recall, this worked when I tried it recently -- I just did not like what the Plot exposed. so I ended up deciding it would be better to use a Stroke for that purpose.

                        There is a bug and it is not failing to use AddPlot(). I'm surprised it gets by the compiler, but the bug is that you cannot do static initialization dynamically ( = new Plot() ).

                        Examining what actually happens is interesting. In all cases NT is able to bring up the Indicators dialog, which means construction is not a problem -- it does that to populate the list of available indicators.

                        What happens next is interesting, though. When selecting (single-click) the indicator:
                        • In the bad case (initialization code is in) the grayed-out Properties area looks good -- Plot shows the correct name and details.
                        • In the good case (no attempted initialization) the grayed-out Properties area is terrible. It does show the correct name, but all of the details are missing. Strange that the good case is the one that is misbehaving.
                        The problem comes when I double-click on the indicator to add it.
                        • The good case does not display Plot properly. It does not show anything but the name and, although it has the triangle for expansion, it does not expand. The little triangle flips around but nothing else happens.
                        • The bad case asserts.
                        Interestingly, it appears NT does detect a problem. If I click on Ignore for the exception and then Cancel the Indicators dialog I get an NT dialog that says "Unhandled exception: Non-static method requires a target." Getting that dialog is fine -- NT has detected a problem and is telling me about it. Good. I'm not sure I understand the wording of the dialog, but I presume it has detected the problem. I have no problem with the NT error dialog -- that's how it should work.

                        There seem to be two bugs:
                        • NT should not allow an uncaught exception. Somehow, it is failing to protect itself Clearly, it is doing something, since it does detect an error. Just as clearly, it is missing something or is doing something in the wrong order, since there is that uncaught exception.
                        • In the good case (no attempted initialization) it fails to display the Plot properly even though the preview in the bad case looked good.
                        The summary:
                        • AddPlot() is irrelevant -- no one is trying to add a Plot. That will come later, in Configure.
                        • NT fails to display the Plot properly in the good case, even though it does the right thing in the bad case.
                        • NT should not allow the exception to escape. That is an NT bug.

                        Comment


                          #13
                          Hello ETFVoyageur,

                          If you want to make a input to gather info for a plot later you would use AddPlot, there is not use case to make a public Plot property, the platform does that on its own with AddPlot.

                          If you want to dynamically configure a plot you can use it in State.Configure, see the sample of that in the help guide in the following link under the sample named "ns Indicator which dynamically adds a plot in State.Configure"



                          As the example you provided is using unsupported code I cannot do anything to help there or with that exception, you just have to not use that code.
                          JesseNinjaTrader Customer Service

                          Comment


                            #14
                            If you want to make a input to gather info for a plot later you would use AddPlot, there is not use case to make a public Plot property, the platform does that on its own with AddPlot.
                            That is just plain wrong but I am done arguing about it. I know how to work around the problem.


                            Comment


                              #15
                              Jesse,

                              I want to be sure I understand your, and presumably NT's, position..

                              In the case where the indicator has ten plots that it may or may not use, depending on what the user sets up in the configuration dialog, is it your position that the indicator should AddPlots for all ten lines? That would mean creating all ten data series even if some or most of them will never be used.

                              There is no way of predicting which will be used when the indicator would need to do AddPlot at SetValues time. That is known only afterward because the user can turn each of them on or off . AddPlots() means that all data series will be created, even if the user can configure that most of them will not be used.

                              Another point is that it is possible to arrange that the properties shown in the dialog depend on user settings -- the indicator can arrange that if the user says to enable a feature its configurable attributes will only then be shown That can lead to a vastly simpler configuration presentation. Can Plots be shown and hidden similarly? Even if they can be, will the possibly extraneous data series still be created?

                              I presume the same discussion applies to lines. Is that correct?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by greenberet, Today, 05:07 AM
                              0 responses
                              12 views
                              0 likes
                              Last Post greenberet  
                              Started by nicbizz, 07-14-2024, 09:02 AM
                              3 responses
                              27 views
                              0 likes
                              Last Post nicbizz
                              by nicbizz
                               
                              Started by Rudmax, 07-02-2024, 05:40 AM
                              12 responses
                              285 views
                              1 like
                              Last Post benghabili  
                              Started by samish18, Today, 03:50 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post samish18  
                              Started by Rotdabbel, 07-17-2024, 10:00 AM
                              2 responses
                              11 views
                              0 likes
                              Last Post Rotdabbel  
                              Working...
                              X