Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Button that changes Objects to Visible/Invisible

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

    Button that changes Objects to Visible/Invisible

    I added a button to my chart which my idea was making objects I drew Visible/Invisible. What I did was set a variable, and before plotting something I am checking if the variable is true, I am changing the variable from true to false or false to true on the button click (var = !var). I did this because I though ninja trader would somehow re-run the script, but I believe I am wrong. I think I need to loop through all object I drew and change their visibility?
    Anyways, what is the correct way to have a button that shows and hide objects I drew.

    Thank you
    Last edited by amfpaulo; 07-01-2024, 07:07 AM.

    #2
    I n On state change , set the initial variable plot to false, it should work .

    Comment


      #3
      Hello amfpaulo,

      Yes once an object is drawn you wouldn't be able to toggle its visibility just with a bool that controls drawing, that would only affect future drawings. If you are only using a few drawings that have specific tag names you would need to add an else to your condition that uses the bool so when it is false you redraw the objects, calling the same tag will update the previous object.

      I would suggest looking at the following indicator from the user app share, line 279 is where it handles drawing objects. That would be a better approach if you have many objects or unique tag names being used. That controls visibility using the IsVisible property.

      Updated: March 12th, 2017 This is an indicator that adds a toolbar to the main menu area of each chart window. It will add 4 buttons to every tab in the window to perform the following functions: A button to toggle on / off all drawing items in the currently selected tab by switching "visible […]

      Comment


        #4
        Thank you , The code was useful moreover I was able to accomplish the task ! You guys are very precise with your answers! Does NinjaTrader eventually hire developers ? I have a lot of experience with C# and I am fascinated with NJ Platform and how easy it is to develop for it.

        Thank you again

        Comment


          #5
          Hello amfpaulo,

          You can monitor the public https://ninjatrader.com/careers/ website, if any job openings come up they are posted there. C# is the main language that NinjaTrader uses so it is possible that developer or scripting related jobs could open up in the future.

          Comment


            #6
            Thank you, I'll keep my eyes on it.

            Comment


              #7
              Hey Guys I have another question. I was able to loop through drawing objects moreover make them visible or now. However, I now have a necessity to check for specific group of objects, since I have tagged them with a prefix I can easily test by the name, like Tag.StartWith("Arrow")... But there is no Tag Property on the DrawingObjects... I tried Name but name holds the type of object.... how can I check the Tag property ? Is it possible?

              Comment


                #8
                Hello amfpaulo,

                In that sample the object is being cast to a DrawingTool so that should work to get its tag. It would be draw.Tag

                Code:
                foreach (var obj in chartWindow.ActiveChartControl.ChartObjects)
                {
                    var draw = obj as DrawingTool;
                    if (draw != null)
                    {
                        Print(draw.Tag);
                    }
                }


                You can also see the sample in the following page which is a more simple way of accessing just the drawing objects on the chart, that also shows casting to different types if you needed specific anchors or properties of a specific type object.

                Comment


                  #9
                  Thank you. You are correct.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  571 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  330 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
                  548 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  549 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X