Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to Invoke a Custom Drawing Tool From Code

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

    How to Invoke a Custom Drawing Tool From Code

    I am trying to modify the Shortcut Toolbar by NinjaAddons.com to include custom Drawing Tools.

    The original code is located here:
    HTML Code:
    https://ninjatraderecosystem.com/user-app-share-download/shortcut-toolbar-by-ninjaaddons-com/
    I am able to pull the custom tools from the Drawing Tools menu using the NTMenuItem.ItemCollection, like the original code does for the standard tools.

    The Addon uses the NTMenuItem.Command property for each tool to invoke the drawing tool from the new sidebar menu. My problem is the NTMenuItem.Command property is null for any custom tool, so I am not able to use this to invoke the tool from the Addon sidebar menu.

    The custom tools are invoked just fine from the Drawing Tool menu. So I have a couple of questions:

    1) How does the Drawing Tool menu invoke Custom Drawing Tools?
    2) How can I invoke a Custom Drawing Tool with code?

    The code I added for the custom tools, mirrors the code for the standard tools.
    Code:
    public class NinjaAddonsToolBar : AddOnBase
    {[INDENT]private string[] CUSTOMTOOL_HEADERS = new string[3] { "Risk Reward 3", "Measured Move", "Horizontal Line Segment" };
    [/INDENT][INDENT]// existing code [/INDENT][INDENT]protected override void OnWindowCreated(Window window)
    {[/INDENT][INDENT=2]// existing code
    
    #region -- Add Custom Tools --
    else if (CUSTOMTOOL_HEADERS.Contains(mnItem.Header.ToString()))
    {[/INDENT][INDENT=3]verticalStackPanel.Children.Add(new NTMenuItem()[/INDENT][INDENT=4]{
    ToolTip = mnItem.Header,
    Style = mnItem.Style,
    Icon = mnItem.Icon,
    [COLOR=#c0392b][B]Command = mnItem.Command,[/B][/COLOR]
    Margin = new Thickness(1),
    Width = ITEM_WIDTH,
    HorizontalAlignment =
    HorizontalAlignment.Left
    });[/INDENT][INDENT=3]}[/INDENT]

    Thanks, Greg
    The Trading Mantis
    NinjaTrader Ecosystem Vendor - The Trading Mantis

    #2
    Hello Greg,

    You may want to contact the original author for further details about the unsupported / undocumented custom code.

    The custom drawing tools do not have a supported way of creating a command.

    Below is a link to a thread on this topic.


    The other approach is to find the hotkey from the NinjaTrader.Gui.HotKeys.IHotKeysContainer, but custom drawing objects also will not have a system hotkey.

    Unfortunately, I'm not aware of a work around for this.



    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks Chelsea,

      The info you provided was very helpful!

      Using a hot key will allow me to work around this. I'll just have to hard code the hot key for each custom tool, instead of pulling it from the IHotKeysContainer.

      I'll post another reply, which includes the workaround, once I have the coding worked out.
      The Trading Mantis
      NinjaTrader Ecosystem Vendor - The Trading Mantis

      Comment


        #4
        Here is an updated code file that use SendKeys (with the tool's hotkey) to invoke a custom drawing tool.
        Attached Files
        Last edited by TheTradingMantis; 01-16-2021, 06:52 PM.
        The Trading Mantis
        NinjaTrader Ecosystem Vendor - The Trading Mantis

        Comment


          #5
          Hi TheTradingMantis #TheTradingMantis

          This is lovely coding. Thank you.
          I tried getting things like ChartMarkersPlus ( made after you had completed this) but it doesn't seem to pick them up.
          I have tried setting hot keys as you seem to use those to run through the drawing tools and I added them in the various sections you outline but nothing>
          Any clues you might give me would be v helpful.
          thank you
          Edit - actually moving them into the correct group I now have them as Icons but clicking doesn't get them to draw?

          new DrawingToolGroup
          {
          Name = "SHAPE_TOOLS",
          DrawingTools = new List<DrawingTool>
          {
          new DrawingTool { Name = "Ellipse", Include = true },
          new DrawingTool { Name = "Rectangle", Include = true },
          new DrawingTool { Name = "Triangle", Include = false },
          new DrawingTool { Name = "Polygon", Include = false },
          new DrawingTool { Name = "Arc", Include = false },
          new DrawingTool { Name = "TriangleUpP", Include = true },
          new DrawingTool { Name = "TriangleDownP", Include = true }

          }
          },​
          Last edited by Mindset; 01-25-2025, 09:05 AM.

          Comment


            #6
            For the hot key to work, you will need to include the SendKeyCode property for any custom drawing tools like ChartMarkersPlus.

            Example:
            Code:
            new DrawingTool { Name = "TriangleUpP",   Include = true, SendKeyCode = "^%m" }
            When constructing the SendKeyCode, use the following: CTRL = ^, SHIFT = +, ALT = %

            In the example, the corresponding hot key is "CTRL ALT m"
            The Trading Mantis
            NinjaTrader Ecosystem Vendor - The Trading Mantis

            Comment

            Latest Posts

            Collapse

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