Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Getting Template Names

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

    Getting Template Names

    Hello

    Is there an easy way to get a list of template names for a drawing tool. Tried using this method, but this doesn't work.

    Code:
    NinjaTrader.NinjaScript.DrawingTools.DrawingTool.GetTemplateFolder(NinjaTrader.NinjaScript.DrawingTools.AndrewsPitchfork)
    Thanks
    Unsuitable
    NinjaTrader Ecosystem Vendor - Ocean Trading Indicators

    #2
    Hello Unsuitable,

    Thanks for the post.

    It looks like this is not a documented method so I can't say if this would be a correct way to access the template folder always, it looks like this does work to gather the path though.

    The method takes a type so it would need to have a typeof statement.

    Code:
    NinjaTrader.NinjaScript.DrawingTools.DrawingTool.GetTemplateFolder(typeof(NinjaTrader.NinjaScript.DrawingTools.AndrewsPitchfork));
    Keep in mind I am not certain if this would work in a compiled export, when you try to gather types or cast types to NinjaTrader.Custom objects it can fail so that would be something to test if you plan to export the file as compiled. If you run into problems there you may want to just use the standard user folder path and then build the path yourself so its hard coded in your script.

    You may be able to automate the folder path similar to the method above by using the types string representation like the considerations page shows. https://ninjatrader.com/support/help...ghtsub=dynamic

    Code:
    Path.Combine(NinjaTrader.Core.Globals.UserDataDir, "templates","DrawingTool","AndrewsPitchfork");

    I look forward to being of further assistance.
    Last edited by NinjaTrader_Jesse; 11-13-2020, 08:36 AM.

    Comment


      #3
      Hello Jesse,

      Did a little digging into Path.Combine method. This is what I came up with.

      Code:
      string filePath = Path.Combine(NinjaTrader.Core.Globals.UserDataDir, "templates","DrawingTool","AndrewsPitchfork","Warning Line Opposite.xml");
      //Print("file path " + filePath);
      XmlDocument doc = new XmlDocument();
      doc.Load(filePath);
      XmlNodeList nodeList = doc.SelectNodes("/NinjaTrader/AndrewsPitchfork/CalculationMethod");
      
      foreach (XmlNode node in nodeList)
      {
        Print("Node Value " + node.InnerText);
      }
      To get a list of template names wouldn't be much more complicated. Not sure how to do it, but it can probably be figured out by searching, "C# how to get a list of files within a path?". I want to build an indicator that can cycle between drawing templates. The problem is that NT does not have an easy way to set a new template. Orginally I was thinking to just to instiate an new object with the same position but use the template string overload method. Then delete the original draw object. However, draw objects drawn by an indicator behaves weirdly if the indicator is removed from the chart. Actually a selected object is guranteeed to have an owner (owner being the chart) so that method may work.

      Nevertheless, the method of reading the XML file is going to be a pain in the ass. Espically if a template has additional levels... seeing how I'll be looking to compile the inidicator.
      Unsuitable
      NinjaTrader Ecosystem Vendor - Ocean Trading Indicators

      Comment


        #4
        So looks like one cannot get the owner of a draw object. The drawnby property returns null if it was drawn by the user. One cannot initiate using Draw.DrawingTool() with null as the owner. This goes back to the problem I was having with setting the owner to the chart and what not. If y'all have access to the uncompiled code of the drawing tools script, can't you take a peak at how it sets the owner when a user draws an object?
        Unsuitable
        NinjaTrader Ecosystem Vendor - Ocean Trading Indicators

        Comment


          #5
          Hello Unsuitable,

          To get a list of template names wouldn't be much more complicated. Not sure how to do it, but it can probably be figured out by searching, "C# how to get a list of files within a path?". I want to build an indicator that can cycle between drawing templates.
          Yes you could use any C# means of parsing the folder for template files, likely using Directory.GetFiles is the easiest or Linq. Stackoverflow has many samples like the following public answer: https://stackoverflow.com/a/13301088


          The problem is that NT does not have an easy way to set a new template. Orginally I was thinking to just to instiate an new object with the same position but use the template string overload method. Then delete the original draw object. However, draw objects drawn by an indicator behaves weirdly if the indicator is removed from the chart. Actually a selected object is guranteeed to have an owner (owner being the chart) so that method may work.
          If the indicator is removed from the chart the expectation would be that the objects are as well. Was that what you were referring to?

          Nevertheless, the method of reading the XML file is going to be a pain in the ass. Espically if a template has additional levels... seeing how I'll be looking to compile the inidicator.
          If you use the filename of the template without its extension you should be able to pass that as the template in the Draw. syntax. Was that not working for some reason?

          So looks like one cannot get the owner of a draw object. The drawnby property returns null if it was drawn by the user. One cannot initiate using Draw.DrawingTool() with null as the owner. This goes back to the problem I was having with setting the owner to the chart and what not. If y'all have access to the uncompiled code of the drawing tools script, can't you take a peak at how it sets the owner when a user draws an object?
          I'm not certain I follow what you are trying to do here. Are you trying to manipulate the objects owner in some way?

          I look forward to being of further assistance.

          Comment


            #6
            Hello Jesse,

            Originally posted by NinjaTrader_Jesse View Post
            If the indicator is removed from the chart the expectation would be that the objects are as well. Was that what you were referring to?

            If you use the filename of the template without its extension you should be able to pass that as the template in the Draw. syntax. Was that not working for some reason?
            Well, that's exactly what I would like to do. Create an object and pass the template name. The problem is that it would be creating a draw object that is attached to the indicator it self. When removing the indicator it would remove the object as well.

            My current work around is to set the drawnBy to null, set the isLocked to false and manually change the attachedTo property to the chart. These are properties that shouldn't really be changed. When doing so this happens.

            Click image for larger version

Name:	unnamed.gif
Views:	600
Size:	373.7 KB
ID:	1127540

            The explination can be found at the bottom of: https://www.oceantradingindicators.x...ons-user-guide

            My thinking is that if the owner is set properly (setting the owner to chart instead of this, the indicator), I could avoid setting the drawnBy, isLocked, and attachedTo properties. As if the draw object was drawn by a user through the drawing Tool and not the indicator. Hence I would like to know how the drawing tool script handles the owners if that's possible.

            Thanks
            Unsuitable
            NinjaTrader Ecosystem Vendor - Ocean Trading Indicators

            Comment


              #7
              Hello Unsuitable,

              Thanks for the clarification.

              It sounds like everything is working as expected, drawing objects drawn by script are not permanent. When a script reloads or first starts it will re process bars so the objects would need to be removed and re added at those points.

              Tools that create manually drawn objects generally don't use the Draw methods in code but instead invoke the chart commands to have the user manually draw an object. That object could then be referenced through the drawing object collection and the script has nothing to do with actually drawing the object.

              For the use case you described if you have found setting the said properties to work then you could go that route. How the tool handles the owner is found in your code and the code of the existing tools, where it is being passed in the Draw partial class. Further than that point would be internal code so we wouldn't have any info on how its being handled beyond that.

              I look forward to being of further assistance.

              Comment


                #8
                Hello Jesse,

                Well for now, I have a sudo solution for keeping objects drawn by an indicator on the chart upon refresh. It's a little finaky when changing the indicator's parameters or removing the indicator altogether, however, the object stays drawn when refreshing the indicator which is the important part. It would be cool if there was a field to indicate whether a draw object can be attached to the chart instead of the indicator (treated like a user drawn object). Or even an IsDeletedUponRefresh field would suffice. I believe ChelseaB created a feature request for that... probably won't be implemented any time soon. I'm sure that has some additional security concerns as well.

                So far the bulk of the coding is finished for changing the template the manual way. The real challenge will be adding the additional levels to draw objects such as the pitchfork. However, there is documentation on how to handle that.



                Thanks
                Unsuitable
                NinjaTrader Ecosystem Vendor - Ocean Trading Indicators

                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