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

Remove Drawn Objects

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

    Remove Drawn Objects

    Hi,

    is there a way (by code) to remove all drawn objects (drawn by an indicator) once that the same indicator has been removed from the chart?

    Thanks.

    #2
    As you remove an indicators from a chart all drawing objects drawn by the indicator are removed.

    Comment


      #3
      I tried to draw a rectangle on chart by a coded indicator but when I removed the indicator, the rectangle drawn was still there. I had to remove it manually.
      Maybe there is some particular code string to add?

      Thanks.

      Comment


        #4
        I just double checked by attached simple indicator and it works as expected:
        Code:
                protected override void OnBarUpdate()
                {
                    Plot0.Set(Close[0]);
                    if (CurrentBar < 10)
                        return;
                    DrawRectangle("tag", 10, Close[10], 0, Close[10] - 10 * TickSize, Color.Blue);
                }
        Please post your complete indicator if you experience something different.

        Also: Please make sure you are on latest 6.0.1000.5

        Comment


          #5
          I tried with your example and it does work, nevertheless using my code, the drawn rectangle remains on chart when the indicator is off.
          Let's say I've got an Input in the indicator. When the Input has the value of NPat (5 in the case below) then a rectangle is drawn and the tb assumes a value of 1.
          Everything works perfectly except that when I remove the Indicator the rectangle remains on chart.
          I'm sure I'm missing something, but I don't know what..

          ================================================== ====
          protected override void OnBarUpdate()
          {
          if (Open[0] < Low[1])
          {
          NPat = 5;
          }
          else
          NPat = 0;
          {


          if (NPat == Input)
          {
          tb = 1;

          DrawRectangle(CurrentBar.ToString(), 0, Math.Min(Low[0],Low[1]) - TickSize, 1, Math.Max(High[0],High[1]) + TickSize, Color.Gold, Color.Gold, 3);
          }
          else
          {
          tb = 0;
          }


          Plot0.Set(tb);

          Comment


            #6
            I copied your code snippet and modified it slightly to allow it to compile. It works as expected. Removal of rectangle happens automatically. Please try the attached indicator and see if it works for you. If it still doesn't work perhaps your install/.NET got messed up somehow and I advise you to do a reinstall.
            Attached Files
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Thanks Josh, nevertheless the trouble could be in this line of code:

              if (NPat == 5)

              My goal is: if NPat is equal to my Input (that, in this case, I insert with a value of 5) then draw a rectangle. If my input value is different from 5 the indicator does not draw anything.

              Hope this is more clear.

              Thanks.

              Comment


                #8
                Okay MAX. The potential problem I see with using "Input" is because Input is generally already defined as an IDataSeries. When you go NPat == Input you are comparing an int to an IDataSeries which causes compile error. Take a look at the attached file. It replaces "Input" with "UserInput" and is a user definable value. It works in adding and removing the rectangles as expected on my end.
                Attached Files
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks Josh, but my goal is to allow the user to choose the value. If I put the input as internal variable this is not possible, because nothing is shown on the indicator as Input.

                  Comment


                    #10
                    Josh I tried your indicator but I have an error.

                    Comment


                      #11
                      Yes it works. Thanks very much Josh.

                      Comment


                        #12
                        Glad you got it working. If you have any more questions feel free to ask.
                        Josh P.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by KenneGaray, Today, 03:48 AM
                        0 responses
                        3 views
                        0 likes
                        Last Post KenneGaray  
                        Started by thanajo, 05-04-2021, 02:11 AM
                        4 responses
                        470 views
                        0 likes
                        Last Post tradingnasdaqprueba  
                        Started by aa731, Today, 02:54 AM
                        0 responses
                        4 views
                        0 likes
                        Last Post aa731
                        by aa731
                         
                        Started by Christopher_R, Today, 12:29 AM
                        0 responses
                        10 views
                        0 likes
                        Last Post Christopher_R  
                        Started by sidlercom80, 10-28-2023, 08:49 AM
                        166 responses
                        2,237 views
                        0 likes
                        Last Post sidlercom80  
                        Working...
                        X