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

How do I remove draw objects when they're global?

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

    How do I remove draw objects when they're global?

    Great! many thanks Chelsea. I didn't see that tip before.

    By the way, instead of opening a new topic, I take advantage to ask you one more question regarding remove draw objects.

    I noticed that if the draw object isn't global, the instruction RemoveDrawObjects(); actually remove all of them, but if my indicator draws any object which is global (drawn in all charts), this instruction does not remove anything.

    How do I remove draw objects when they're global?

    Thanks again...

    #2
    Hello germanf,

    I've moved your post to a new thread as this was not related to the topic of the previous thread.

    I am not able to reproduce this behavior. I've drawn a global object, and RemoveDrawObjects() removes the object.

    Below is a link to a video.
    https://drive.google.com/file/d/1P6r...w?usp=drivesdk

    To confirm, if you follow the exact steps shown in this video with the test script, you are experiencing different behavior?

    RemoveGlobalDrawObjectsTest_NT8.zip
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,
      Thanks for your response and moving the issue to a new topic.

      I cannot attach mp4 files, so please, follow this link from "WeTransfer" to download the video

      https://we.tl/t-jQQEdPveCo



      Here's a snippet of my code:
      ​​

      if(BarsInProgress == 0)
      {
      if(Bars.IsFirstBarOfSession)
      {
      RemoveDrawObjects();
      }​

      .................
      if(alphaStill[draw] != 0 && deltaStill[draw] != 0)
      {​
      if(!isGlobal) Draw.Rectangle(this, "ATpendingToClose " +draw, false, alphaDelta[draw], alphaStill[draw], Times[0][0], deltaStill[draw], Brushes.Transparent, regionColor, regionOpacity);
      if(isGlobal) Draw.Rectangle(this, "ATpendingToClose " +draw, alpha[draw], alphaStill[draw], Times[0][0], deltaStill[draw], true, template);​
      }
      ....................


      When is first bar of session, all previous drawings are removed to draw them during the current session.
      Depending on the parameter isGlobal, the first or second method will be used.

      When is not global, all objects are removed at first bar of session, and the new ones are drawn.
      The issue comes when they're global.

      You can see this behavior in the video. I have only two charts open, and my indicator is just in one of them.

      Comment


        #4
        Hello germanf,

        Did you try the sample that Chelsea had linked to check if that sample works?

        The code you have shown in post 3 is drawing objects after you remove them so if your condition to draw is true you will re draw new objects after removing them. To make sure that its not just your logic causing that result you can test the sample that Chelsea linked which should prove that removing global objects works.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Hello Jesse,
          Yes, actually global objects are removed. What I mean, both methods to draw the rectagle are exactly at the same point in the code, so when RemoveDrawObjects(), should affect exactly in the same way.

          The issue is,

          When objects are drawn by the following method, in IsFirstBarOfSession, all of them are removed.
          Draw.Rectangle(this, "ATpendingToClose " +draw, false, alphaDelta[draw], alphaStill[draw], Times[0][0], deltaStill[draw], Brushes.Transparent, regionColor, regionOpacity);

          When objects are drawn by the method below, there still are some objects undeleted.
          Draw.Rectangle(this, "ATpendingToClose " +draw, alpha[draw], alphaStill[draw], Times[0][0], deltaStill[draw], true, template);​

          Basically, no matter where I remove the objects. If methods to draw are at the same point, there shouldn't be any difference by using one method or another, and the result also have to be the same. As you could see in the video, that's not the case.

          Comment


            #6
            Hello germanf,

            Thanks for confirming that objects are being removed. It sounds like the problem is with how your logic is structured.

            The code you had shown in post 3 could "undo" the RemoveDrawObjects. You are checking if its the IsFirstBarOfSession and if so calling RemoveDrawObjects. If the other code you have shown comes after the IsFirstBarOfSession like you have shown it will also get called on the IsFirstBarOfSession. If the conditions there are true you will have cleared the drawing objects and then re drawn the object.

            If you are expecting that all objects are removed for the first bar of the session your condition should look like the following:


            Code:
            if(BarsInProgress == 0)
            {
                if(Bars.IsFirstBarOfSession)
               {
                  RemoveDrawObjects();
               }​
               else if(alphaStill[draw] != 0 && deltaStill[draw] != 0)
               {​
                  if(!isGlobal) Draw.Rectangle(this, "ATpendingToClose " +draw, false, alphaDelta[draw], alphaStill[draw], Times[0][0], deltaStill[draw], Brushes.Transparent, regionColor, regionOpacity);
                  if(isGlobal) Draw.Rectangle(this, "ATpendingToClose " +draw, alpha[draw], alphaStill[draw], Times[0][0], deltaStill[draw], true, template);​
               }
            }
            JesseNinjaTrader Customer Service

            Comment


              #7
              Hi Jesse, many thanks for your prompt response,
              My code is exactly the same as yours. Both Draw.Rectangle methods are outside IsFirstBarOfSession.

              Here's the code shown in post highlighting the braces...

              if(BarsInProgress == 0)
              {
              if(Bars.IsFirstBarOfSession)
              {
              RemoveDrawObjects();
              }​

              .................
              if(alphaStill[draw] != 0 && deltaStill[draw] != 0)
              {​
              if(!isGlobal) Draw.Rectangle(this, "ATpendingToClose " +draw, false, alphaDelta[draw], alphaStill[draw], Times[0][0], deltaStill[draw], Brushes.Transparent, regionColor, regionOpacity);
              if(isGlobal) Draw.Rectangle(this, "ATpendingToClose " +draw, alpha[draw], alphaStill[draw], Times[0][0], deltaStill[draw], true, template);​
              }
              ....................​
              ....................​

              No more drawing methods here
              }


              The behavior is different depending on the method to draw, that's why I opened the thread saying that RemoveDrawingOjects() doesn't work as expected when they're global.

              Comment


                #8
                Hello germanf,

                I think you had misunderstood my explanation of the else with IsFirstBarOfSession, if you mean to draw again on the first bar of the session then what you have will do that. The objects are removed and then it can immediately draw again within the same OnBarUpdate call if your conditions are true. If you don't want to draw on the first bar of the session and have everything removed for that bar then you need that else statement so your drawing conditions can't happen on the same OnBarUpdate as the IsFirstBarOfSession.

                We already confirmed that removing global objects works as expected by using the sample so the result you are seeing has something to do with how your logic is executing. You can use Prints if it is not clear why objects show up in one use case and not another.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Hello Jesse,
                  I understand what you explained, but I insist. Remove drawing objects has different behavior when objects are global and depending on "Tick replay". The result is not what is expected.
                  It only works when "Tick replay" is enabled. If you disable "Tick replay", global objects aren't removed.

                  Please, find attached a simple code which demonstrates the issue.
                  Attached Files

                  Comment


                    #10
                    Hello germanf,

                    The script you attached always draws a new object for every OnBarUpdate. When you remove the objects you also immediately draw a new object so it should always have at least 1 object drawn.

                    To test if the object is getting removed you need to stop drawing it again and then remove it. The sample that chelsea linked does that by drawing the object one time in historical and then on the first realtime bar it removes it. These actions happen 1 bar apart and not at the same time like the script you had attached.

                    Code:
                    if (State == State.Historical && CurrentBar == Count - 2)
                    {
                        Draw.Dot(this, "myDot", true, 0, High[0] + 3 * TickSize, true, string.Empty);
                    }
                    
                    if (State == State.Realtime)
                    {
                        RemoveDrawObjects();
                    }
                    Do you see some kind of difference if you draw 1 object and then later remove it? If so what were the settings being used when you saw the difference and what was observed? ​
                    JesseNinjaTrader Customer Service

                    Comment


                      #11
                      Hi Jesse, thanks for your response.
                      The code that Chelsea linked works fine, but that's not what I want to do. What I want, effectively, is to remove all past objects when is first bar of session, and draw new ones, so yes, it should always be one object drawn, but just one. Only one because the tag of the object in my script is the same for the whole day, and I'm removing the objects when a new day begins. When is first bar of session, the objects are removed, after that, the counter adds 1, so a new object is created.

                      If you add the indicator I've attached before, when you select "isGlobal" from the properties, just when the session closes, there're rectangles that remain drawn. If you unselect "isGlobal", only one rectangle is in the chart what is as expected. This happens when "tick replay" is not enabled.

                      If you activate "tick replay", both global and not global behaves in the same way.

                      So, the behavior is different just depending on if the object is global or not, and if "tick replay" activated.

                      See attached pictures and see the difference between them.​
                      Attached Files

                      Comment


                        #12
                        Hello germanf,

                        If you are seeing some kind of difference in the way your logic runs between tick replay and not you could use prints to identify how to make conditions that account for both use cases. Supporting tick replay generally requires making a second set of logic specifically to be used when tick replay is enabled. Depending on why you are using tick replay you may need to code other areas of your script separately as well if you plan to support using tick replay or not. You can read about developing for tick replay in the following link: https://ninjatrader.com/support/help..._highlightsub= tick+replay

                        Another suggestion here would be to not use RemoveDrawObjects at all and just draw 1 object. The sample you provided is just redrawing a object on each bar so removing the object is not necessary in contrast to the given sample code. Using a non unique tag name instead of incrementing it would let you keep updating the object without removing it. Your sample would be like the following:

                        Code:
                        if(BarsInProgress == 0)
                        {
                        if(isGlobal) Draw.Rectangle(this, "Rectangle Global", 10, High[0], 0, Low[0], true, "Default");
                        else Draw.Rectangle(this, "Rectangle NotGlobal ", false, 10, High[0], 0, Low[0], Brushes.Transparent, Brushes.Red, 50);
                        
                        }​
                        JesseNinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by ballston, 05-07-2021, 06:32 AM
                        6 responses
                        253 views
                        0 likes
                        Last Post NinjaTrader_Clayton  
                        Started by demarcog, Today, 08:51 AM
                        0 responses
                        1 view
                        0 likes
                        Last Post demarcog  
                        Started by futuros, 01-26-2023, 05:10 PM
                        3 responses
                        40 views
                        0 likes
                        Last Post NinjaTrader_ChrisL  
                        Started by number1, Yesterday, 09:13 PM
                        1 response
                        33 views
                        0 likes
                        Last Post NinjaTrader_Sev  
                        Started by angelvincent37, Yesterday, 08:15 AM
                        2 responses
                        25 views
                        0 likes
                        Last Post angelvincent37  
                        Working...
                        X