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

TypeConverter reference not set & script reload bug

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

    TypeConverter reference not set & script reload bug

    Hello fellow humans,
    I'm currently running into two problems developing custom strategies & indicators:
    1. An indicator with a custom TypeConverter (for UI customizations) works as expected without error. However, once I use this indicator in a strategy and the strategy adds this indicator to the chart and I open the "Indictors" menu I receive: `Unhandled exception: Object reference not set to an instance of an object.` (And the properties panel remains empty for this indicator, but I should be seeing the colors for the added plots.)
      I can confirm that this only happens with a custom TypeConverter for an indicator and only in the described scenario. Otherwise everything functions as expected. I further can confirm that this error is not tied to this specific indicator or its TypeConverter but in general to custom TypeConverters for indicators once these're added to the chart through a strategy.
    2. When I check/uncheck (custom) properties of an indicator, and reload the script (rightclick on chart -> Reload NinjaScript), this checkbox does nothing anymore, i.e. the value during the reload gets "locked in" somehow, until I remove and re-add the indicator. I know I can "reload" the indicator by simply checking/unchecking and then applying or even if I recompile the code it's enough to toggle the visibility. My main concern about this is that the usability is error prone to non-developers. I have multiple clients which encountered this error (or similar ones) tied to said reload function.
    In hope for soon assistance
    Human#102

    #2
    Hello Human#102,

    Object reference not set to an instance of an object means that something was null. If that is only seen when the type converter is used with the strategy that adds the indicator you would likely need to add prints into the type converter to check which object is null when that is being called.

    For the second item we would need to see a simplified sample of what you are testing to get a better idea of what may be happening. I would suggest to make a new empty indicator and add the user input that you are using along with how it is used in your script and then attach that sample. Based on that we could check if everything is being used in the correct way or make suggestions on how to correctly use it otherwise.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi Jesse,
      Sorry I couldn't answer as quickly as you've replied.
      The first error happens only if the indicator is used inside a strategy and then the indicators menu is accessed. The indicator on its own does not produce this error. I've attached a minimal setup for both errors. To recreate the second error you can apply the indicator to a chart, then open its settings again, uncheck enableEma2 or enableEma3 or both, apply this change and then rightclick on the chart -> reload Ninjascript. After the reload, its impossible to to disable/enable said checkboxes, the entire indicator must be readded to the chart.
      Attached Files

      Comment


        #4
        Hello Human#102,

        For the first problem you are likely hitting an error in the indicators type converter because it will not have any property descriptors when called by a strategy.

        Code:
        PropertyDescriptor emaLength2 = propertyDescriptorCollection["EmaLength2"];
        emaLength2 will be null when called from a strategy, that would only be relevant for applying the indicator by itself when it has editable user inputs. You could add a null check for these properties to make sure they exist before trying to manipulate them.

        if(emaLength2 != null)
        {
        propertyDescriptorCollection.Remove(emaLength2);
        emaLength2 = new ReadOnlySampleErrorIndicatorDescriptor(indicator, emaLength2);
        propertyDescriptorCollection.Add(emaLength2);
        }

        This would be repeated for any property that you are manipulating.

        For the second problem I don't see that happening. I can check or uncheck the boxes each time I reload NinjaScript. Nothing appears to get stuck.


        JesseNinjaTrader Customer Service

        Comment


          #5
          Hi again,

          Now of course the first error makes sense. When added through a strategy the indicator has no properties, except for the Plot colors. I can easily solve that by just checking for any of the managed properties to see whether it is used inside a strategy or not and handle that accordingly.

          The second error still persists, for me as well as a client of mine. I've recorded how to reproduce it with the provided sample indicator.
          You can download it from my cloud: NinjaTrader_reload_error.mp4.​

          Comment


            #6
            Hello Human#102,

            If you are referring to the indicators plot color you set the plot to transparent based on your bool, if you want it to regain a color you need to add an else condition and set a color to the plot when the checkbox is enabled.

            JesseNinjaTrader Customer Service

            Comment


              #7
              From the indicator properties window, checking & unchecking these values sets the brushes either to transparent or their respective colors. This works without issues and as expected. It is only after the reload function is used, that the properties don't work anymore. So why does the "reload NinjaScript" function "breaks" the properties? Perhaps this result is expected, but then I'd like to know that and to leave the feedback that this is highly unintuitive appears as a clear bug.
              Perhaps a rephrase of the problem will help: Why does the "reload NinjaScript" function change the behavior and functionality of the properties of an indicator? Does it "freeze" plot values or what exactly happens under the hood?

              Comment


                #8
                Hello Human#102,

                In the script you provided you never reset the plot color, so that prevents the plot from having a brush after its set to transparent in that use case. You can correct that by adding an else condition like the following:

                Code:
                if (!EnableEMA3 || !ShowEMA3)
                Plots[2].Brush = Brushes.Transparent;
                else
                Plots[2].Brush = Brushes.Yellow;

                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Sorry, it seems my thoughts were not clear: Yes, this does solve the issue. But so does "just never use the Reload Ninjascript option", in which case I don't even have to explicitly change the color back.

                  At this point I'm mainly curious about what happens under the hood when using this option, and trying to point out that it is highly unintuitive, that it appears like a bug.
                  If I don't use the "reload NinjaScript" function, I don't have to explicitly reset the color in the code. After I use the "reload NinjaScript" function, the properties which were not false, (or the plots which were not set transparent) also still change the color to transparent and back. Only once the plot is set to transparent, I need to do so. So why does NinjaScript change the handling of plots or properties in certain cases when reloading the script from the right click menu?

                  Again, if all of this is working as expected, I'd simply like to know why its handled differently in this specific case. If not, then it may be a bug. Certainly not an urgent or breaking one, but still one that may or may not be forgotten in the backlog.

                  Comment


                    #10
                    Hello Human#102,

                    I wouldn't be able to say what may be happening in the internal code, we do not have access to that type of information. As this can be solved by just setting a color that would be the only solution that I could suggest here.
                    JesseNinjaTrader Customer Service

                    Comment


                      #11
                      In that case, thank you very much Jesse, especially for the quick solution for the other issue.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by athexinehowley, Today, 02:39 AM
                      0 responses
                      4 views
                      0 likes
                      Last Post athexinehowley  
                      Started by dtaylor, Today, 02:24 AM
                      0 responses
                      4 views
                      0 likes
                      Last Post dtaylor
                      by dtaylor
                       
                      Started by RosaRichardow, Today, 12:21 AM
                      1 response
                      5 views
                      0 likes
                      Last Post marcus2300  
                      Started by ETFVoyageur, Today, 12:45 AM
                      1 response
                      8 views
                      0 likes
                      Last Post ETFVoyageur  
                      Started by TradeSaber, Yesterday, 10:33 PM
                      1 response
                      12 views
                      0 likes
                      Last Post TradeSaber  
                      Working...
                      X