Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Cloud Sharing Drawing Tools

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

    Cloud Sharing Drawing Tools

    2nd question and 2nd week with NT -- already too deep into this. Good stuff!

    OK, so I want to be able to use my custom drawing tools to (1) mark up a chart then (2) upload it to the cloud so that my friend can (3) download, (4) edit and upload from his machine.

    So, I worked all weekend and made it work but I feel that I hacked it too much and ran into a few problems and can't find answers in the code, forum or documentation.

    Question #1. Is there a way to create a drawing tool on that is marked as being created by the user? [i.e. IsUserDrawn = true]

    The reason I want this is so that the drawing object can be automatically serialized and saved when the page loads.

    I'm fine with some unsupported method that uses reflection but couldn't find one and wasn't even sure which object to look at. I checked both ChartManager and DrawingTool but didn't figure out how it gets hooked up.

    My hack#1 for this one was to serialize all downloaded tools to xml and save them on the file system and then recreate them in the OnStateChange / State.Configure.

    My hack#2 for this required me to move all the the user drawn tools that I wanted to upload/download to be owned by my own indicator and therefore removed -- found a reflective hack to do that.

    From https://ninjatrader.com/support/foru...-delete-itself

    Code:
     
      using System.Reflection;  typeof(ChartControl) .GetMethod("RemoveDrawingTool") .Invoke(ChartControlOfDrawObject, new Object[]  {     DrawingObjectToDelete, false, false });
    Is there a better way?

    Question #2. Is there a way I can hook into the serialization and control creation that NT uses?

    It would be great if I could serialize my custom object to a string then deserialize it so that it comes back, already attached to my chart.

    It would also be great if I could just create the drawing tool then hook it to the chart (even better if it was marked as a user-created tool like I wrote in Question #1).

    Instead the only way I found to do this was to create a new tool that is hooked to its owner when created. One thing that's not ideal is that my newly created drawing tool is hooked to my indicator and not to the chart because I won't be able to redraw with hack#1 without that.

    My hack #3 was to do this by hand. I wrote code to work like the static Draw.Rectangle class which creates a new tool by calling DrawingTool.GetByTagOrNew() and then fills it in and makes it active with the values that I got back from the object that I serialized and stored in my SQL database that lives in the cloud.

    Is there another or better way?


    I have more questions but I'll limit my 2nd question to 2 questions.

    #2
    Hello ntdev,

    Thank you for your post.

    IsUserDrawn is the only way that drawing tools are marked as being user drawn and there would not be a supported way to set this to true - it's a readonly variable.

    If I'm understanding correctly on the second question, you're trying to create a Drawing object and then save it as a public property so it's serialized and written to the template/workspace xml files, is that correct? There wouldn't be a way we could suggest to "hook into the serialization".

    You can't exactly just ToString() everything and make your own serializable types, but what we'd recommend sounds a lot like what you're already doing here. We'd recommend saving properties from your drawing object to public properties and then use a Draw.MyObject() method to draw from your serialized variables to recreate the object.

    Please let us know if we may be of further assistance to you.

    Comment


      #3
      Thanks Kate. That's what I figured -- like I said, I have it all working although it's not as elegant and integrated as I'd like but it works.

      One last question...

      Question #3: Is there a way I can allow the user to remove these (now drawn by my indicator) drawn objects individually without deleting the indicator that created them?

      I get the following message when I try to select and delete an individual drawn object but still want the user to be able to edit and remove them individually.

      "Warning - This object was drawn by an indicator or strategy. Removing this object will also remove the indicator/strategy that created this object. Do you wish to continue?"

      Maybe I should not have used the indicator as the owner in my call to DrawingTool.GetByTagOrNew() ???? But what to use and is this the problem?

      Any suggestions on this one? Or am I back to finding a way to set IsUserDrawn which causes this behavior?

      Can I grab the delete operation (or keystroke) before it gets to NT's normal handling?

      Comment


        #4
        PS Is there an unsupported way to set IsUserDrawn?

        I only see the getter with reflection -- Boolean get_IsUserDrawn().

        Comment


          #5
          Hello ntdev,

          Thank you for your reply.

          There is not an unsupported method to set IsUserDrawn that I am aware of.

          As far as allowing the user to remove objects drawn by the script, that is possible. You can set AllowRemovalOfDrawObjects to true in OnStateChange:



          Please let us know if we may be of further assistance to you.

          Comment


            #6
            Originally posted by NinjaTrader_Kate View Post
            Hello ntdev,

            As far as allowing the user to remove objects drawn by the script, that is possible. You can set AllowRemovalOfDrawObjects to true in OnStateChange:


            Thanks again Kate -- that worked perfectly! I thought I read the entire documentation but I missed that one.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            576 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            334 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            101 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            553 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            551 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X