Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Changing default temple of drawing tool from scipt.

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

    Changing default temple of drawing tool from scipt.

    Hello,

    Is there a way to access and change the default template of the drawing tool from a script? Specifically, trying to change the default color brush of all the tools programmatically. Since the drawing tools have multiple brushes depending on how the complexity of said tool, I will have to iterate through all the brush parameters for each tool.

    Thanks
    Unsuitable
    NinjaTrader Ecosystem Vendor - Unsuitable

    #2
    Hello Unsuitable,

    The template itself is an xml file located in Documents\NinjaTrader 8\templates\DrawingTools.

    There are no NinjaScript methods to modify the template file itself. You can use StreamWriter to write text as well as xml files, but would be a risky and time consuming task.
    https://ninjatrader.com/support/help...o_write_to.htm

    However, with a script you can add a DrawingObject and specify the properties like the color.
    https://ninjatrader.com/support/help...8/draw_dot.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello Unsuitable,

      The template itself is an xml file located in Documents\NinjaTrader 8\templates\DrawingTools.

      There are no NinjaScript methods to modify the template file itself. You can use StreamWriter to write text as well as xml files, but would be a risky and time consuming task.
      https://ninjatrader.com/support/help...o_write_to.htm

      However, with a script you can add a DrawingObject and specify the properties like the color.
      https://ninjatrader.com/support/help...8/draw_dot.htm
      HelloChelseaB,

      This guy managed to do it somehow. https://www.youtube.com/watch?v=ozM96Uuwprw
      Also a member on future.io forums. https://futures.io/local_links.php?a...27&linkid=1738

      The futures.io script has a separate toolbar as well. I suspect that the color selector and toolbar talk to each other when assigning colors, as you suggested doing. As for the youtube guy, he has set up as I wanted. Both solutions are behind a paywall. I managed to get the color selector going. All I need now is a way to change the drawing tool colors. The manipulation of XML files is definitely sketchy.

      Click image for larger version

Name:	2020-09-28_12-49-47.gif
Views:	44
Size:	1,019.6 KB
ID:	1120194
      Unsuitable
      NinjaTrader Ecosystem Vendor - Unsuitable

      Comment


        #4
        Hello Unsuitable,

        I am not seeing in the video where this is saving a template file.. At what time does this video show the code of the script saving a template file?

        The object's brush will have the color. You can change the brush as a parameter to the method call or as a property of the object.
        Draw.Dot(NinjaScriptBase owner, string tag, bool isAutoScale, DateTime time, double y, Brush brush)

        myDot.Brush = Brushes.Red.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hello ChelseaB,

          I took another peek at the youtube video and he uses a custom toolbar that interacts with the color picker. In all honesty, I assumed it changed the default's drawing objects template, my bad.

          Going to have to implement a sperate toolbar aswell. :P

          For those that wondered what I used for the buttons, https://ninjatrader.com/support/help...collection.htm
          Unsuitable
          NinjaTrader Ecosystem Vendor - Unsuitable

          Comment


            #6
            I checked out the internet for NT8 examples of toolbars and the only decent one is the mahToolBar. I checked it out but it turns out it sends out a keypress (hotkey) that is assigned to the tools instead of calling the actual command. In my nt7 toolbar indicator, it calls the individual drawing tool command.

            Anyways, instead of creating a whole new toolbar, the script grabs the most recent drawn object and changes the brush color from there. It's a little limited in functionality but will get the job done. The problem with that solution is that the chart only updates the color if moved. Is there a way to send a "force update" to the chart?

            Click image for larger version

Name:	p35lrIv.gif
Views:	45
Size:	759.0 KB
ID:	1120273

            The code:
            Code:
            Object lastDrawingObject = DrawObjects.Last();
            
            if (lastDrawingObject is DrawingTools.Line)
            {
                    NinjaTrader.NinjaScript.DrawingTools.Line line = (NinjaTrader.NinjaScript.DrawingTools.Line) lastDrawingObject;
                    line.Stroke.Brush = btn.Background;
            }
            Thanks
            Unsuitable
            NinjaTrader Ecosystem Vendor - Unsuitable

            Comment


              #7
              Hello Unsuitable,

              There is a ForceRefresh() method.
              https://ninjatrader.com/support/help...rcerefresh.htm
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                ChelseaB the MVP

                I noticed that its a tad sluggish. As noted in the NT8 documentation on DrawObjects, iterating over a large number of objects can be a performance hit. Instead of calling .Last(), is it possible to call the last element in DrawnObject by using count? The following code errors out, DrawObjects only accept tags. Looked into it and .Last() is apparently optimized for said task. Perhaps that's the best it can do.

                Code:
                Object lastDrawingObject = DrawObjects[DrawObjects.Count()-1];
                Unsuitable
                NinjaTrader Ecosystem Vendor - Unsuitable

                Comment


                  #9
                  Hello Unsuitable,

                  If you are trying to remove all object except the last 5, it would be necessary to remove each object by its tag name. I can't think of any way to do that other than looping through all of the drawing objects except the last 5.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    No, I'm not trying to remove all except the last 5. I'm trying to get the last drawn object from DrawObjects[] without calling DrawObjects.Last(). Last() does work but it's not instant. It will do for now.
                    Unsuitable
                    NinjaTrader Ecosystem Vendor - Unsuitable

                    Comment


                      #11
                      Hello Unsuitable,

                      Apologies for the confusion, there is another forum thread open also with questions on DrawObjects.

                      Try:

                      Code:
                      private List<IDrawingTool> drawObjectsList;
                      Code:
                      if (DrawObjects.Count() > 0)
                      {
                      drawObjectsList = DrawObjects.ToList();
                      Print(drawObjectsList[drawObjectsList.Count() - 1].Tag);
                      }
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        I tried the code and although it works, its the same speed as the .Last() solution. So I imagine the slow down is somewhere else or perhaps my computer is a tad slow. It's not that much of a bother. Anyways I got another question about the button handling but I'll post it in the WPF toolbar thread.

                        Thanks
                        Unsuitable
                        NinjaTrader Ecosystem Vendor - Unsuitable

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by TheCatTrader, Today, 04:52 PM
                        0 responses
                        4 views
                        0 likes
                        Last Post TheCatTrader  
                        Started by localappleseed, Today, 04:10 PM
                        0 responses
                        8 views
                        0 likes
                        Last Post localappleseed  
                        Started by Ragstoriches, Today, 03:13 PM
                        2 responses
                        15 views
                        0 likes
                        Last Post Ragstoriches  
                        Started by michaelsh, Today, 03:21 PM
                        1 response
                        18 views
                        0 likes
                        Last Post NinjaTrader_ChrisL  
                        Started by Ragstoriches, Today, 02:53 PM
                        1 response
                        14 views
                        0 likes
                        Last Post NinjaTrader_Emily  
                        Working...
                        X