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

Collection was modified

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

    #31
    Hello td_910,

    Thanks for your reply.

    The easiest way to find the error would be to use Visual Studio and have the debugger break when the exception happens.

    See this video I made earlier on how to set up NinjaTrader for Visual Studio debugging:


    Here is the help guide page on the subject as well:


    Run the script after attaching visual studio to the NinjaTrader.exe process and wait for the exception to occur. You should see Visual Studio stop at the line where the exception occurs.

    Please let me know if I can assist any further.
    Chris L.NinjaTrader Customer Service

    Comment


      #32
      thanks, I'll do that

      one general question: Can I try to remove an object that doesn't exist without getting an exception?

      e.g. RemoveDrawObject("Long_B1_TickFailure"+unique+(Cur rentBar - 1));
      without the object being existent?

      Comment


        #33
        Hello td_910,

        Thanks for your reply.

        After testing with an indicator, I found that if you call RemoveDrawObject on a tag that does not exist, the action will be ignored and code flow will continue. We will need to find the exact line where the exception is thrown using Visual Studio debugging.
        Chris L.NinjaTrader Customer Service

        Comment


          #34
          thanks, that's what I thought too

          yes, I'll do that

          can I debug more than one indicator at a time?
          Last edited by td_910; 04-01-2019, 03:07 PM.

          Comment


            #35
            switching work spaces I got this: https://www.screencast.com/t/w81yYNs8R
            has probably nothing to do with my indicators?

            VS is running the whole night, but that error seems to be elusive

            Comment


              #36
              Hello td_910,

              Thanks for your reply.

              The error from your screenshot is not related to the script. There is something happening within either the workspace you switched from or to. You can restore a previous version of either workspace by going to Control Center>Database Management> Expand "Restore Workspace".

              You can also debug two scripts at once. If either of them throw an exception, Visual Studio will break at the exception.

              Please let me know if I can assist further.
              Chris L.NinjaTrader Customer Service

              Comment


                #37
                Chris,

                thanks for bringing up VS to debug NinjaScript. I wonder how I could do without that. :-)
                found a copy/paste error, so far

                Comment


                  #38
                  here is another one, with the exact line of code
                  I'm just checking on an object, if that exists or not, no foreach or casting

                  Last edited by td_910; 04-09-2019, 01:02 PM.

                  Comment


                    #39
                    I didn't expect this line to throw an exception

                    Comment


                      #40
                      Hello td_910,

                      Thanks for your patience.

                      It looks like the help guide example where they access the DrawObjects collection with a tag name could cause this error, so if you could Export your script as source and send in your script to platformsupport[at]ninjatrader[dot]com and reference the forum thread link in the body of the email. I will reproduce and report the problem to our product management team so this can be fixed.

                      As a solution for you now, please use the "Looping through the collection to find specific draw objects" example on the DrawObjects help guide page.

                      https://ninjatrader.com/support/help...rawobjects.htm

                      After implementing the script in this way, you should not see the collection modified problem.

                      I look forward to assisting further.
                      Chris L.NinjaTrader Customer Service

                      Comment


                        #41
                        the script has 1000+ lines of proprietary source code, which I don't wanna give away

                        dealing with chart objects in NT8 seems to become a night mare, compared to NT7
                        especially, if I need to use a thread safe list copy and do the dynamic cast for every single object

                        if I just want to check whether it exists or not

                        I don't hope, a condition like that would throw this error too

                        Code:
                                    #region Alert
                                    if (IsFirstTickOfBar && showAlert)
                                    {
                                        RearmAlert("PABuySellPressure_BGP");
                                        RearmAlert("PABuySellPressure_SGP");
                        
                                        //BGP
                                        if (DrawObjects["BSP_Bull_Larger_Bodies"+(CurrentBar-1)] != null ||
                                            DrawObjects["BSP_Bear_Smaller_Bodies"+(CurrentBar-1)] != null ||
                        
                                            DrawObjects["BSP_Bull_UTail_Decreasing"+(CurrentBar-1)] != null ||
                                            DrawObjects["BSP_Bull_LTail_Decreasing"+(CurrentBar-1)] != null ||
                                            DrawObjects["BSP_Bear_LTail_Increasing"+(CurrentBar-1)] != null ||
                                            DrawObjects["BSP_Bear_UTail_Increasing"+(CurrentBar-1)] != null ||
                        
                                            DrawObjects["BSP_Bear_Overlap_Increasing"+(CurrentBar-1)] != null ||
                                            DrawObjects["BSP_Bull_Overlap_Decreasing"+(CurrentBar-1)] != null ||
                        
                                            DrawObjects["BSP_BrsOnOpen"+(CurrentBar-0)] != null
                                            )
                                            Alert("PABuySellPressure_BGP", Priority.High, "PABuySellPressure - Buying Pressure", SoundFileBuy, 1, Alert_Background, bull_Symbol_Color);
                        I have several pieces of code, that are similar to that and they work without throwing exceptions

                        Code:
                                    if (DrawObjects["RVB_Sell_Text"+(CurrentBar-1)] != null && Low[1]<=Low[0] && Open[0]<=Close[0] && (Median[0]<=Close[0] || High[1]<High[0]))
                                    {
                                        dynamic RVB_Text = DrawObjects["RVB_Sell_Text"+(CurrentBar-1)];
                                        if (RVB_Text.ToString().Equals("NinjaTrader.NinjaScript.DrawingTools.Text"))
                                            if (RVB_Text != null) RVB_Text.DisplayText = "(R)";
                                    }
                        Last edited by td_910; 04-10-2019, 10:44 AM.

                        Comment


                          #42
                          Hello td_910,

                          Thanks for your reply.

                          The most simple refactor of this code you could do is create a method that takes a string (the draw objects tag), performs the FOR loop search, then returns the draw object or true if it exists, then replace your null checks with that method call. I'll create a script that attempts to reproduce this. If it is unsuccessful in re-creating the issue I will need you to make a stripped-down example that re-creates the same problem, we can submit that script to our development team so this workaround can be avoided. Also please let me know when this happens (during run time, a chart refresh, NinjaScript refresh)

                          I look forward to assisting further.
                          Chris L.NinjaTrader Customer Service

                          Comment


                            #43
                            I think I remember, that the issue occurred either during a chart refresh or NinjaScript refresh, not during run time, because the error occurred on the 1st bar, the script processed

                            I use tons of null checks in my code, because it is based on chart objects entirely

                            I really don't get the point, why these null checks don't work (reliably) anymore in NT8 or why they throw the occasional exception

                            if multi-threading is the problem, why isn't the null check not thread safe by default and what is a not thread safe null check for

                            Comment


                              #44
                              here you go: https://www.screencast.com/t/ZIRh1dh3
                              reload all historical data, while there are three other indicators loaded

                              the errors seem to be intermittent, not only the 1st bar, here bar 169
                              and another error as well (
                              "Object reference not set to an instance of an object")

                              the 1st two runs were my proprietary indicator (indicator name was empty)



                              this probably happens, because a price change is processed already by the indicator, while the other three indicators still are modifying the draw objects collection

                              "what is a not thread safe null check for"
                              Attached Files
                              Last edited by td_910; 04-11-2019, 04:24 AM.

                              Comment


                                #45
                                Hello td_910,

                                Thanks for posting a test script. Ill test it out and let you know what I find.

                                Thanks in advance for your patience.
                                Chris L.NinjaTrader Customer Service

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by fx.practic, 10-15-2013, 12:53 AM
                                5 responses
                                5,404 views
                                0 likes
                                Last Post Bidder
                                by Bidder
                                 
                                Started by Shai Samuel, 07-02-2022, 02:46 PM
                                4 responses
                                95 views
                                0 likes
                                Last Post Bidder
                                by Bidder
                                 
                                Started by DJ888, Yesterday, 10:57 PM
                                0 responses
                                7 views
                                0 likes
                                Last Post DJ888
                                by DJ888
                                 
                                Started by MacDad, 02-25-2024, 11:48 PM
                                7 responses
                                159 views
                                0 likes
                                Last Post loganjarosz123  
                                Started by Belfortbucks, Yesterday, 09:29 PM
                                0 responses
                                8 views
                                0 likes
                                Last Post Belfortbucks  
                                Working...
                                X