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

Changing IsVisible on Indicator in code doesn't hide draw objects.

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

    Changing IsVisible on Indicator in code doesn't hide draw objects.

    I have code that toggles the visibility of an indicator using Indicator.IsVisible. This will successfully hide/show the plot lines of an indicator such as SMA, but will not hide any draw objects created by an indicator such as the Candle Stick Pattern Indicator.

    This works fine if you change the properties of the indicator via the Indicators window, and the properties shows the flag correctly.

    #2
    Hello ntbone,

    As a heads up, IsVisible is intentionally not documented in the NinjaTrader help guide and is not intended to be set in an indicator.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      According to this link https://ninjatrader.com/support/help...?isvisible.htm it is documented and Indicators are NinjaScript objects.

      Further investigation reveals that changing the visible property of the indicator in the properties dialog causes all the existing drawing objects to be deleted. Making it visible again causes them to be recreated. I am making an educated guess this has to do with the fact that opening hitting ok or apply in the properties window causes the existing indicator object to be destroyed, taking all the drawing objects it owns with it, and a new one to be created that doesn't create any drawing objects due to not being visible.

      As a work around for any looking for a way to make this work, one can iterate through all the DrawingTool objects in ChartObjects property of the Indicator, and toggle the IsVisible flag on the drawing objects if they are owned by the indicator. This works, though is likely considered an unsupported means of doing this.

      Comment


        #4
        Hello ntbone,

        My mistake. I was looking at an internal document that stated IsVisible is intentionally not documented.

        Thank you for providing the link to the documentation on this (that shows my internal information is out of date).

        I gave this a test. I'm finding if IsVisible is set in State.DataLoaded or in a state previous, this works as expected. If set after a drawing object is drawn, the object is not removed.



        Are you able to set IsVisible in State.DataLoaded?

        I am inquiring further if this is supported to set to false in realtime.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Unfortunately no. I have an addon that adds functionality to hide all indicators. It loops through all the indicators for a chart and turns the visibility on or off. The side effects of this include
          • Drawing objects created by any indicator not disappearing.
          • Panels created by indicators like the moving average disappear but the space they occupied is not adjusted.
          I worked around the first issue per my comment above by looping through all drawing objects and hiding any owned by the indicator. I worked around the second issue by simply not hiding any indicator that has indicator.DrawOnPricePanel = false. For this purpose I really just want to hide all indicators that are drawn on top of the chart itself, not drawn in their own panels.

          Comment


            #6
            Hello ntbone,

            Our development confirmed, this setting simply prevents the script from processing. So rendered objects like plots or custom renders are not rendered because OnRender is never called. However, this does not cause existing drawing tool objects to be removed from the chart or any other actions to occur.

            Possibly RemoveAllDrawObjects() could cause these to be removed before setting the IsVisible.

            With custom panels not removed, I will create a report for this. Once I have a tracking ID for this report I will post in this thread.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              I tried RemoveAllObjects but then when you toggle to make them visible again, they are not regenerated and thus never re-appear. CandleStick indicator is a good example. Sounds like my solution of hiding/showing the attached drawing objects is the best way to go to get what I want.

              Comment


                #8
                Hello ntbone,

                RemoveDrawObjects() removes the drawing objects.

                When you want them back, you would need to call the Draw methods again. (Possibly in a loop)

                However, I am glad to hear you have worked out a solution.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hello ntbone,

                  I've received tracking ID# SFT-4011 for this request to remove a panel if the only indicator on it has IsVisible set to false and tracking ID# SFT-4021 for the request for removing and re-adding drawing objects automatically if IsVisible is set to false/true.

                  Please note it is up to the NinjaTrader Development to decide if or when any request will be implemented.

                  We appreciate your feedback.
                  Last edited by NinjaTrader_ChelseaB; 05-28-2019, 03:25 PM.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NinjaTrader_ChelseaB View Post
                    Hello ntbone,

                    I've received tracking ID# SFT-4011 for this request to remove a panel if the only indicator on it has IsVisible set to false and tracking ID# SFT-4021 for the request for removing and re-adding drawing objects automatically if IsVisible is set to false/true.

                    Please note it is up to the NinjaTrader Development to decide if or when any request will be implemented.

                    We appreciate your feedback.

                    Hello,

                    please add my vote for
                    ID# SFT-4011 and ID# SFT-4021 feature requests.

                    Thank you.

                    Comment


                      #11
                      Hello emuns,

                      I have submitted your votes.

                      Thank you for your feedback on this.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Originally posted by NinjaTrader_ChelseaB View Post
                        Hello emuns,

                        I have submitted your votes.

                        Thank you for your feedback on this.
                        I have coded this already for myself, but it would be nice to have it natively in the platform. Kindly list me among the requestors.

                        Comment


                          #13
                          Hi koganam,

                          I've got your vote added in.

                          Thanks for your voice on this.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            Originally posted by ntbone View Post
                            I have code that toggles the visibility of an indicator using Indicator.IsVisible. This will successfully hide/show the plot lines of an indicator such as SMA, but will not hide any draw objects created by an indicator such as the Candle Stick Pattern Indicator.

                            This works fine if you change the properties of the indicator via the Indicators window, and the properties shows the flag correctly.
                            Is it possible to share your add on, I am trying to find a work around to allow a secondary data series that plots BackBrushAll, cotinually when it stops updating visuals after say 100-500 bars, and a way to code in a refresh, and as I am now I am able to get it to increment during a new period where bars are printing, although the script either does not listen to a refresh or when it is refreshed it wil no longer update based on the new period in which it is coded to paint new backbrush. Any help on getting a visual update or successful refresh to repaint a new period of bars is appreciated.

                            Comment


                              #15
                              The code to hide the drawing objects is very straight forward and won't fix your problem unless you are using the drawing objects. If you are calling AddPlot to render your visuals then the code that I have won't help you.

                              Code:
                              private void ShowIndicator(bool isVisible)
                              {
                                  foreach(var chartObject in chartWindow.ActiveChartControl.ChartObjects)
                                  {
                                      var indicator = chartObject as Indicator;
                                      if(indicator != null && indicator.DrawOnPricePanel)
                                      {
                                          indicator.IsVisible = isVisible;
                                          ToggleIndicatorDrawingObjectVisibilty(indicator, isVisible);
                                      }
                                  }
                              
                                  // forces the chart to redraw.
                                  chartWindow.ActiveChartControl.InvalidateVisual();
                              }
                              
                              private void ToggleIndicatorDrawingObjectVisibilty(Indicator indicator, bool isVisible)
                              {
                                  foreach(var obj in indicator.DrawObjects)
                                  {
                                      if(obj.DrawnBy == indicator)
                                      {
                                          obj.IsVisible = isVisible;
                                      }
                                  }
                              }

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by aussugardefender, Today, 01:07 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post aussugardefender  
                              Started by pvincent, 06-23-2022, 12:53 PM
                              14 responses
                              238 views
                              0 likes
                              Last Post Nyman
                              by Nyman
                               
                              Started by TraderG23, 12-08-2023, 07:56 AM
                              9 responses
                              384 views
                              1 like
                              Last Post Gavini
                              by Gavini
                               
                              Started by oviejo, Today, 12:28 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post oviejo
                              by oviejo
                               
                              Started by pechtri, 06-22-2023, 02:31 AM
                              10 responses
                              125 views
                              0 likes
                              Last Post Leeroy_Jenkins  
                              Working...
                              X