• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Drawing Object Removal

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

    Drawing Object Removal

    I have Draw Objects that my script creates and then at some time later attempts to remove from my chart ( No error from it ) that it clearly does not remove ( Verified that it attempted by Print Statement ). How Can I check for the existence or non existance of the Object after the removal attempt ? Its clearly still on the chart with the correct tag.

    Thanks
    Jerry

    #2
    Hello JerryWar, and thank you for your report.

    The most common reason for an object not being addressable via DrawObjects[tag] is if an @ is not added to the tag. The following code sample should make it clear when @ will be necessary to access a global drawing object. Please let us know if this does not address your question or if there are any other ways we may help.

    Code:
    
          string basetag = "MyLine";
          string globtag = "@" + basetag;
          bool tagIsGlobal = DrawObjects.FirstOrDefault(d => d.Tag.Contains("@")) != null;
          string tag = tagIsGlobal ? globtag : basetag;
    
                if(DrawObjects.Count > 0)
                {
            Print("Removing DrawObjects[\"" + tag + "\"]");
                    RemoveDrawObject(tag);
                }
                else
          {
                    Draw.HorizontalLine(this, "MyLine", High[0], true /* try making this false, it will continue to work */, "");
          }
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Jessica,
      The routine I having the issue with does not use Global drawing objects. That being said, I was unaware of "@" requirement for Global tags. But my question was more toward verifying the object was deleted.

      Currently I use:

      DrawObjects["PivotRayH"+i.ToString()] != null

      to verify an object exists before Deleting. Is this the best way to check the object before and/or after deletion ?

      Update: After working with this, There is funny business going on in NT8. In order to check out objects left on the screen I have to double click on them and sometimes move them. As I move them around all of a sudden they disappear. Like a delayed reaction from Ninja when I place it back down it says, you know what your supposed to be deleted,.

      Update: So I put in a check before removal to test for object and print and after removal to again test for the object and print. And now for the first time I see this what seems to be unrelated error message.

      14:54:02:813 ERROR: Failed to call 'Add' method: System.Threading.LockRecursionException: Write lock may not be acquired with read lock held. This pattern is prone to deadlocks. Please ensure that read locks are released before taking a write lock. If an upgrade is necessary, use an upgrade lock in place of the read lock. at System.Threading.ReaderWriterLockSlim.TryEnterWrit eLockCore(TimeoutTracker timeout) at System.Threading.ReaderWriterLockSlim.TryEnterWrit eLock(TimeoutTracker timeout) at NinjaTrader.Data.BarsSeries.Add(Bars bars, Double open, Double high, Double low, Double close, DateTime time, Int64 volume, Double tickSize, Boolean isBar, Double bid, Double ask)

      Thanks
      Jerry
      Last edited by JerryWar; 12-06-2016, 01:07 PM.

      Comment


        #4
        To clarify, the test code I sent was designed to draw objects for a few seconds and then to remove them on the next bar, repeatedly. It was designed to be run on 10 second bars, and to illustrate a point to the programmer.

        If this is occurring generally outside the test code, please send a set of steps I can use to reproduce this on my end.

        The best way to ensure an object exists is indeed to check the DrawObjects array, as you are doing.
        Jessica P.NinjaTrader Customer Service

        Comment


          #5
          Jessica
          The test code was crystal clear, because of the behavior I was seeing I decided to switch to slightly different implementation which immediately worked. No more removing draw objects, I just recycled them, works great. But now I am at the point where I want to make these Global. I added the "@" to my tags but my dilemma is that in order to use the IsGlobal I have to create templates for the Brush. I ran into issues with this before. It's easy to name several line templates but the issue is that if you have to reinstall Ninja and you loose your template files in the process because they got corrupted. You have to go back to your code to rebuild the templates. I know there is a SaveTemplateFile() I just need a bit of documentation such that I can have the indicator rebuild them if they do not exist.

          Thanks
          Jerry

          Comment


            #6
            Update: I created templates, switched to IsGlobal=true, and added the "@" and now I am getting the same behavior from the routine as I had before using the remove lines. I set the Global to false and took out the "@" and it works again. Not good. So I went to save and shutdown everything and I got

            2016-12-06 18:09:29:349 ERROR: Could not save indicator 'TrendSwing:' There was an error generating the XML document.

            This is the routine I have been working on.

            I just keep hitting Brick walls.

            Comment


              #7
              Are you able to generate this error message starting from a hello world indicator and doing nothing but creating, retrieving, updating, and deleting local and global drawing objects? If so, could you attach a script where this has been done?
              Jessica P.NinjaTrader Customer Service

              Comment


                #8
                Jessica
                Late last night I was able to figure out the XML error message. I searched and found the XML files and Opened a good one to examine what was being saved. What became clear was that if their was anything wrong with the User Properties and/or Default settings that it might cause a problem. So I commented out the User properties and Lo and behold the indicator saved. Something got corrupted the compile was not picking up.
                As to the other issues. My conclusion for me is that I am going to stay away from global Draw Objects
                Draw templates and Removing Draw Objects. I spent hours and found numerous issues. NT8 all by itself has issues with templates and I don't need to compound the situation.

                Thanks

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by GrossBitZeCoinTrader, Today, 02:15 AM
                0 responses
                1 view
                0 likes
                Last Post GrossBitZeCoinTrader  
                Started by Papercut110, Yesterday, 09:08 PM
                0 responses
                6 views
                0 likes
                Last Post Papercut110  
                Started by iq200, 11-09-2019, 08:26 AM
                5 responses
                59 views
                0 likes
                Last Post koganam
                by koganam
                 
                Started by johng964, Yesterday, 02:57 PM
                1 response
                12 views
                0 likes
                Last Post NinjaTrader_RyanS  
                Started by spamula, Yesterday, 03:00 PM
                2 responses
                18 views
                0 likes
                Last Post spamula
                by spamula
                 
                Working...
                X