Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90


Drawing Tool Context Menu Handler with Global Drawing Objects

  • Filter
  • Time
  • Show
Clear All
new posts

    Drawing Tool Context Menu Handler with Global Drawing Objects

    I've got a drawing tool that makes price changes via right-click context-menu items. I've attached a stripped down example with two menu items that Increases/decreases the prices on the drawing object by 4 points.

    When the drawing object is a Global Drawing object, the objects on the other charts are not updated. I'm sure this used to work on a previous version of Ninjatrader, but at some stage it stopped working I can't get it to work with or

    The code that executes in from the Context menu handler is:

    public void IncreasePriceClick(object sender, RoutedEventArgs e)
           foreach (var chartAnchor in Anchors)
                chartAnchor.Price += 4;
    The Force refresh doesn't seem to propagate to the Global objects on the other charts. Furthermore, if I "Reload Ninjascript", the drawing tool snaps back to its original place. I can make the change propagate to the other global objects by clicking on the line while its selected, but can't figure out how to do it from code.

    Any help would be much appreciated.
    Attached Files

    Hello kevinenergy,

    Thank you for your post.

    It would be expected that NinjaScript changes to a global drawing object would not propagate to all charts.

    However, this can be worked around by doing something like the following, but note that this will change the owner of the drawing object.

    foreach (DrawingTool dt in DrawObjects)
    if (dt is HorizontalLine && dt.IsGlobalDrawingTool)
    (dt as NinjaTrader.NinjaScript.DrawingTools.Line).Stroke. Brush = CurrentBar % 2 == 0 ? Brushes.Purple : Brushes.Crimson;
    DrawingTool.SetDrawingToolCommonValues(dt, (dt as IDrawingTool).Tag, (dt as IDrawingTool).IsAutoScale, this, true);

    That being said, I have added a vote on your behalf for an existing feature request to support this. This request is being tracked under the number SFT-4438.

    As with all feature requests, interest is tracked before implementation is considered, so we cannot offer an ETA or promise of fulfillment. If implemented, it will be noted in the Release Notes page of the Help Guide.

    Release Notes —

    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service


      Hey NinjaTrader_Jim do you have any ideas about this? You came up with the original MenuItems on a drawing tool example, so wondered if you had any ideas about how to make changes propagate to the other global objects?

      I've tried various hacky things to get it to work on the IncreasePriceClick method, but nothing works.

      Any ideas?
      Attached Files


        Hello Kevin,

        I had a look with Kate, and I'm a bit stumped for how we can update the other drawing tool instances from within the context menu.

        We are asking QA and Development for a hint, but it may take some time before they are able to do deeper dive into sources to answer this question.

        Kate will reply back once we get further information.
        JimNinjaTrader Customer Service


          Hi Jim. really appreciate you looking into this for me. I built a tool that's a Horizontal Ray which can snap its price to the OHCL using the menu items example you created. I Use it by going tto the daily chart and snap the tool to yesterdays high and low. I know there's an indicator for this but I don't like it for various reasons.

          I can get it my tool to propagate to the other charts with just a simple "click" on the Drawing Tool while its selected. So I've been trying to reproduce the code that happens during the click handler to programatically initiate a click, but just couldn't get it to work.

          Please do let me know if you hear back from the Engineers/QA. Thanks again for your time - and yours too NinjaTrader_Kate


            Hello kevinenergy,

            Actually, I think we can get this accomplished without a hint from Development.

            Try adding a public method that increases the anchor price by X increment and then call ForceRefresh within your method.

            Within your context menu event method, loop through all windows, and within all windows that are charts, loop through the ChartObjects collection, and look for types that match your Drawing Tool. If the type matches, we know it is a DrawingTool and can see if it is a global DrawingTool. If it is, we can call the above method to update all instances.

            I have made some modifications to your script to demonstrate. I am using the dynamic type when looping through ChartObjects since this is recommended in case you want to export this Drawing Tool in a DLL.

            Attached Files
            JimNinjaTrader Customer Service


              Hi Jim,

              Sorry for the late response I've not been working for the last few weeks and just got back to my desk. Thank you for coming up with a solution for this.... I will give it a try!

              Thanks again,



                Thank you NinjaTrader_Jim for post #6 and your solution, this has helped me here very well:
                Hi, I have made an attempt to update the price of the "LabeledHorizontalLine" from NinjaTrader_Jim ( (, via "INotifyPropertieChange". This goes so far perfectly, until
                NinjaTrader Ecosystem Vendor - Sidi Trading



                  Trying to achieve a similar goal. After taking a look at the code, it appears that it only changes the chart objects in the active Chart Control. How would one iterate through the tabs as well? Is there a collection of Chart Controls? The end goal is to find charts that match the Instrument, match the specific item and update values.

                  NinjaTrader Ecosystem Vendor - Ocean Trading Indicators


                    Hello Unsuitable,

                    Thank you for your note.

                    You should be able to achieve your desired result using the items collection. Here is a post where a user was having the opposite problem; they were able to loop through the tabs of a selected chart but not through all charts:
                    Hi, I was wondering if there's a way to iterate through (or refer to) open chart windows, other than the currently selected chart? I can iterate through tabs

                    Please let me know if I may be of further assistance.
                    Emily C.NinjaTrader Customer Service


                      Hello Emily,

                      This should work.

                      Thank you for directing me to the thread.
                      NinjaTrader Ecosystem Vendor - Ocean Trading Indicators


                      Latest Posts


                      Topics Statistics Last Post
                      Started by merzo, 06-25-2023, 02:19 AM
                      11 responses
                      1 like
                      Last Post richerd
                      by richerd
                      Started by ghappy21, Yesterday, 10:32 AM
                      5 responses
                      Last Post brucerobinson  
                      Started by FishTrade, 07-12-2024, 12:18 AM
                      2 responses
                      Last Post FishTrade  
                      Started by butt_toast, 04-28-2021, 05:46 AM
                      7 responses
                      Last Post Phrygian  
                      Started by DeanJ, Yesterday, 05:19 AM
                      2 responses
                      Last Post DeanJ
                      by DeanJ