Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

saving draw objects

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

    saving draw objects

    Hello, i have custom indicator and part of this has its own custom drawing tool which is rendered.
    There is a collection of these drawing objects and these are currently cleaned up on termination and any collections they use cleaned up.
    With the standard ninja drawing tools / objects eg fib retracement when added to a chart and ninjatrader is closed and opened those drawing tools will reappear on chart.

    Are they attached to the chart / indicator instance and so ninja knows they need to be rendered again ?
    Is there any XML aspect to saving and restoring these.
    Just curious if i can persist my drawing objects or if would be a challenging task - is there a recommended approach or mechanism for this
    thanks

    #2
    Hello explorer101,
    Thanks for your post.

    Drawing objects would be saved in the workspace with that instance of your chart/indicator. There would not be any extra steps you would need to take to ensure the same behavior happened with your custom indicator/drawing object.

    Josh G.NinjaTrader Customer Service

    Comment


      #3
      I will check over but have a sense for the custom drawing in indicator there will be a bit more involved.
      What is the key state distinction i can check and rely on for a chart having the ninjascript reloaded for a parameter change ie F5 vs an actual reload of historical data
      or a chart loading data for the first time - it might be that handling the F5 reload and persisting the collections i use will suffice. Once ninja is closed all the objects and collections
      used by my indicator will not have persisted unless i store them somewhere ; at least the way i see it currently
      thanks

      Comment


        #4
        If you are drawing manually, then you can draw with the tool and in the properties set it to attach to (x all charts), then save the template as default (click text 'template' in bottom right corner of window). From now on the drawing tool will be a global draw object by default (and thus auto saved)

        If your indicator is doing the drawing then I don't know. The drawing will be attached to the indicator and get destroyed without it (I think)

        Comment


          #5
          just to point out another distinction here :
          The indicator which does the drawing uses a custom drawing tool - so i have created a custom drawing tool which is managed by the indicator in terms of collections and the # of custom drawing objects on the chart - hence the original question and my update
          thanks

          Comment


            #6
            Oh I think I understand.

            So the indicator is doing the drawing, but you want those draw objects to behave as if the user had drawn them as global draw objects, and thus benefit from the built in NT persistence?

            so that when your indicator loads it could then scan the chart objects and find past drawn objects to populate your collection.

            Comment


              #7
              to anon84 - correct on first part - but i would need to store anchor points and other details where the original custom drawings were located on that chart in order to then reproduce on restarting ninjatrader. So i would need to store the collection of details rather than find draw objects which i would need to redraw from the collection details
              Last edited by explorer101; 05-19-2019, 05:14 PM.

              Comment


                #8
                Hi

                If it's a global draw object then ninja already saves the anchor points and such so that they are restored and redrawn whenever you open the appropriate chart, so you wouldn't need to track all that.

                You can detach your indicator-drawn objects and turn them into 'user drawn' objects with this trick:

                *Had written a lot of stuff here before about my solution and caveats, but since then I have found that it was simpler than I thought.

                All that is needed is to draw your line as a global object in your indicator, eg:

                Code:
                Draw.HorizontalLine(this, "tag123", 199.33, true/*set global*/, "MySavedTemplate");
                Then in the drawing tool code attach the line to the chart bars (as opposed to the indicator) and remove association with the indicator by setting DrawnBy to null.

                Code:
                this.AttachedTo.ChartObject = CurrentChartScale.GetFirstChartBars();
                this.DrawnBy = null;
                DrawnBy may have to be nulled more than once. I found that setting it in the first OnRender call didn't hold. The value must get written to again somehow. You can tell if it's worked by going to the properties of your draw object after its on the chart. If the 'attached to' combo box is greyed out then the DrawnBy is not null.

                You can get the current chartscale reference from within a few methods - OnRender, OnMouseDown etc.

                After this the drawing will be an independent object and saved by ninja even after restarts. Then when booting up your indicator you can scan charts to see if any instances of your draw tool already exist. The anchor points and other properties can then be accessed via those chart objects if your code needs that.

                *I realised a quirk that I encountered before is still there. NT doesn't save the line data in [Documents\NinjaTrader 8\templates\GlobalDrawingObject\] unless the drawing tool has been interacted with. Simply clicking on the tool is enough to count, but you can't expect users to do that. There is a hidden event method in ChartControl called OnGlobalDrawingObjectChanged which I suspect gets called whenever the tool is interacted with. My guess is it contains some code that provides the final piece of the puzzle to make it save correctly.

                If anyone finds a solution please post. This is a useful little trick to have if drawing based on a lot of tick data for example. It would be a simple built-in way to save your calculated draw objects without having to go over every tick and recalculate, or managing your own serialization. Tick Volume profile of the previous day could be a good use. at EOD you could generate the values and then remove the indicator, leaving the draw data intact. That way you wouldn't even need that old tick data loaded the next day. Could be a big resource saver if you use a lot of instruments. Also in theory you could eventually rack up days worth of tick vol profile data without ever having to load a single tick from those periods.

                But.. after saying all that, in such a scenario it might just be safer to spend the time writing a custom save feature. If the user accidentally deletes the draw objects somehow then all the data collected is gone.
                Last edited by anon84; 05-20-2019, 10:00 AM.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                595 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                343 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                103 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                556 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                554 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X