Announcement

Collapse

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

Collapse

Drawing Tool Context Menu Handler with Global Drawing Objects

Collapse
X
 
  • 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 8.0.24.2 or 8.0.25.0.

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

    Code:
    public void IncreasePriceClick(object sender, RoutedEventArgs e)
    {
           foreach (var chartAnchor in Anchors)
           {
                chartAnchor.Price += 4;
           }
    
           ForceRefresh();
    }
    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

    #2
    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 — https://ninjatrader.com/support/help...ease_notes.htm

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

    Comment


      #3
      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

      Comment


        #4
        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

        Comment


          #5
          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

          Comment


            #6
            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

            Comment


              #7
              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,

              Kevin.

              Comment


                #8
                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 (https://ninjatraderecosystem.com/use...-drawing-tool/ (https://ninjatraderecosystem.com/user-app-share-download/labeled-lines-drawing-tool/)), via "INotifyPropertieChange". This goes so far perfectly, until
                sidlercom80
                NinjaTrader Ecosystem Vendor - Sidi Trading

                Comment


                  #9
                  Hello,

                  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.

                  Thanks
                  Unsuitable
                  NinjaTrader Ecosystem Vendor - Ocean Trading Indicators

                  Comment


                    #10
                    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

                    Comment


                      #11
                      Hello Emily,

                      This should work.

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

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by bortz, 11-06-2023, 08:04 AM
                      47 responses
                      1,606 views
                      0 likes
                      Last Post aligator  
                      Started by jaybedreamin, Today, 05:56 PM
                      0 responses
                      9 views
                      0 likes
                      Last Post jaybedreamin  
                      Started by DJ888, 04-16-2024, 06:09 PM
                      6 responses
                      19 views
                      0 likes
                      Last Post DJ888
                      by DJ888
                       
                      Started by Jon17, Today, 04:33 PM
                      0 responses
                      6 views
                      0 likes
                      Last Post Jon17
                      by Jon17
                       
                      Started by Javierw.ok, Today, 04:12 PM
                      0 responses
                      15 views
                      0 likes
                      Last Post Javierw.ok  
                      Working...
                      X